Linux工具之autoconf和automake
1 autoscan — 在 hello.c所在目录完成扫描
文件长生如下文件
┗ autoscan.log
┗ configure.scan
┗ mv configure.scan configure.ac
┗ edit configure,ac
修改 configure.ac的内容
# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ([2.69])AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])# add itAM_INIT_AUTOMAKE#change itAC_CONFIG_SRCDIR(hello.c)AC_CONFIG_HEADERS([config.h])# Checks for programs.AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.# add itAC_CONFIG_FILES([Makefile])AC_OUTPUT
2 makefile.am — 创建添加如下信息
AUTOMAKE_OPTIONS=foreignbin_PROGRAMS=helloworldhelloworld_SOURCES=hello.c
┗ binPROGRAMS 指定可执行输出文件
┗ helloworldSOURCES 制定输入的原文件
3 执行aclocal
├── aclocal.m4
├── autom4te.cache
│ ├── output.0
│ ├── requests
│ └── traces.0
4 执行autoheader | with sudo
├── aclocal.m4
├── autom4te.cache
│ ├── output.0
│ ├── output.1
│ ├── requests
│ ├── traces.0
│ └── traces.1
├── autoscan.log
├── config.h.in
:::warning
autom4te: cannot open autom4te.cache/requests: Permission denied
autoheader: ‘/usr/bin/autom4te’ failed with exit status: 1
————————————————————————————————————————————————
sudo XXX
:::
5 执行autoconf | with sudo
├── aclocal.m4
├── autom4te.cache
│ ├── output.0
│ ├── output.1
│ ├── requests
│ ├── traces.0
│ └── traces.1
├── autoscan.log
├── config.h.in
├── configure
├── configure.ac
├── main.c
└── Makefile.am
执行automake —add-missing | with sudo
├── aclocal.m4
├── autom4te.cache
│ ├── output.0
│ ├── output.1
│ ├── requests
│ ├── traces.0
│ └── traces.1
├── autoscan.log
├── compile -> /usr/share/automake-1.16/compile
├── config.h.in
├── configure
├── configure.ac
├── depcomp -> /usr/share/automake-1.16/depcomp
├── install-sh -> /usr/share/automake-1.16/install-sh
├── main.c
├── Makefile.am
├── Makefile.in
└── missing -> /usr/share/automake-1.16/missing**
经过以上操作我们就可以像一般安装程序一config —> make —> make install
安装
./configuremakemake install┗ /usr/bin/install -c helloworld '/usr/local/bin'这样直接可以直接执行,不用带上绝对路径
autogen.sh 登场
#!/bin/shechoecho ... helloworld autogen ...echoMISSING=""env aclocal --version >/dev/null 2>&1if [ $? -eq 0 ];thenACLOCAL=aclocalelseMISSING="$MISSING aclocal"fienv autoconf --version > /dev/null 2>&1if [ $? -eq 0 ];thenAUTOCONF=autoconfelseMISSING="$MISSING autoconf"fienv autoheader --version > /dev/null 2>&1if [ $? -eq 0 ]; thenAUTOHEADER=autoheaderelseMISSING="$MISSING autoconf"fienv automake --version > /dev/null 2>&1if [ $? -eq 0 ];thenAUTOMAKE=automakeelseMISSING="$MISSING automake"fienv libtoolize --version > /dev/null 2>&1if [ $? -eq 0 ];thenTOOL=libtoolizeelseenv glibtoolize --version > /dev/null 2>&1if [$? -eq 0 ];thenTOOL=glibtoolizeelseMISSING="$MISSING libtoolize/glibtoolize"fifienv tar -cf /dev/null /dev/null > /dev/null 2>&1if [ $? -ne 0 ];thenMISSING="$MISSING tar"fiif [ "x$MISSING" != "x" ];thenecho "ABORTING."echoecho "The following build tools are missing:"echofor pkg in $MISSING;doecho " * $pkg"doneechoecho "please install them and try again."echofiecho Running $ACLOCAL$ACLOCALecho Running $AUTOHEADER$AUTOHEADERecho Running $TOOL$TOOLecho Running $AUTOCONF$AUTOCONFecho Running $AUTOMAKE$AUTOMAKE --add-missing --force-missing --copy --foreignechoecho "Please proceed with configuring, compiling and installing"
目录结构
├── autogen.sh
├── configure.ac
├── Makefile.am
└── src
├── hello.c
└── Makefile.am
根目录的configure ac
# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ([2.69])AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])AC_CONFIG_SRCDIR([src/hello.c])AC_CONFIG_HEADERS([config.h])# ● addAM_INIT_AUTOMAKE(helloworld,1.0)# ● addAC_CONFIG_FILES([Makefilesrc/Makefile])# Checks for programs.AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT
根目录的Makefile.am
SUBDIRS = src#ACLOCAL_AMFLAGS = -I m4.PHONY:cleanclean: distcleanfind . -name Makefile.in -exec rm -rf {} \;rm -rf autom4te.cacherm -f aclocal.m4 autoscan.log config.h config.log config.sub configure depcomp Makefile compile config.h.in config.status install-sh missing stamp-h1 config.guess config.h.in~ ltmain.sh
src目录下的Makefile.am
AUTOMAKE_OPTIONS=foreignbin_PROGRAMS=helloworldhelloworld_SOURCES=hello.chelloworld_LDADD=LIBS=-lmINCLUDE=-I/usr/include
:::warning
AC_CONFIG_FILES([Makefile
src/Makefile])
要让Makefile.am遍地开花
:::
参考文献
Linux工具之autoconf和automake
例解 autoconf 和 automake 生成 Makefile 文件
