目录
acat@acat-xx:src$ tree
.
├── aclocal.m4
├── AUTHORS
├── autom4te.cache
│ ├── output.0
│ ├── output.1
│ ├── requests
│ ├── traces.0
│ └── traces.1
├── autoscan.log
├── bson
│ ├── APACHE-2.0.txt
│ ├── GNU-AGPL-3.0.txt
│ ├── lib
│ │ ├── atomic_int.h
│ │ ├── base64.cpp
│ │ ├── base64mulu.h
│ │ ├── emeralddb-base64.o
│ │ ├── emeralddb-md5.o
│ │ ├── emeralddb-nonce.o
│ │ ├── md5.cpp
│ │ ├── md5.h
│ │ ├── md5.hpp
│ │ ├── nonce.cpp
│ │ └── nonce.h
│ └── src
│ ├── bsonassert.h
│ ├── bson_db.h
│ ├── bsonelement.h
│ ├── bson.h
│ ├── bson-inl.h
│ ├── bsonmisc.h
│ ├── bsonobjbuilder.h
│ ├── bsonobj.cpp
│ ├── bsonobj.h
│ ├── bsonobjiterator.h
│ ├── bsontypes.h
│ ├── emeralddb-bsonobj.o
│ ├── emeralddb-oid.o
│ ├── inline_decls.h
│ ├── lib
│ ├── oid.cpp
│ ├── oid.h
│ ├── ordering.h
│ ├── stringdata.h
│ └── util
│ ├── builder.h
│ ├── embedded_builder.h
│ ├── emeralddb-json.o
│ ├── hex.h
│ ├── json.cpp
│ ├── json.h
│ ├── misc.h
│ ├── optime.h
│ └── time_support.h
├── build.sh
├── ChangeLog
├── client
├── compile -> /usr/share/automake-1.15/compile
├── config.guess -> /usr/share/automake-1.15/config.guess
├── config.h
├── config.h.in
├── config.h.in~
├── config.log
├── config.status
├── config.sub -> /usr/share/automake-1.15/config.sub
├── configure
├── configure.ac
├── configure.in.bak
├── configure.scan
├── COPYING -> /usr/share/automake-1.15/COPYING
├── depcomp -> /usr/share/automake-1.15/depcomp
├── dms
├── driver
├── emeralddb
├── emeralddb-base64.o
├── emeralddb-bsonobj.o
├── emeralddb-json.o
├── emeralddb-md5.o
├── emeralddb-nonce.o
├── emeralddb-oid.o
├── emeralddb-pmdMain.o
├── include
│ └── core.hpp
├── INSTALL -> /usr/share/automake-1.15/INSTALL
├── install-sh -> /usr/share/automake-1.15/install-sh
├── ixm
├── Makefile
├── Makefile.am
├── Makefile.in
├── missing -> /usr/share/automake-1.15/missing
├── mon
├── msg
├── NEWS
├── oss
├── pd
├── pmd
│ ├── emeralddb-pmdMain.o
│ └── pmdMain.cpp
├── README
├── rtn
└── stamp-h1
17 directories, 84 files
首先运行autoconf生成文件:configure.scan,然后将其重命名为configure.ac,并修改configure.ac的文件内容。
configure.ac
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(emeralddb,1.0)
AC_USE_SYSTEM_EXTENSIONS
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([include/core.hpp])#自动生成
AC_CONFIG_HEADERS([config.h])#自动生成
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_MAKE_SET
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([string.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_UINT64_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_STRNLEN
AC_CHECK_FUNCS([localtime_r memset pow strchr strtol])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
以上完成之后,可以运行:aclocal,autoconf,autoheader三个命令。
其中,aclocal用于生成辅助文件。autoconf用于根据前面编写的configure.ac的内容生成configure脚本文件。autoheader用于生成config.h.in文件。
Makefile.am
Makefile.am文件定义了Makefile文件的规则,如编译的参数,程序需要用到哪些可执行文件等。
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = emeralddb#项目名字
emeralddb_SOURCES =\
pmd/pmdMain.cpp \
bson/src/bsonobj.cpp bson/src/util/json.cpp bson/src/oid.cpp \
bson/lib/nonce.cpp bson/lib/md5.cpp bson/lib/base64.cpp
# timer_CPPFLAGS = -I include/ #包含目录
emeralddb_CXXFLAGS=-I../boost -Ibson -Ibson/src -Ibson/lib -Iinclude -D_FILE_OFFSET_BITS=64 -ggdb -Wall -O0
emeralddb_LDADD=-lpthread -lm -lboost_system -lboost_thread -lboost_program_options -lrt
emeralddb_LDFLAGS=-fPIC -rdynamic -L../boost/stage/lib -pthread
以上完成了之后,可以运行automake --add-missing命令,用于生成文件:Makefile.in。然后运行命令:./configure 用于生成Makefile文件,接着运行make命令进行编译,生成目标程序。
build.sh
# ********** build.sh ************
#!/bin/bash
aclocal
autoconf
autoheader
automake --add-missing
./configure CXXFLAGS= CFLAGS=
运行:
acat@acat-xx:src$ ./build.sh Makefile.am:3: warning: source file 'pmd/pmdMain.cpp' is in a subdirectory, Makefile.am:3: but option 'subdir-objects' is disabled automake: warning: possible forward-incompatibility. automake: At least a source file is in a subdirectory, but the 'subdir-objects' automake: automake option hasn't been enabled. For now, the corresponding output automake: object file(s) will be placed in the top-level directory. However, automake: this behaviour will change in future Automake versions: they will automake: unconditionally cause object files to be placed in the same subdirectory automake: of the corresponding sources. automake: You are advised to start using 'subdir-objects' option throughout your automake: project, to avoid future incompatibilities. Makefile.am:3: warning: source file 'bson/src/bsonobj.cpp' is in a subdirectory, Makefile.am:3: but option 'subdir-objects' is disabled Makefile.am:3: warning: source file 'bson/src/util/json.cpp' is in a subdirectory, Makefile.am:3: but option 'subdir-objects' is disabled Makefile.am:3: warning: source file 'bson/src/oid.cpp' is in a subdirectory, Makefile.am:3: but option 'subdir-objects' is disabled Makefile.am:3: warning: source file 'bson/lib/nonce.cpp' is in a subdirectory, Makefile.am:3: but option 'subdir-objects' is disabled Makefile.am:3: warning: source file 'bson/lib/md5.cpp' is in a subdirectory, Makefile.am:3: but option 'subdir-objects' is disabled Makefile.am:3: warning: source file 'bson/lib/base64.cpp' is in a subdirectory, Makefile.am:3: but option 'subdir-objects' is disabled checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking minix/config.h usability... no checking minix/config.h presence... no checking for minix/config.h... no checking whether it is safe to define __EXTENSIONS__... yes checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for style of include used by make... GNU checking whether make supports nested variables... yes checking dependency style of gcc... gcc3 checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking dependency style of g++... gcc3 checking for gcc... (cached) gcc checking whether we are using the GNU C compiler... (cached) yes checking whether gcc accepts -g... (cached) yes checking for gcc option to accept ISO C89... (cached) none needed checking whether gcc understands -c and -o together... (cached) yes checking whether make sets $(MAKE)... (cached) yes checking for string.h... (cached) yes checking for stdbool.h that conforms to C99... yes checking for _Bool... yes checking for inline... inline checking for size_t... yes checking for uint64_t... yes checking for stdlib.h... (cached) yes checking for GNU libc compatible malloc... yes checking for stdlib.h... (cached) yes checking for GNU libc compatible realloc... yes checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for working strnlen... yes checking for localtime_r... yes checking for memset... yes checking for pow... no checking for strchr... yes checking for strtol... yes checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating config.h config.status: config.h is unchanged config.status: executing depfiles commands acat@acat-xx:src$ make make all-am make[1]: 进入目录“/media/acat/J/emeralddb/src” make[1]: 离开目录“/media/acat/J/emeralddb/src” acat@acat-xx:src$ ./emeralddb 0Hello World,pmdMain! acat@acat-xx:src$