kjay@kjay:~/Makefile_Tutorial/hello$ ls hello.c kjay@kjay:~/Makefile_Tutorial/hello$ cat hello.c #include<stdio.h> intmain() { printf("Hello, Linux World!\n"); return0; }
2. 使用autoscan自动检查hello.c编译所需的文件等
1 2 3
kjay@kjay:~/Makefile_Tutorial/hello$ autoscan kjay@kjay:~/Makefile_Tutorial/hello$ ls autoscan.log configure.scan hello.c
使用autoscan --help查看autoscan的作用
Examine source files in the directory tree rooted at SRCDIR, or the current directory if none is given. Search the source files for common portability problems, check for incompleteness of “configure.ac”, and create a file “configure.scan” which is a preliminary “configure.ac” for that package.
kjay@kjay:~/Makefile_Tutorial/hello$ mv configure.scan configure.ac kjay@kjay:~/Makefile_Tutorial/hello$ cat configure.ac # -*- Autoconf -*- # Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69]) AC_INIT([hello], [1.0], [xxx@qq.com]) AM_INIT_AUTOMAKE # Add, automake AC_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. AC_CONFIG_FILES([Makefile]) # Add, Create Makefile AC_OUTPUT
the AC_OUTPUT line is a closing command that actually produces the part of the script in charge of creating the files registered with AC_CONFIG_HEADERS and AC_CONFIG_FILES.
kjay@kjay:~/Makefile_Tutorial/hello$ autoconf kjay@kjay:~/Makefile_Tutorial/hello$ ls aclocal.m4 autom4te.cache autoscan.log configure configure.ac hello.c
输入autoconf --help,可以看到它的作用
Generate a configuration script from a TEMPLATE-FILE if given, or configure.ac if present, or else configure.in. Output is sent to the standard output if TEMPLATE-FILE is given, else into configure.
Create a template file of C #define statements for configure to use. To this end, scan TEMPLATE-FILE, or configure.ac if present, or else configure.in.
kjay@kjay:~/Makefile_Tutorial/hello$ automake --add-missing configure.ac:11: installing './compile' configure.ac:6: installing './install-sh' configure.ac:6: installing './missing' Makefile.am: installing './INSTALL' Makefile.am: installing './COPYING'using GNU General Public License v3 file Makefile.am: Consider adding the COPYING file to the version control system Makefile.am: for your code, to avoid questions about which license your project uses Makefile.am: installing './depcomp'
automake的功能是
Generate Makefile.in for configure from Makefile.am.
kjay@kjay:~/Makefile_Tutorial/hello$ ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes 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 whether make supports the include directive... yes (GNU style) checking dependency style of gcc... gcc3 checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating config.h config.status: executing depfiles commands kjay@kjay:~/Makefile_Tutorial/hello$ ls aclocal.m4 autom4te.cache ChangeLog config.h config.log configure COPYING hello.c install-sh Makefile.am missing README AUTHORS autoscan.log compile config.h.in config.status configure.ac depcomp INSTALL Makefile Makefile.in NEWS stamp-h1