autotools-practice

http://www.aireadfun.com/blog/2012/12/03/study-automake/


[fpxshyy@localhost makefpxshyykit]$ tar zxvf summary-1.0.0.tar.gz
summary-1.0.0/
summary-1.0.0/doc/
summary-1.0.0/doc/OVERVIEW
summary-1.0.0/man/
summary-1.0.0/man/summary.8
summary-1.0.0/src/
summary-1.0.0/src/person/
summary-1.0.0/src/person/main.c
summary-1.0.0/src/person/main.h
summary-1.0.0/src/person/do.h
summary-1.0.0/src/person/do.c
summary-1.0.0/src/lib/
summary-1.0.0/src/lib/lib.h
summary-1.0.0/src/lib/lib.c
summary-1.0.0/script/
summary-1.0.0/script/summary.sh
[fpxshyy@localhost makefpxshyykit]$ cd summary-1.0.0/
[fpxshyy@localhost summary-1.0.0]$ ls
doc  man  script  src
[fpxshyy@localhost summary-1.0.0]$ autoscan
[fpxshyy@localhost summary-1.0.0]$ ls
autoscan.log  configure.scan  doc  man    script    src
[fpxshyy@localhost summary-1.0.0]$ mv configure.scan configure.ac
[fpxshyy@localhost summary-1.0.0]$ ls
autoscan.log  configure.ac  configure.ac~  doc    man  script  src
[fpxshyy@localhost summary-1.0.0]$ autoconf
[fpxshyy@localhost summary-1.0.0]$ ls
autom4te.cache    autoscan.log  configure  configure.ac  configure.ac~  doc  man    script    src
[fpxshyy@localhost summary-1.0.0]$ cd man
[fpxshyy@localhost man]$ ls
Makefile.am  summary.8
[fpxshyy@localhost man]$ pwd
/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/man
[fpxshyy@localhost man]$ cd ..
[fpxshyy@localhost summary-1.0.0]$ cd script/
[fpxshyy@localhost script]$ ls
summary.sh
[fpxshyy@localhost script]$ ls
Makefile.am  summary.sh
[fpxshyy@localhost script]$ cd ..
[fpxshyy@localhost summary-1.0.0]$ cd doc
[fpxshyy@localhost doc]$ ls
OVERVIEW
[fpxshyy@localhost doc]$ ls
Makefile.am  OVERVIEW
[fpxshyy@localhost doc]$ cd ..
[fpxshyy@localhost summary-1.0.0]$ ls
autom4te.cache    autoscan.log  configure  configure.ac  configure.ac~  doc  Makefile.am    man  script  src
[fpxshyy@localhost summary-1.0.0]$ cd src
[fpxshyy@localhost src]$ ls
lib  person
[fpxshyy@localhost src]$ cd lib
[fpxshyy@localhost lib]$ ls
lib.c  lib.h  Makefile.am
[fpxshyy@localhost lib]$ cd ..
[fpxshyy@localhost src]$ cd person/
[fpxshyy@localhost person]$ ls
do.c  do.h  main.c  main.h
[fpxshyy@localhost person]$ cd ..
[fpxshyy@localhost src]$ ls
lib  Makefile.am  person
[fpxshyy@localhost src]$ cd ..
[fpxshyy@localhost summary-1.0.0]$ automake
configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
automake: error: no 'Makefile.am' found for any configure output
automake: Did you forget AC_CONFIG_FILES([Makefile]) in configure.ac?
[fpxshyy@localhost summary-1.0.0]$ autoscan
[fpxshyy@localhost summary-1.0.0]$ diff configure.ac configure.scan
5c5
< AC_INIT([summary], [1.0.0], [fight1987168@gmail.com])
---
> AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
20a21,27
> AC_CONFIG_FILES([Makefile
>                  doc/Makefile
>                  man/Makefile
>                  script/Makefile
>                  src/Makefile
>                  src/lib/Makefile
>                  src/person/Makefile])
[fpxshyy@localhost summary-1.0.0]$ ls
autom4te.cache    autoscan.log  configure  configure.ac  configure.ac~  configure.scan  doc  Makefile.am    man  script  src
[fpxshyy@localhost summary-1.0.0]$ aclocal
[fpxshyy@localhost summary-1.0.0]$ autoheader
[fpxshyy@localhost summary-1.0.0]$ autoconf
[fpxshyy@localhost summary-1.0.0]$ ls
aclocal.m4    autoscan.log  configure     configure.ac~   doc         man     src
autom4te.cache    config.h.in   configure.ac  configure.scan  Makefile.am  script
[fpxshyy@localhost summary-1.0.0]$ automake --add-missing
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
src/lib/Makefile.am:1: error: library used but 'RANLIB' is undefined
src/lib/Makefile.am:1:   The usual way to define 'RANLIB' is to add 'AC_PROG_RANLIB'
src/lib/Makefile.am:1:   to 'configure.ac' and run 'autoconf' again.
src/lib/Makefile.am: installing './depcomp'
[fpxshyy@localhost summary-1.0.0]$ automake
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
src/lib/Makefile.am:1: error: library used but 'RANLIB' is undefined
src/lib/Makefile.am:1:   The usual way to define 'RANLIB' is to add 'AC_PROG_RANLIB'
src/lib/Makefile.am:1:   to 'configure.ac' and run 'autoconf' again.
[fpxshyy@localhost summary-1.0.0]$ autoreconf
configure.ac:7: error: possibly undefined macro: AC_INIT_AUTOMAKE
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
[fpxshyy@localhost summary-1.0.0]$ ls
aclocal.m4    autoscan.log  configure     configure.ac~   depcomp  install-sh   Makefile.in  missing    src
autom4te.cache    config.h.in   configure.ac  configure.scan  doc      Makefile.am  man           script
[fpxshyy@localhost summary-1.0.0]$ automake
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
src/lib/Makefile.am:1: error: library used but 'RANLIB' is undefined
src/lib/Makefile.am:1:   The usual way to define 'RANLIB' is to add 'AC_PROG_RANLIB'
src/lib/Makefile.am:1:   to 'configure.ac' and run 'autoconf' again.
[fpxshyy@localhost summary-1.0.0]$ autoreconf
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
[fpxshyy@localhost summary-1.0.0]$ ls
aclocal.m4    autoscan.log  configure     configure.ac~   depcomp  install-sh   Makefile.in  missing    src
autom4te.cache    config.h.in   configure.ac  configure.scan  doc      Makefile.am  man           script
[fpxshyy@localhost summary-1.0.0]$ automake
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
[fpxshyy@localhost summary-1.0.0]$ ls
aclocal.m4    autoscan.log  configure     configure.ac~   depcomp  install-sh   Makefile.in  missing    src
autom4te.cache    config.h.in   configure.ac  configure.scan  doc      Makefile.am  man           script
[fpxshyy@localhost summary-1.0.0]$ ./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... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for ranlib... ranlib
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 for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/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 for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating man/Makefile
config.status: creating script/Makefile
config.status: creating src/Makefile
config.status: creating src/lib/Makefile
config.status: creating src/person/Makefile
config.status: creating config.h
config.status: executing depfiles commands
[fpxshyy@localhost summary-1.0.0]$ ls
aclocal.m4    config.h     config.status  configure.ac~   doc        Makefile.am  missing  stamp-h1
autom4te.cache    config.h.in  configure        configure.scan  install-sh    Makefile.in  script
autoscan.log    config.log   configure.ac   depcomp        Makefile    man         src
[fpxshyy@localhost summary-1.0.0]$ make
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/missing autoheader)
rm -f stamp-h1
touch config.h.in
cd . && /bin/sh ./config.status config.h
config.status: creating config.h
config.status: config.h is unchanged
make  all-recursive
make[1]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0”
Making all in doc
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
make[2]: 对“all”无需做任何事。
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
Making all in man
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/man”
make[2]: 对“all”无需做任何事。
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/man”
Making all in script
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/script”
make[2]: 对“all”无需做任何事。
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/script”
Making all in src
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/src”
make[2]: 对“all”无需做任何事。
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/src”
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0”
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0”
make[1]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0”
[fpxshyy@localhost summary-1.0.0]$ make install
Making install in doc
make[1]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
make[2]: 对“install-exec-am”无需做任何事。
 /usr/bin/mkdir -p '/usr/local/share/doc/summary'
/usr/bin/mkdir: 无法创建目录"/usr/local/share/doc": 权限不够
make[2]: *** [install-docDATA] 错误 1
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
make[1]: *** [install-am] 错误 2
make[1]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
make: *** [install-recursive] 错误 1
[fpxshyy@localhost summary-1.0.0]$ sudo make install
[sudo] password for fpxshyy:
Making install in doc
make[1]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
make[2]: 对“install-exec-am”无需做任何事。
 /usr/bin/mkdir -p '/usr/local/share/doc/summary'
 /usr/bin/install -c -m 644 OVERVIEW '/usr/local/share/doc/summary'
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
make[1]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/doc”
Making install in man
make[1]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/man”
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/man”
make[2]: 对“install-exec-am”无需做任何事。
 /usr/bin/mkdir -p '/usr/local/share/man/man8'
 /usr/bin/install -c -m 644 summary.8 '/usr/local/share/man/man8'
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/man”
make[1]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/man”
Making install in script
make[1]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/script”
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/script”
 /usr/bin/mkdir -p '/usr/local/bin'
 /usr/bin/install -c summary.sh '/usr/local/bin'
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/script”
make[1]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/script”
Making install in src
make[1]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/src”
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/src”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/src”
make[1]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0/src”
make[1]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0”
make[2]: 进入目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0”
make[1]: 离开目录“/home/fpxshyy/FpxStdudio/makefpxshyykit/summary-1.0.0”
[fpxshyy@localhost summary-1.0.0]$ ls
aclocal.m4    config.h     config.status  configure.ac~   doc        Makefile.am  missing  stamp-h1
autom4te.cache    config.h.in  configure        configure.scan  install-sh    Makefile.in  script
autoscan.log    config.log   configure.ac   depcomp        Makefile    man         src
[fpxshyy@localhost summary-1.0.0]$




Step-By-Step Example of Autotools for Beginner

Dec 3rd, 2012 | Comments

This is a simple autotools example for beginner. You can easily follow it. After that you should be able to use autotools for your own project without complex features. This example shows how to use autoconf/automake, how to edit configure.ac/Makefile.am and how to disable default CFLAGS=’-g -O2’ for debug etc. OK, let’s do it!

autoconf version: 2.68
automake version: 1.11.3
Ubuntu 12.04

Create Sources

If you want to use autotools in your project, first of all you should have an existing one. following is an example I use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
summary-1.0.0
    ├── doc             #project documents
    │   └── OVERVIEW
    ├── man             #manuals
    │   └── summary.8
    ├── script          #useful scripts
    │   └── summary.sh
    └── src             #source code
        ├── lib         #general functions
        │   ├── lib.c
        │   └── lib.h
        └── person      #one program
            ├── do.c
            ├── do.h
            ├── main.c
            └── main.h

you can DOWNLOAD this project. Of course, you can create your own project.

Autoconf

Generating configure.ac In summary-1.0.0, Use autoscan

airead@airead:/tmp/summary-1.0.0$ ls
doc man script src
airead@airead:/tmp/summary-1.0.0$ autoscan
airead@airead:/tmp/summary-1.0.0$ ls
autoscan.log configure.scan doc man script src
airead@airead:/tmp/summary-1.0.0$
airead@airead:/tmp/summary-1.0.0$ mv configure.scan configure.ac
airead@airead:/tmp/summary-1.0.0$ ls
autoscan.log configure.ac doc man script src

autoscan produces two files autoscan.log and configure.scan. Then we rename configure.scan to configure.ac which will be used by autoconf.

The configure is not perfect, so we should edit it.

1
2
3
4
mv
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
to
AC_INIT([summary], [1.0.0], [fgh1987168@gmail.com]) #or your E-mail

Generating configure, Use autoconf

airead@airead:/tmp/summary-1.0.0$ ls
autoscan.log configure.ac doc man script src
airead@airead:/tmp/summary-1.0.0$ autoconf
airead@airead:/tmp/summary-1.0.0$ ls
autom4te.cache configure doc script
autoscan.log configure.ac man src

autoconf produces shell script configure used by user and autom4te.cache which you can safely remove it. We already have configure, but where is the Makefile?

Automake

The Relationship Between Makefile.am, Makefile.in And Makefile

Makefile.am is a programmer-defined file and is used by automake to generate the Makefile.in file. The ./configure script will use the Makefile.in to generate a Makefile.

Create Makefile.am

We now prepare the Makefile.am file for each of directories. Automake will step into each of them and produce the corresponding Makefile.in file.

airead@airead:/tmp/summary-1.0.0$ vim Makefile.am

1
2
AUTOMAKE_OPTIONS = foreign
SUBDIRS = doc man script src

the first line sets automake mode. “foreign” means not GNU, and is common for avoiding boring messages about files organized differently from what gnu expects.
The second line shows a list of subdirectories to descend for further work.

airead@airead:/tmp/summary-1.0.0$ vim man/Makefile.am

1
man_MANS = summary.8

In general, the uppercase, suffix part like “_PROGRAMS” is called primary and tells partially what to perform on the argument; the lowecase, prefix (it’s not given a name) tells the directory where to install. So man_MANS installs manuals at $(PREFIX)/share/man.

airead@airead:/tmp/summary-1.0.0$ vim script/Makefile.am

1
bin_SCRIPTS = summary.sh

installs scripts in $(PREFIX)/bin

airead@airead:/tmp/summary-1.0.0$ vim doc/Makefile.am

1
2
docdir = $(datadir)/doc/@PACKAGE@
doc_DATA = OVERVIEW

if “abc” is wanted for prefix, “abcdir” is to be specified. E.g. the code above expands to $(PREFIX)/share/doc/summary (“@PACKAGE@” will be expanded by autoconf when producing the final Makefile, see below). $(datadir) is known by all configure scripts it generates, $(PREFIX)/share.

Now let’s create src/Makefile.am, it’s a little complex.airead@airead:/tmp/summary-1.0.0$ vim src/Makefile.am

1
SUBDIRS=lib person

it shows a list of subdirectories to descend for further work. Continue to create…

airead@airead:/tmp/summary-1.0.0$ vim src/lib/Makefile.am

1
2
noinst_LIBRARIES=libutils.a
libutils_a_SOURCES=lib.c lib.h

The special prefix noinst_ indicates that the objects in question should be built but not installed at all. Each _LIBRARIES variable is a list of the libraries to be built. So noinst_LIBRARIES build libutils.a but not install. _SOURCES list sources of libutils.a.
Extra objects can be added to a library using the library_LIBADD variable.

airead@airead:/tmp/summary-1.0.0$ vim src/person/Makefile.am

1
2
3
4
5
AM_CFLAGS = -I../lib

bin_PROGRAMS = summary
summary_SOURCES = main.c main.h do.c do.h
summary_LDADD = ../lib/libutils.a

Variables that end with _PROGRAMS are special variables that list programs that the resulting Makefile should build. bin_PROGRAMS indicates that program summary should be built and install in $(PREFIX)/bin. its sources shows in summary_LDADD. summary_LDADD indicates that the program needs libutils.a when linking.

Generating Makefile.in, Use automake

let’s run automake:airead@airead:/tmp/summary-1.0.0$ automake
configure.ac: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal).
automake: no `Makefile.am' found for any configure output
automake: Did you forget AC_CONFIG_FILES([Makefile]) in configure.ac?

So we should edit configure.ac again. add following after AC_INIT() in configure.ac.

1
AM_INIT_AUTOMAKE(summary, 1.0.0)

Integrating The Checking (Autoconf) Part And The Building (Automake) Part

Now there are some new Makefile.am in each of directories, so we should reautoscan for extra information in the project.
airead@airead:/tmp/summary-1.0.0$ autoscanairead@airead:/tmp/summary-1.0.0$ diff configure.ac configure.scan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
5c5
< AC_INIT([summary], [1.0.0], [fgh1987168@gmail.com])
---
> AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
9,10d8
< AM_INIT_AUTOMAKE(summary, 1.0.0)
<
22a21,27
> AC_CONFIG_FILES([Makefile
>                  doc/Makefile
>                  man/Makefile
>                  script/Makefile
>                  src/Makefile
>                  src/lib/Makefile
>                  src/person/Makefile])

we found that the configure.ac misses the AC_CONFIG_FILES([*]), so put those above AC_OUTPUT in configure.ac. after that, run following command:

airead@airead:/tmp/summary-1.0.0$ aclocal
airead@airead:/tmp/summary-1.0.0$ autoheader
airead@airead:/tmp/summary-1.0.0$ autoconf

aclocal program creates the file ‘aclocal.m4’ by combining stock installed macros, user defined macros and the contents of ‘acinclude.m4’ to define all of the macros required by ‘configure.ac’ in a single file.
autoheader runs m4 over ‘configure.ac’, but with key macros defined differently than when autoconf is executed, such that suitable cpp definitions are output to ‘config.h.in’.
autoconf expands the m4 macros in ‘configure.ac’, perhaps using macro definitions from ‘aclocal.m4’, to generate the configure script.

Then we call automake to generate Makefile.in.airead@airead:/tmp/summary-1.0.0$ automake --add-missing
configure.ac:9: installing `./install-sh'
configure.ac:9: installing `./missing'
src/lib/Makefile.am:1: library used but `RANLIB' is undefined
src/lib/Makefile.am:1: The usual way to define `RANLIB' is to add `AC_PROG_RANLIB'
src/lib/Makefile.am:1: to `configure.ac' and run `autoconf' again.
src/lib/Makefile.am: installing `./depcomp'

Read the error information and fix it by puting AC_PROG_RANLIB after AC_INIT_AUTOMAKE() in configure.ac. run automake again.
airead@airead:/tmp/summary-1.0.0$ automake

Now we have one usable configure script.

Build Project

airead@airead:/tmp/summary-1.0.0$ ./configure
configure do two things:

  1. scan for dependencies on the basis of the AC_* macros instructed in configure.ac. If there’s something wrong/missing in the system, an opportune error message will be dumped.
  2. for each Makefile requested in AC_OUTPUT(), translate the Makefile.in template for generating the final Makefile. The main makefile will provide the most common targets like install, clean, distclean, uninstall et al.

If configure succeeds, all the Makefile files are available. Run make.airead@airead:/tmp/summary-1.0.0$ make
If no accident, make will products src/lib/libutils.a and src/person/summary which we can execute. Run following if you like.
airead@airead:/tmp/summary-1.0.0$ make install

Change Default CFLAGS For Debug

autoconf default CFLAGS is ‘-g -O2’, it is inconvenient to debug program. How to change this?
Macro AC_PROG_CC in configure.ac determines a C compiler to use. If using the GNU C compiler, set shell variable GCC to ‘yes’. If output variable CFLAGS was not already set, set it to ‘-g -O2’ for the GNU C compiler (‘-O2’ on systems where GCC does not accept ‘-g’), or ‘-g’ for other compilers.
Put CFLAGS="-g -O0" above AC_PROG_CC, then
airead@airead:/tmp/summary-1.0.0$ autoreconf
It works well.
note: There is no space on either side of =.

References



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值