learn_autotools Documentation Release 1.0.0

Sues

Jan 19, 2018

Contents:

1 autotools 1 1.1 autotools...... 1 1.2 autotools...... 1 1.3 autotools...... 1 1.4...... 2

2 flow 3 2.1...... 4 2.2...... 5

3 flow_intent 7 3.1...... 9 3.2...... 9

4 files_todo 11 4.1 content in configure.ac...... 11 4.2 content in Makefile.am...... 12 4.3 configure.ac...... 12 4.4 Makefile.am...... 12

5 build 13 5.1 prepare...... 13 5.2 configure...... 13 5.3 ...... 14 5.4 make install...... 14 5.5 target else...... 14

6 15

7 17

8 pkg-config 21 8.1...... 22 8.2...... 22 8.3...... 22

9 libtool 25 9.1 libtool...... 26

i 9.2 libtool...... 26 9.3...... 26 9.4...... 26

10 Indices and tables 29

ii CHAPTER 1

autotools

building useful, solid and distribution-friendly packages autotools , useful solid distribution-friendly ? ,, makefile autotools , ./configure;make;make install

1.1 autotools

GNU build chain

1.2 autotools autoconf, automake, libtool, pkg-config, and so on. autoconf configure automake Makefile.in libtool gcc pkg-config

1.3 autotools autoconf automake *nix ,, Makefile ,autoconf automake autoconf configure autoconf automake libtool pkg-config

1 learn_autotools Documentation, Release 1.0.0 autoconf automake , makefile.am pkg-config libtool pkg-config autoconf automake libtool

1.4 autotools

2 Chapter 1. autotools CHAPTER 2

flow

, autoscan autoconf autoscan autoheader aclocal automake autoconf ,,

1/ ,Makefile.am

2/ autoscan

3/ mv configure.scan configure.ac

4/ autoheader

5/ add AM_INIT_AUTOMAKE to configure.ac

6/ aclocal

7/ automake --add-missing --copy

8/ autoconf

9/ ./configure

10/

3 learn_autotools Documentation, Release 1.0.0

make

11/ make install

----

autoscan update configure.ac(compare configure.scan with configure.ac) autoreconf

2.1

,5,configure.ac Makefile.am

4 Chapter 2. flow learn_autotools Documentation, Release 1.0.0

2.2 autotools2 .. autotools2 : http://www.lugod.org/presentations/autotools/presentation/autotools.pdf

2.2. 5 learn_autotools Documentation, Release 1.0.0

6 Chapter 2. flow CHAPTER 3

flow_intent

,,

1/ ,Makefile.am Makefile.am automake Makefile.in Makefile.in ./configure Makefile

2/ autoscan configure.scan

3/ mv configure.scan configure.ac

4/ autoheader config.h.in config.h.in ./cofnigure config.h

5/ configure.ac AC_INIT AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE automake

6/ aclocal aclocalperl.aclocalconfigure.ac,aclocal.

7/ automake --add-missing --copy Makefile.am configure.ac Makefile.in

7 learn_autotools Documentation, Release 1.0.0

8/ autoconf aclocal.m4 configure.ac configure

9/ ./configure configure Makefile.in Makefile configure config.h.in config.h

10/ make

11/ make install

----

autoscan update configure.ac(compare configure.scan with configure.ac) autoreconf

8 Chapter 3. flow_intent learn_autotools Documentation, Release 1.0.0

3.1

,5,

3.2 autotools2 .. autotools2 : http://www.lugod.org/presentations/autotools/presentation/autotools.pdf

3.1. 9 learn_autotools Documentation, Release 1.0.0

10 Chapter 3. flow_intent CHAPTER 4

files_todo

configure.ac Makefile.am

4.1 content in configure.ac

AM_INIT_AUTOMAKE

AC_CHECK_ AC_PROG_CC

AC_OUTPUT(FILE)Makefile.

, AC_INITAC_OUTPUT automake,,aclocal.aclocalaclocal.m4. configure.scan,.configure.ac autoconfconfigure.configure,, Makefile,. configure.ac,autoconfshell. configure.ac,AC_INITAC_OUTPUT. configure.ac #,. AC_INIT([FULL-PACKAGE-NAME],[VERSION],[BUG-REPORT-ADDRESS]) (FULL-PACKAGE-NAMEVERSIONBUG-REPORT-ADDRESSbug make dist,helloworld-1.0.tar.gz,. AM_INIT_AUTOMAKEautomake AC_PROG_CCC. configure.acaclocal.m4,autoconfconfigure

11 learn_autotools Documentation, Release 1.0.0

4.2 content in Makefile.am

Makefile.amMakefile.in,.Makefile.am AUTOMAKE_OPTIONS automake.automake,GNU, AUTHORS.ChangeLog.NEWS.foreign,automake. bin_PROGRAMS .,. helloworld_SOURCES "helloworld".,. helloworld.h,helloworld.c:helloworld_SOURCES= helloworld.h helloworld.c. bin_PROGRAMS,filename_SOURCES. _LDADD _LDFLAGS _CFLAGS

4.3 configure.ac

M4sh shM4

AS_IF[TEST1][TRUE][TEST2][TRUE2][FALSE]

4.4 Makefile.am

12 Chapter 4. files_todo CHAPTER 5

build

autotools

5.1 prepare

5.2 configure

./configure Makefile.in config.h.in() ./configure Makefile config.h configure

./configure

./configure VAR=xxx , Makefile config.h sudo

./configure --prefix=path /usr/local/

$./configure --help |grep prefix -3 --srcdir=DIR find the sources in DIR [configure dir or `..']

13 learn_autotools Documentation, Release 1.0.0

Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX]

By default, `make install' will install all the files in `/usr/local/bin', `/usr/local/lib' etc. You can specify an installation prefix other than `/usr/local' using `--prefix', for instance `--prefix=$HOME'.

5.3 make

.o .a .so .la

5.4 make install

sudo

,

$ls -l /usr/ |grep local drwxr-xr-x 14 root root 4096 12 26 11:37 local

5.5 target else

GNU MakefielMakefile, make Makefile,,,. make clean makeobject".o". make install ,/usr/local/bin. make dist distribution package.tar.gz. "PACKAGE-VERSION.tar.gz".PACKAGEVERSION,configure.acAC_INIT([FULL-PACKAGE-NAME],

˓→[VERSION],[BUG-REPORT-ADDRESS]). make distcheck ,.

14 Chapter 5. build CHAPTER 6

autoconf

autoconf

/. /etc /etc/emacs /etc/emacs/site-start.d /etc/emacs/site-start.d/50autoconf.el /usr /usr/bin /usr/bin/autoscan /usr/bin/autoreconf /usr/bin/autom4te /usr/bin/autoupdate /usr/bin/ifnames /usr/bin/autoconf /usr/bin/autoheader /usr/share /usr/share/doc /usr/share/doc/autoconf /usr/share/doc/autoconf/README.Debian /usr/share/doc/autoconf/NEWS.gz /usr/share/doc/autoconf/README /usr/share/doc/autoconf/changelog.Debian.gz /usr/share/doc/autoconf/NEWS.Debian.gz /usr/share/doc/autoconf/copyright /usr/share/man /usr/share/man/man1 /usr/share/man/man1/ifnames.1.gz /usr/share/man/man1/autom4te.1.gz /usr/share/man/man1/autoconf.1.gz /usr/share/man/man1/autoheader.1.gz /usr/share/man/man1/autoupdate.1.gz /usr/share/man/man1/autoscan.1.gz /usr/share/man/man1/config.guess.1.gz /usr/share/man/man1/autoreconf.1.gz

15 learn_autotools Documentation, Release 1.0.0

/usr/share/man/man1/config.sub.1.gz /usr/share/emacs /usr/share/emacs/site-lisp /usr/share/emacs/site-lisp/autoconf /usr/share/emacs/site-lisp/autoconf/autotest-mode.el /usr/share/autoconf /usr/share/autoconf/autoscan /usr/share/autoconf/autoscan/autoscan.list /usr/share/autoconf/Autom4te /usr/share/autoconf/Autom4te/XFile.pm /usr/share/autoconf/Autom4te/C4che.pm /usr/share/autoconf/Autom4te/Channels.pm /usr/share/autoconf/Autom4te/Configure_ac.pm /usr/share/autoconf/Autom4te/ChannelDefs.pm /usr/share/autoconf/Autom4te/Request.pm /usr/share/autoconf/Autom4te/General.pm /usr/share/autoconf/Autom4te/FileUtils.pm /usr/share/autoconf/Autom4te/Getopt.pm /usr/share/autoconf/INSTALL /usr/share/autoconf/autotest /usr/share/autoconf/autotest/general.m4 /usr/share/autoconf/autotest/autotest.m4 /usr/share/autoconf/autotest/autotest.m4f /usr/share/autoconf/autotest/specific.m4 /usr/share/autoconf/m4sugar /usr/share/autoconf/m4sugar/m4sugar.m4 /usr/share/autoconf/m4sugar/m4sh.m4 /usr/share/autoconf/m4sugar/version.m4 /usr/share/autoconf/m4sugar/foreach.m4 /usr/share/autoconf/m4sugar/m4sugar.m4f /usr/share/autoconf/m4sugar/m4sh.m4f /usr/share/autoconf/autom4te.cfg /usr/share/autoconf/autoconf /usr/share/autoconf/autoconf/functions.m4 /usr/share/autoconf/autoconf/status.m4 /usr/share/autoconf/autoconf/lang.m4 /usr/share/autoconf/autoconf/headers.m4 /usr/share/autoconf/autoconf/autoconf.m4f /usr/share/autoconf/autoconf/oldnames.m4 /usr/share/autoconf/autoconf/autoheader.m4 /usr/share/autoconf/autoconf/go.m4 /usr/share/autoconf/autoconf/erlang.m4 /usr/share/autoconf/autoconf/general.m4 /usr/share/autoconf/autoconf/types.m4 /usr/share/autoconf/autoconf/.m4 /usr/share/autoconf/autoconf/autotest.m4 /usr/share/autoconf/autoconf/specific.m4 /usr/share/autoconf/autoconf/autoconf.m4 /usr/share/autoconf/autoconf/c.m4 /usr/share/autoconf/autoconf/libs.m4 /usr/share/autoconf/autoconf/autoupdate.m4 /usr/share/autoconf/autoconf/programs.m4 /usr/share/autoconf/autoconf/autoscan.m4

16 Chapter 6. autoconf CHAPTER 7

automake

/. /usr /usr/bin /usr/bin/automake-1.15 /usr/bin/aclocal-1.15 /usr/share /usr/share/automake-1.15 /usr/share/automake-1.15/texinfo.tex /usr/share/automake-1.15/ylwrap /usr/share/automake-1.15/install-sh /usr/share/automake-1.15/depcomp /usr/share/automake-1.15/am /usr/share/automake-1.15/am/ltlibrary.am /usr/share/automake-1.15/am/texibuild.am /usr/share/automake-1.15/am/ltlib.am /usr/share/automake-1.15/am/distdir.am /usr/share/automake-1.15/am/configure.am /usr/share/automake-1.15/am/scripts.am /usr/share/automake-1.15/am/lang-compile.am /usr/share/automake-1.15/am/clean.am /usr/share/automake-1.15/am/subdirs.am /usr/share/automake-1.15/am/java.am /usr/share/automake-1.15/am/header-vars.am /usr/share/automake-1.15/am/texi-vers.am /usr/share/automake-1.15/am/data.am /usr/share/automake-1.15/am/install.am /usr/share/automake-1.15/am/remake-hdr.am /usr/share/automake-1.15/am/check.am /usr/share/automake-1.15/am/lisp.am /usr/share/automake-1.15/am/libtool.am /usr/share/automake-1.15/am/python.am /usr/share/automake-1.15/am/footer.am /usr/share/automake-1.15/am/library.am /usr/share/automake-1.15/am/mans.am /usr/share/automake-1.15/am/libs.am

17 learn_autotools Documentation, Release 1.0.0

/usr/share/automake-1.15/am/header.am /usr/share/automake-1.15/am/compile.am /usr/share/automake-1.15/am/check2.am /usr/share/automake-1.15/am/progs.am /usr/share/automake-1.15/am/mans-vars.am /usr/share/automake-1.15/am/yacc.am /usr/share/automake-1.15/am/lex.am /usr/share/automake-1.15/am/dejagnu.am /usr/share/automake-1.15/am/program.am /usr/share/automake-1.15/am/tags.am /usr/share/automake-1.15/am/inst-vars.am /usr/share/automake-1.15/am/depend.am /usr/share/automake-1.15/am/texinfos.am /usr/share/automake-1.15/am/depend2.am /usr/share/automake-1.15/am/vala.am /usr/share/automake-1.15/am/clean-hdr.am /usr/share/automake-1.15/compile /usr/share/automake-1.15/ar-lib /usr/share/automake-1.15/COPYING /usr/share/automake-1.15/test-driver /usr/share/automake-1.15/mkinstalldirs /usr/share/automake-1.15/INSTALL /usr/share/automake-1.15/missing /usr/share/automake-1.15/py-compile /usr/share/automake-1.15/tap-driver.sh /usr/share/automake-1.15/Automake /usr/share/automake-1.15/Automake/XFile.pm /usr/share/automake-1.15/Automake/Channels.pm /usr/share/automake-1.15/Automake/Variable.pm /usr/share/automake-1.15/Automake/VarDef.pm /usr/share/automake-1.15/Automake/Version.pm /usr/share/automake-1.15/Automake/Wrap.pm /usr/share/automake-1.15/Automake/Condition.pm /usr/share/automake-1.15/Automake/RuleDef.pm /usr/share/automake-1.15/Automake/Language.pm /usr/share/automake-1.15/Automake/DisjConditions.pm /usr/share/automake-1.15/Automake/Item.pm /usr/share/automake-1.15/Automake/Rule.pm /usr/share/automake-1.15/Automake/FileUtils.pm /usr/share/automake-1.15/Automake/Options.pm /usr/share/automake-1.15/Automake/Configure_ac.pm /usr/share/automake-1.15/Automake/General.pm /usr/share/automake-1.15/Automake/Config.pm /usr/share/automake-1.15/Automake/ChannelDefs.pm /usr/share/automake-1.15/Automake/Getopt.pm /usr/share/automake-1.15/Automake/ItemDef.pm /usr/share/automake-1.15/Automake/Location.pm /usr/share/automake-1.15/mdate-sh /usr/share/info /usr/share/info/automake-1.15.info.gz /usr/share/info/automake-1.15.info-1.gz /usr/share/info/automake-1.15.info-2.gz /usr/share/doc-base /usr/share/doc-base/automake-1.15 /usr/share/lintian /usr/share/lintian/overrides /usr/share/lintian/overrides/automake /usr/share/aclocal-1.15

18 Chapter 7. automake learn_autotools Documentation, Release 1.0.0

/usr/share/aclocal-1.15/maintainer.m4 /usr/share/aclocal-1.15/sanity.m4 /usr/share/aclocal-1.15/as.m4 /usr/share/aclocal-1.15/ar-lib.m4 /usr/share/aclocal-1.15/auxdir.m4 /usr/share/aclocal-1.15/depend.m4 /usr/share/aclocal-1.15/python.m4 /usr/share/aclocal-1.15/extra-recurs.m4 /usr/share/aclocal-1.15/missing.m4 /usr/share/aclocal-1.15/init.m4 /usr/share/aclocal-1.15/runlog.m4 /usr/share/aclocal-1.15/dmalloc.m4 /usr/share/aclocal-1.15/obsolete.m4 /usr/share/aclocal-1.15/tar.m4 /usr/share/aclocal-1.15/make.m4 /usr/share/aclocal-1.15/mkdirp.m4 /usr/share/aclocal-1.15/options.m4 /usr/share/aclocal-1.15/silent.m4 /usr/share/aclocal-1.15/vala.m4 /usr/share/aclocal-1.15/strip.m4 /usr/share/aclocal-1.15/substnot.m4 /usr/share/aclocal-1.15/cond.m4 /usr/share/aclocal-1.15/lead-dot.m4 /usr/share/aclocal-1.15/install-sh.m4 /usr/share/aclocal-1.15/internal /usr/share/aclocal-1.15/internal/ac-config--dirs.m4 /usr/share/aclocal-1.15/gcj.m4 /usr/share/aclocal-1.15/prog-cc-c-o.m4 /usr/share/aclocal-1.15/upc.m4 /usr/share/aclocal-1.15/amversion.m4 /usr/share/aclocal-1.15/cond-if.m4 /usr/share/aclocal-1.15/lex.m4 /usr/share/aclocal-1.15/lispdir.m4 /usr/share/aclocal-1.15/depout.m4 /usr/share/aclocal /usr/share/doc /usr/share/doc/automake /usr/share/doc/automake/NEWS.gz /usr/share/doc/automake/AUTHORS /usr/share/doc/automake/copyright /usr/share/doc/automake/changelog.Debian.gz /usr/share/doc/automake/README.Debian /usr/share/doc/automake/README /usr/share/man /usr/share/man/man1 /usr/share/man/man1/automake-1.15.1.gz /usr/share/man/man1/aclocal-1.15.1.gz /usr/share/automake-1.15/config.sub /usr/share/automake-1.15/config.guess

19 learn_autotools Documentation, Release 1.0.0

20 Chapter 7. automake CHAPTER 8

pkg-config

/. /usr /usr/share /usr/share/aclocal /usr/share/aclocal/pkg.m4 /usr/share/man /usr/share/man/man1 /usr/share/man/man1/pkg-config.1.gz /usr/share/pkgconfig /usr/share/pkg-config-dpkghook /usr/share/doc /usr/share/doc/pkg-config /usr/share/doc/pkg-config/README /usr/share/doc/pkg-config/copyright /usr/share/doc/pkg-config/changelog.Debian.gz /usr/share/doc/pkg-config/pkg-config-guide.html /usr/share/doc/pkg-config/NEWS.gz /usr/share/doc/pkg-config/AUTHORS /usr/share/pkg-config-crosswrapper /usr/lib /usr/lib/pkgconfig /usr/lib/pkg-config.multiarch /usr/bin /usr/bin/x86_64-pc-linux--pkg-config /usr/bin/pkg-config /etc /etc/dpkg /etc/dpkg/dpkg.cfg.d /etc/dpkg/dpkg.cfg.d/pkg-config-hook-config

21 learn_autotools Documentation, Release 1.0.0

8.1

8.2

$ pkg-config --cflags lua5.2 -I/usr/include/lua5.2 $ pkg-config --libs lua5.2 -llua5.2

$ pkg-config --cflags zlib -I/usr/local/include $ pkg-config --libs zlib -L/usr/local/lib -lz

$(pkg-config --cflags lua5.2) `pkg-config --cflags lua5.2` gcc -c test.c`pkg-config --cflags lua5.2` -o test.o gcc test.o main.o`pkg-config --libs lua5.2`

Makefile CFLAGS +=`pkg-config --cflags sqlite3` LDFLAGS +=`pkg-config --libs sqlite3`

8.3 pkg-config option xxx

xxx.pc xxx.pc

pkgconfig .pc,.

pkgconfig $ locate pkgconfig |xargs file |awk '/directory/ {print $1}' | sed 's/://' /usr/lib/pkgconfig /usr/lib/i386-linux-gnu/pkgconfig /usr/local/lib/pkgconfig /usr/share/pkgconfig

pkg-config looks in /usr/lib/pkgconfig /usr/share/pkgconfig /usr/local/lib/pkgconfig /usr/local/share/pkgconfig

22 Chapter 8. pkg-config learn_autotools Documentation, Release 1.0.0

PKG_CONFIG_PATH export PKG_CONFIG_PATH=/opt//lib/pkgconfig:$PKG_CONFIG_PATH xxx.pc

1: prefix=/usr/local exec_prefix=${prefix} libdir=${exec_prefix}/lib sharedlibdir=${libdir} includedir=${prefix}/include

Name: xxx Description: xxx compression library Version:1.2.8

Requires: Libs: -L${libdir} -L${sharedlibdir} -lz Cflags: -I${includedir} man: Here is an example file: # This is a comment prefix=/home/hp/unst # this defines a variable exec_prefix=${prefix} # defining another variable in terms of the first libdir=${exec_prefix}/lib includedir=${prefix}/include

Name: GObject # human-readable name Description: Object/type system for GLib # human-readable description Version:1.3.1 URL: http://www.gtk.org

Requires: glib-2.0=1.3.1 Conflicts: foobar <=4.5 Libs: -L${libdir} -lgobject-1.3 Libs.private: -lm Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib/include

8.3. 23 learn_autotools Documentation, Release 1.0.0

24 Chapter 8. pkg-config CHAPTER 9

libtool

/. /usr /usr/bin /usr/bin/libtoolize /usr/share /usr/share/aclocal /usr/share/aclocal/ltversion.m4 /usr/share/aclocal/libtool.m4 /usr/share/aclocal/ltsugar.m4 /usr/share/aclocal/ltargz.m4 /usr/share/aclocal/lt~obsolete.m4 /usr/share/aclocal/ltoptions.m4 /usr/share/libtool /usr/share/libtool/build-aux /usr/share/libtool/build-aux/install-sh /usr/share/libtool/build-aux/depcomp /usr/share/libtool/build-aux/compile /usr/share/libtool/build-aux/ltmain.sh /usr/share/libtool/build-aux/missing /usr/share/doc /usr/share/doc/libtool /usr/share/doc/libtool/NEWS.gz /usr/share/doc/libtool/THANKS.gz /usr/share/doc/libtool/AUTHORS /usr/share/doc/libtool/copyright /usr/share/doc/libtool/changelog.Debian.gz /usr/share/doc/libtool/README.Debian /usr/share/doc/libtool/README /usr/share/doc/libtool/TODO.gz /usr/share/man /usr/share/man/man1 /usr/share/man/man1/libtoolize.1.gz /usr/share/libtool/build-aux/config.sub /usr/share/libtool/build-aux/config.guess

25 learn_autotools Documentation, Release 1.0.0

9.1 libtool

$ file /usr/bin/libtool /usr/bin/libtool: Bourne-Again shell script, ASCII text executable

9.2 libtool

,libool pkg-config gcc

,

libtool , libtool ,

,,

,,

, 1, 2,,

, lo la , ,2

9.3

libtool --mode=compile gcc -g -O -c foo.c libtool --mode=compile --tag=CC mipsel-linux-gcc -g -I../include -c BTX.c 1 libtool --mode=link gcc -g -O -o libhello.la foo.o hello.o libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo -rpath /usr/local/lib -lm 2 libtool --mode=link gcc -g -O -o hell main.o libhello.la

.c .la() .lo() , .o

9.4

1..libs

2.-fPICobj .lib

3.obj

26 Chapter 9. libtool learn_autotools Documentation, Release 1.0.0

4. .lo

1..lo .la

2. .la

9.4. 27 learn_autotools Documentation, Release 1.0.0

28 Chapter 9. libtool CHAPTER 10

Indices and tables

• genindex • modindex • search

29