Anda di halaman 1dari 10

GNU make

make
makefile

Makefile make
makefile autoconf
automake makefile

makefile
automake,autoconf makefile

|
autoscan*
|
configure.scan
|
*
|
makefile.am configure.in --aclocal*--> aclocal.m4
\ ____ / \ __________ /
\/ \/
automake* autoconf*
| |
makefile.in configure
\ ____ /
\ /
./configure*
|
makefile
makefile make

(1). autoscan configure.scan


(2). configure.scan configure.in
(3). autoheader configure.h.in configure.acconfigure.in
AC_CONFIG_HEADER()
(4). libtoolizeltmain.sh libtool
(5). allocal aclocal.m4
(6). autoconf configure
(7). makefie.am makefile.am
(8). automake makefile.in makefile.am makefile.in
automake -a config.guessconfig.subinstall-shmissingdepcomp
(9)../configure config.statusconfig.hmakefile
(10). make
(11). make install
makefile
C main.cadd/add.c sub/sub.c
/*main.c*/
#include<stdio.h>
int main(void)
{
printf("%d\n",add(sub(100,5),1));
return 0;
}
/* add/add.c */
int add(int x,int y)
{
return x+y;
}
/* sub/sub.c */
int sub(int x,int y)
{
return x-y;
}
add.c sub.c main.c

1. configure.in makefile.am
Q makefile
configure.in makefile.am
(1). configure.in
autoscan configure.scan
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])
AC_INIT([FULL-PACKAGE-NAME],[VERSION],[BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT
configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])
AC_INIT(hellobb,1.0,[])
AM_INIT_AUTOMAKE(hellobb,1.0)
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT(Makefile add/Makefile sub/Makefile)

AC_INIT AC_OUTPUT AC_INIT AC_OUTPUT


AC_INIT
AC_OUTPUT shell configure
AM_INIT_AUTOMAKE automake
AC_PROG_CC C CC gcc cc C
CC
AC_PROG_LIBTOOL LIBTOOL
AC_CONFIG_SRCDIR([main.c])./configure main.c
AC_CONFIG_HEADER([config.h])./configure config.h.in config.h config.h
#define c -
DHAVE_CONFIG_H -Dmacro
#AC_CONFIG_HEADER([config.h])make main.c
gcc -DPACKAGE_NAME=\"hellobb\" -DPACKAGE_TARNAME=\"hellobb\" DPACKAGE-V
ERSION=\"1.0\" -DPACKAGE_STRING=\"hellobb\ 1.0\" -DPACKAGE_BUGREPORT=\"\" D
PACKAGE=\"hellobb\" -DVERSION=\"1.0\" -DSTDC_HEADERS=1 _DHAVE_SYS_TYPES_
H=1 -DHAVE_UNISTDLIB_H=1 -DHAVE_STING_H=1 -DHAVE_MEMORY_H=1 dHAVE_
STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_ H=1
-DHAVE_DLFCN_H=1 -DLT_OBJDIR=\"./libs/\" -I. -g -O2 -MT main.o -MD -MP MF .deps
/main.Tpo -c -o main.c main.c
AC_CONFIG_HEADER([config.h])make main.c
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o
main.c
-Dmacro config.h -
DHAVE_CONFIG_H

(2). makefile.am
makefile.am
add/makefile.am sub/makefile.am
lib_LTLIBRARIES = libadd.la // libadd.la
libadd_la_SOURCES = add.c // libadd.la
makefile.am
AUTOMAKE_OPTIONS = foreign
SUBDIRS = add sub // makefile.am
bin_PROGRAMS = main // main
main_SOURCES = main.c // main
main_LDADD = add/libadd.la sub/libsub.la // main

(3).automake automake -a
automake -a automake -add-missing config.guess,config.sub,missing,
depcomp,install-shautomake

2.
Q./configure
Qmake
autoscan,autoheader,automake,autoconf

main.c add/add.c sub/sub.c


makefile.am makefile.am add/makefile.am sub/makefile.am
autoscan configure.scan
autoscan.log
(configure.scan)
configure.in //./configure

autoheader config.h.in
libtoolize ltmain.sh
aclocal aclocal.m4 //autoconf m4
autom4te.cache
autoconf (configure.in, aclocal.m4)
configure
automake -a (configure.in makefile.am add/makefile.am sub/makefile.am)
config.guess //
config.sub //
CPU_TYPE_MANUFACTORER-KERNEL-OPERATING-SYSTEM
install-sh //
missing // Common stub for a few missing GNU program while installing.
depcomp //Compile a program generating depedencies as side-effects.
makefile.in add/makefile.in sub/makefile.in
./configure (configure makefile.in add/makefile.in sub/makefile.in config.h.in )
(config.guess config.sub install-sh missing depcomp ltmainsh)
config.status //configure
./configure shell config.status
config.h //
config.log //./configure
makefile add/makefile sub/makefile
./deps/main.Po add/.deps/add.Plo sub/.deps.sub.Plo // dummy
stamp-h1
make (config.status config.h makefile add/makefile sub/makefile)
libtool
add.lo add.o libadd.la
add/.libs add.o libadd.a libadd.la libsub.lai libadd.so libadd.so.0 libadd.so.0.0.0
sub.lo sub.o libsub.la
sub/.libs sub.o libsub.a libsub.la libsub.lai libsub.so libsub.so.0 libsub.so.0.0.0

./deps/main.Po add/.deps/add.Plo sub/.deps.sub.Plo // gcc -MT,-MD,-MP,


-MF
main.o
main

3.configure make
Q./configure config.status
Qmake
configure
configure shell autoconf
POSIX Makefile
./configure
configure.in configure
AC_INIT,AM_INIT_AUTOMAKE,AC_PROG_CC
AC_PROG_LIBTOOL
AC_OUTPUT
configure config.status configure
config.status config.status

configure config.status makefile

-g

configure cpu-vendor-os
config.guess uname

configure config.sub

# ./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... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
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 build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1966080
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking how to run the C preprocessor... gcc -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 dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating add/Makefile
config.status: creating sub/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

make
make
makefile.am makefile
SUBDIRS = add sub make Makefile
main_LDADD = add/libadd.la sub/libsub.la main libadd.la libsub.la
configure.in makefile
AC_PROG_LIBTOOL libtool
AC_CONFIG_HEADERS([config.h])-DHAVE_CONFIG_H
makefile configure
config.status config.h
CC CFLAGS makefile
makefile
# make
make all-recursive
make[1]: Entering directory `/root/program/hello_autoconf2'
Making all in add
make[2]: Entering directory `/root/program/hello_autoconf2/add'
/bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT add.lo
-MD -MP -MF .deps/add.Tpo -c -o add.lo add.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT add.lo -MD -MP -MF
.deps/add.Tpo -c add.c -fPIC -DPIC -o .libs/add.o
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT add.lo -MD -MP -MF
.deps/add.Tpo -c add.c -o add.o >/dev/null 2>&1
mv -f .deps/add.Tpo .deps/add.Plo
/bin/sh ../libtool --tag=CC --mode=link gcc -g -O2 -o libadd.la -rpath /usr/local/lib add.lo
libtool: link: gcc -shared .libs/add.o -Wl,-soname -Wl,libadd.so.0 -o .libs/libadd.so.0.0.0
libtool: link: (cd ".libs" && rm -f "libadd.so.0" && ln -s "libadd.so.0.0.0" "libadd.so.0")
libtool: link: (cd ".libs" && rm -f "libadd.so" && ln -s "libadd.so.0.0.0" "libadd.so")
libtool: link: ar cru .libs/libadd.a add.o
libtool: link: ranlib .libs/libadd.a
libtool: link: ( cd ".libs" && rm -f "libadd.la" && ln -s "../libadd.la" "libadd.la" )
make[2]: Leaving directory `/root/program/hello_autoconf2/add'
Making all in sub
make[2]: Entering directory `/root/program/hello_autoconf2/sub'
/bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT sub.lo
-MD -MP -MF .deps/sub.Tpo -c -o sub.lo sub.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT sub.lo -MD -MP -MF
.deps/sub.Tpo -c sub.c -fPIC -DPIC -o .libs/sub.o
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT sub.lo -MD -MP -MF
.deps/sub.Tpo -c sub.c -o sub.o >/dev/null 2>&1
mv -f .deps/sub.Tpo .deps/sub.Plo
/bin/sh ../libtool --tag=CC --mode=link gcc -g -O2 -o libsub.la -rpath /usr/local/lib sub.lo
libtool: link: gcc -shared .libs/sub.o -Wl,-soname -Wl,libsub.so.0 -o .libs/libsub.so.0.0.0
libtool: link: (cd ".libs" && rm -f "libsub.so.0" && ln -s "libsub.so.0.0.0" "libsub.so.0")
libtool: link: (cd ".libs" && rm -f "libsub.so" && ln -s "libsub.so.0.0.0" "libsub.so")
libtool: link: ar cru .libs/libsub.a sub.o
libtool: link: ranlib .libs/libsub.a
libtool: link: ( cd ".libs" && rm -f "libsub.la" && ln -s "../libsub.la" "libsub.la" )
make[2]: Leaving directory `/root/program/hello_autoconf2/sub'
make[2]: Entering directory `/root/program/hello_autoconf2'
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o
main.c
mv -f .deps/main.Tpo .deps/main.Po
/bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o main main.o add/libadd.la sub/libsub.la
libtool: link: gcc -g -O2 -o .libs/main main.o add/.libs/libadd.so sub/.libs/libsub.so -Wl,-rpath
-Wl,/usr/local/lib
make[2]: Leaving directory `/root/program/hello_autoconf2'
make[1]: Leaving directory `/root/program/hello_autoconf2'

Q: main.c gcc -DHAVE_CONFIG_H -I. -g -O2 -MT main.o -MD -MP -MF
.deps /main.Tpo -c -o main.o main.c -MT,-MD,-MP,-MF

-MT,-MD,-MP,-MF makefile rule,

targets : dependency
-MF .deps/main.Tpo rule .deps/main.Tpo -MD
-M
-MT target
-MP phony target
test.o: test.c test.h
test.h: #phony target
main.Poadd.Plo
main.Po:
main.o: main.c /usr/include/stdio.h /usr/include/features.h \
/usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \
/usr/lib/gcc/i686-redhat-linux/4.5.1/include/stddef.h \
/usr/include/bits/types.h /usr/include/bits/typesizes.h \
/usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \
/usr/lib/gcc/i686-redhat-linux/4.5.1/include/stdarg.h \
/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
/usr/include/bits/stdio.h

/usr/include/stdio.h:
/usr/include/features.h:
/usr/include/sys/cdefs.h:
/usr/include/bits/wordsize.h:
/usr/include/gnu/stubs.h:
/usr/include/gnu/stubs-32.h:
/usr/lib/gcc/i686-redhat-linux/4.5.1/include/stddef.h:
/usr/include/bits/types.h:
/usr/include/bits/typesizes.h:
/usr/include/libio.h:
/usr/include/_G_config.h:
/usr/include/wchar.h:
/usr/lib/gcc/i686-redhat-linux/4.5.1/include/stdarg.h:
/usr/include/bits/stdio_lim.h:
/usr/include/bits/sys_errlist.h:
/usr/include/bits/stdio.h:
add.Plo:
add.lo: add.c

Cross-compiling
Q
configure
--build--host--target target<=host<=build<=config.
guess ./configure --build=i686-pc-linux-gnu --host=m68k-coff
--build=build-type configure compile config.guess

--host=host-type build
--target=target-type host
host_type configure

host_type arm-pc-linux-gcc

Qmake install
prefix/usr/local
bindir/usr/local/bin
includir/usr/local/include
libdir/usr/local/libs
--prefix --exec-prefix configure
./configure --prefix=/usr

GUN build system


autoconf
automake
libtool
autoheader
(whereis ,which)

GNU gcc
GNU make
GNU automake
GNU autoconf
GNU m4
perl
GNU tar
GNU zip ( gzip )
GNU Libtool ( shared library )