You are on page 1of 93

Outline

How to Use Make and Automake

Cui Tao
tcui@lsec.cc.ac.cn

The State Key Laboratory of Scientific and Engineering Computing
The Institute of Computational Mathematics and Scientific
Engineering Computing

April 21, 2005

Cui Tao tcui@lsec.cc.ac.cn make && automake

Part I: Compile ,Link and Debug
Outline Part II: Make and Makefile
Part III: Autoconf Automake

Part I: Compile ,Link and Debug
Part II: Make and Makefile
Part III: Autoconf Automake

Cui Tao tcui@lsec.cc.ac.cn make && automake

Part I: Compile ,Link and Debug
Outline Part II: Make and Makefile
Part III: Autoconf Automake

Outline of Part I

1 Compile and Link

2 ¥6

3 NÁ

Cui Tao tcui@lsec.cc.ac.cn make && automake

cc.ac.Link and Debug Outline Part II: Make and Makefile Part III: Autoconf Automake Outline of Part I 1 Compile and Link 2 ¥6 3 NÁ Cui Tao tcui@lsec. Part I: Compile .cn make && automake .

cn make && automake .Link and Debug Outline Part II: Make and Makefile Part III: Autoconf Automake Outline of Part I 1 Compile and Link 2 ¥6 3 NÁ Cui Tao tcui@lsec.ac. Part I: Compile .cc.

cc.cn make && automake . Part I: Compile .ac.Link and Debug Outline Part II: Make and Makefile Part III: Autoconf Automake Outline of Part II 4 Makefile{0 Ÿo´Makefile? Šö{0 Makefile©‡¶ Makefile¤ Make´XÛóŠ 5 XÛMakefile A Simple Example Makefile5K MakefileCþ Makefile·- Makefile–8I Cui Tao tcui@lsec.

Link and Debug Outline Part II: Make and Makefile Part III: Autoconf Automake Outline of Part II 4 Makefile{0 Ÿo´Makefile? Šö{0 Makefile©‡¶ Makefile¤ Make´XÛóŠ 5 XÛMakefile A Simple Example Makefile5K MakefileCþ Makefile·- Makefile–8I Cui Tao tcui@lsec. Part I: Compile .cc.ac.cn make && automake .

Part I: Compile ,Link and Debug
Outline Part II: Make and Makefile
Part III: Autoconf Automake

Outline of Part III

6 Autoconf ÚAutomake {0
{0
A Simple Example
¦^autoconf)¤configure
¦^automake)¤Makefile.in

Cui Tao tcui@lsec.cc.ac.cn make && automake

Compile and Link
¥6

Part I

Compile ,Link and Debug

Cui Tao tcui@lsec.cc.ac.cn make && automake

Compile and Link
¥6

Outline

1 Compile and Link

2 ¥6

3 NÁ

Cui Tao tcui@lsec.cc.ac.cn make && automake

Compile and Link ¥6 NÁ Outline 1 Compile and Link 2 ¥6 3 NÁ Cui Tao tcui@lsec.ac.cn make && automake .cc.

Compile and Link ¥6 NÁ Outline 1 Compile and Link 2 ¥6 3 NÁ Cui Tao tcui@lsec.cc.cn make && automake .ac.

cc.cn make && automake . Compile and Link ¥6 NÁ ?ÈóL§ ý?n£Pre-Processing¤ Ðm÷ \includeŠé¤¹SN ?È£Compiling¤ ®?£Assembling¤ ó£Linking¤ Cui Tao tcui@lsec.ac.

cn make && automake . Compile and Link ¥6 NÁ ?ÈóL§ ý?n£Pre-Processing¤ Ðm÷ \includeŠé¤¹SN ?È£Compiling¤ ®?£Assembling¤ ó£Linking¤ Cui Tao tcui@lsec.ac.cc.

cc.ac.cn make && automake . Compile and Link ¥6 NÁ ?ÈóL§ ý?n£Pre-Processing¤ Ðm÷ \includeŠé¤¹SN ?È£Compiling¤ ®?£Assembling¤ ó£Linking¤ Cui Tao tcui@lsec.

cc.cn make && automake . Compile and Link ¥6 NÁ ?ÈóL§ ý?n£Pre-Processing¤ Ðm÷ \includeŠé¤¹SN ?È£Compiling¤ ®?£Assembling¤ ó£Linking¤ Cui Tao tcui@lsec.ac.

cn make && automake .ac.cc.i -o hello.o -o hello Cui Tao tcui@lsec.c -o hello. Compile and Link ¥6 NÁ ?ÈóL§ gcc -E hello.o gcc hello.i gcc -c hello.

Compile and Link ¥6 NÁ 1n¼ê¥ Þ©‡£.cn make && automake .h¤Ú¥©‡£.a¤8Ü XÛé¤I‡Þ©‡Ú¥©‡ºº Cui Tao tcui@lsec.ac.so½ö.cc.

cc.cn make && automake .c -L /home/xiaowp/lib -lfoo -o foo Cui Tao tcui@lsec.ac. Compile and Link ¥6 NÁ XÛ¦^GCC -I: gcc foo.c -I /home/tcui/include -o foo -L: -l: gcc foo.

Compile and Link ¥6 NÁ XÛ¦^GCC -I: gcc foo.cn make && automake .c -L /home/xiaowp/lib -lfoo -o foo Cui Tao tcui@lsec.ac.c -I /home/tcui/include -o foo -L: -l: gcc foo.cc.

cn make && automake .cc.ac.a(—¤ Cui Tao tcui@lsec.so(—¤— first choice if without ’-static’ ·ó¥£Ï~±. Compile and Link ¥6 NÁ Ä¥Ú·¥ Äó¥£Ï~±.

ac.cc.cn make && automake . Compile and Link ¥6 NÁ GDB GDB´GNUm |„uÙ˜‡rŒUNIXe§SNÁó ä" ˜„5`§GDḂa\¤e¡o‡¡õUµ éÄ\§S§Œ±Uì\g½Â‡¦‘%¤–$1 §S" Œ4NÁ§S3\¤½N˜ä:?Ê4" §SÊ4ž§Œ±udž\§S¥¤u)¯" ÄUC\§S‰1‚¸" Cui Tao tcui@lsec.

input).c #include <stdio. return 0. Compile and Link ¥6 NÁ Example Example: crash.cc.ac.cn make && automake .h> int main(void) int input =0. printf(‘‘The integer you input is %d ’’. printf(‘‘Input an integer:’’). Cui Tao tcui@lsec. scanf(‘‘%d’’. input).

ac. Makefile{0 XÛMakefile Part II Something about Makefile Cui Tao tcui@lsec.cn make && automake .cc.

cc.cn make && automake .ac. Makefile{0 XÛMakefile Outline 4 Makefile{0 Ÿo´Makefile? Šö{0 Makefile©‡¶ Makefile¤ Make´XÛóŠ 5 XÛMakefile A Simple Example Makefile5K MakefileCþ Makefile·- Makefile–8I Cui Tao tcui@lsec.

Makefile{0 XÛMakefile Outline 4 Makefile{0 Ÿo´Makefile? Šö{0 Makefile©‡¶ Makefile¤ Make´XÛóŠ 5 XÛMakefile A Simple Example Makefile5K MakefileCþ Makefile·- Makefile–8I Cui Tao tcui@lsec.cc.cn make && automake .ac.

and rules by which an executable application is built. dependencies. Cui Tao tcui@lsec. Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ Ÿo´Makefile? A makefile details the files.cc.ac.cn make && automake .

cn make && automake .ac.stallman.org/ ùpbþ˜Ü¦Cìµ Cui Tao tcui@lsec. Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ Richard Stallman m ^‡+EÚk°§l5vk+L˜Uó]§l5vk¦^ LWindowsöŠXÚ"ù´¦̐µhttp://www.cc.

cn make && automake .com/ roland/ §e¡´¦˜ ¯.µ ܊? ¿‘oGNU make" ÚThomas Bushnell˜Ó? GNU Hurd" ?¿‘oXGNU C library" ܊?¿‘oXÜ©GNU Emacs" Cui Tao tcui@lsec. Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ Roland McGrath ‡<̐´µhttp://www.frob.cc.ac.

ac.cc. Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ Makefile©‡¶ %@µGNUmakefile. makefile. and Makefile A½µmake -f filename man make Cui Tao tcui@lsec.cn make && automake .

Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ Makefile¤ w«5K: w«5K`² §XÛ)¤˜‡½õ8I© ‡"ù´dMakefileÖö²wÑ§‡)¤©‡§© ‡6©‡§)¤·-" Û©5K: du·‚makekgÄíõU§¤±Û© 5KŒ±4·‚'o÷/{Ñ/ÖMakefile§ù´ dmake¤|±" Cþ½Â: 3Makefile¥·‚‡½Â˜XCþ§Cþ ˜„Ñ´iÎG§ù‡k:”CŠó¥÷§Makefile ‰1ž§Ù¥CþѬ*ЃAÚ^ ˜þ" ©‡«: ٝ) n‡Ü©§˜‡´3˜‡Makefile¥Ú ^.˜‡´ Šâ.˜‡Makefile§Ò”CŠó¥include˜¶. œ¹½Makefile¥kÜ©§Ò”CŠó¥ ý?È#if˜¶„kÒ´½Â˜‡õ1·-" 5º: Makefile¥k15º§ÚUNIXShell.

˜§Ù 5º´^/#0iÎ"XJ\‡3\Makefile¥¦^ Cui Tao tcui@lsec.cn make && automake .cc.ac.

Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ Ú^Ù§Makefile 3Makefile¦^include'…iŒ±rOMakefile¹?5" includeŠ{´µinclude ¡filename¿ Cui Tao tcui@lsec.ac.cc.cn make && automake .

ac. Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ MakeóŠn I make¬3c8¹eé¶i’makefile’½’Makefile’© ‡" XJ駧¬é©‡¥ƒA8I"XJmakevk ½§%@é1˜‡8I" XJ8IØ3§½´8I¤6©‡©‡?Užm‡ '8I©‡#§@o§¦Ò¬‰1 ¡¤½Â·-" Cui Tao tcui@lsec.cc.cn make && automake .

ac.cc.cn make && automake . Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ make‰1Ú½ Ö\¤kMakefile Ö\includeÙa§Makefile Щz©‡¥Cþ íÛ©5K§¿©Û¤k5K ¤k8I©‡Mï6'Xó Šâ6'X§û½= 8I‡­#)¤ ‰1)¤·- Cui Tao tcui@lsec.

Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ make‰1Ú½ Ö\¤kMakefile Ö\includeÙa§Makefile Щz©‡¥Cþ íÛ©5K§¿©Û¤k5K ¤k8I©‡Mï6'Xó Šâ6'X§û½= 8I‡­#)¤ ‰1)¤·- Cui Tao tcui@lsec.cn make && automake .cc.ac.

ac.cc.cn make && automake . Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ make‰1Ú½ Ö\¤kMakefile Ö\includeÙa§Makefile Щz©‡¥Cþ íÛ©5K§¿©Û¤k5K ¤k8I©‡Mï6'Xó Šâ6'X§û½= 8I‡­#)¤ ‰1)¤·- Cui Tao tcui@lsec.

Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ make‰1Ú½ Ö\¤kMakefile Ö\includeÙa§Makefile Щz©‡¥Cþ íÛ©5K§¿©Û¤k5K ¤k8I©‡Mï6'Xó Šâ6'X§û½= 8I‡­#)¤ ‰1)¤·- Cui Tao tcui@lsec.ac.cc.cn make && automake .

Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ make‰1Ú½ Ö\¤kMakefile Ö\includeÙa§Makefile Щz©‡¥Cþ íÛ©5K§¿©Û¤k5K ¤k8I©‡Mï6'Xó Šâ6'X§û½= 8I‡­#)¤ ‰1)¤·- Cui Tao tcui@lsec.ac.cn make && automake .cc.

cn make && automake . Ÿo´Makefile? Šö{0 Makefile{0 Makefile©‡¶ XÛMakefile Makefile¤ Make´XÛóŠ make‰1Ú½ Ö\¤kMakefile Ö\includeÙa§Makefile Щz©‡¥Cþ íÛ©5K§¿©Û¤k5K ¤k8I©‡Mï6'Xó Šâ6'X§û½= 8I‡­#)¤ ‰1)¤·- Cui Tao tcui@lsec.cc.ac.

Ÿo´Makefile?
Šö{0
Makefile{0
Makefile©‡¶
XÛMakefile
Makefile¤
Make´XÛóŠ

make‰1Ú½

Ö\¤kMakefile
Ö\includeÙa§Makefile
Щz©‡¥Cþ
íÛ©5K§¿©Û¤k5K
¤k8I©‡Mï6'Xó
Šâ6'X§û½=
8I‡­#)¤
‰1)¤·-

Cui Tao tcui@lsec.cc.ac.cn make && automake

A Simple Example
Makefile5K
Makefile{0
MakefileCþ
XÛMakefile
Makefile·-
Makefile–8I

Example I

cc = gcc
INCLUDE = -I/usr/local/mysql/include/mysql
LIBS = -L/usr/local/mysql/lib/mysql
CLIENT = -lmysqlclient

.PHONY all
all: mysqlcli

main.o: main.c passwd.h
$(cc) $(INCLUDE) -c main.c
pro1.o: pro1.c
$(cc) $(INCLUDE) -c pro1.c

Cui Tao tcui@lsec.cc.ac.cn make && automake

A Simple Example
Makefile5K
Makefile{0
MakefileCþ
XÛMakefile
Makefile·-
Makefile–8I

Example II

mysqlcli: main.o pro1.o
$(cc) -o mysqlcli main.o pro1.o $(LIBS) $(CLIENT)
clean:
rm -f main.o pro1.o
rm -f mysqlcli

Cui Tao tcui@lsec.cc.ac.cn make && automake

cn make && automake . A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I 5K¥Š{ target : prerequisites command targetÒ´˜‡8I©‡§Œ±´Object File§Œ±´‰ 1©‡"„Œ±´˜‡I\£Label¤" prerequisitesÒ´§‡)¤@‡target¤I‡©‡½´8 I" commandÒ´makeI‡‰1·-"£?¿Shell· -¤  §„Š˜J´§3Makefile¥·-§7L‡± Tab …m©" Cui Tao tcui@lsec.cc.ac.

o \ insert.c kbd.o display.cn make && automake .c insert.o files.h cc -c command.h command.o cc -o edit main.h buffer.ac.o display.o : display.o command.o command.c defs.o main.h cc -c display.c command.h cc -c kbd.o kbd.o : insert.o search.c defs.h cc -c insert.o utils.c defs.o : command.h cc -c main.c display. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Example-w«5K edit : main.c defs.o files.c defs.o : main.c Cui Tao tcui@lsec.h buffer.o kbd.o : kbd.h command.o utils.o \ insert.o search.cc.

cc.c defs.h cc -c utils.c defs.h cc -c files.c files.o kbd.o \ insert.o : files.o display.o files.cn make && automake .o : search. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Example(Y) search.o utils.c utils.o : utils.ac.h cc -c search.h command.o Cui Tao tcui@lsec.o command.c clean : rm -f edit main.h buffer.c defs.o search.h buffer.

o©‡" Cui Tao tcui@lsec.cn make && automake .o©‡ù˜5K§\Š ÒØ^Ñ5§make¬gÄíÑù«5K§¿)¤·‚I‡ .cc. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Ÿo´Û¹5K /Û¹5K0Ò´˜«.~0%ì Ø[/5$1"~X§r.ac.~§make¬Uìù«/.c©‡?Ȥ.

Cui Tao tcui@lsec..C0¤ ?ÈPascal§SÛ¹5: $(PC) t-c $(PFLAGS) ?ÈFortran/Ratfor§SÛ¹5K: /..cc0ŠC++ ©‡ M§ Ø´ /.cn make && automake .F0/$(FC) t-c $(FFLAGS) $(CPPFLAGS)0 /.f0/$(FC) t-c $(FFLAGS) $(RFLAGS)0 ý?nFortran/Ratfor§SÛ¹5K" .f0/$(FC) t-c $(FFLAGS) /.cc. .. .ac. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ~^Û¹5K ?ÈC§SÛ¹5K: $(CC)t-c $(CPPFLAGS) $(CFLAGS) ?ÈC++§SÛ¹5K: $(CXX) -c $(CPPFLAGS) $(CFLAGS)0" £ïƦ^/.

ac.cc. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Û¹5K¥^Cþ 3Û¹5K¥·-¥§ÄþÑ´¦^ ˜ ýk˜C þ"\Œ±3\makefile¥UCù CþŠ§½´3make ·-1¥D\ù Š§½´3\‚¸Cþ¥˜ù Š§ÃØ No§‡˜ ù A½Cþ§@oÙÒ¬éÛ¹5Kå Š^" Cui Tao tcui@lsec.cn make && automake .

cc.cn make && automake . A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Û¹5K¥^Cþ I AR : ar CC : cc CXX : g++ CPP : $(CC) -E FC : f77 PC : pc TEX : tex RM : rm -f CFLAGS : CŠó?Èìëê CXXFLAGS : C++Šó?Èìëê" Cui Tao tcui@lsec.ac.

.. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Û¹5K¥^Cþ II CPPFLAGS : Cý?nìëê"£C ÚFortran ?È쏬^ ¤" FFLAGS : FortranŠó?Èìëê" LDFLAGS : óìëê"£Xµ/ld0¤ ..ac. .cc.cn make && automake .. Cui Tao tcui@lsec.

ac. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ª5K ¦^ª5K5½Â˜‡Û¹5K"˜‡ª5KÒʇ˜ „5K§´35K¥§8I½ÂI‡k/%0iÎ" /%0¿g´L«˜‡½õ‡?¿iÎ" Cui Tao tcui@lsec.cc.cn make && automake .

c0L«±/.%. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ª5K0 ª5K¥§–35K8I½Â¥‡¹/%0§ÄK§Ò ´˜„5K"8I¥/%0½ÂL«é©‡¶š§ /%0L«Ý?¿š˜iÎG"~Xµ /%.ac.cc.c0(—©‡¶£©‡¶ ݖ5¤" Cui Tao tcui@lsec.cn make && automake .c0(—©‡¶£©‡¶ݖ3¤§ /s.c0KL«±/s.0mÞ§/.

c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ .ac.o : %.cn make && automake .cc.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ } Cui Tao tcui@lsec.o. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ª5K«~ %.

.cc.o print: *.]0"ù´ ÚUnixB-Shell´ƒÓ" clean: rm -f *.cn make && automake . . A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I 5K¥ÏÎ I make|±n«Ïε/*0§/?0Ú/[.c lpr -p $? touch print Cui Tao tcui@lsec.ac..

cc.cn make && automake . A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I MakefileCþ 3Makefile¥½ÂCþ§Ò”´C/C++Šó¥÷˜§¦ “L ˜‡©iG§3Makefile¥‰1žÿÙ¬gÄ /Ðm3¤¦^/" Cui Tao tcui@lsec.ac.

cn make && automake .cc. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Cþ¶ Cþ·¶iŒ±¹iÎ!êi§ey‚£Œ±´êim Þ¤§ØAT¹k/:0!/#0!/=0½´˜iӘ‚! £¤"Cþ´Œ¯a" Cui Tao tcui@lsec.ac.

cn make && automake . A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ‚¸Cþ make$1žXڂ¸CþŒ±3makem©$1ž1\ Makefile©‡¥§´XJMakefile¥®½Â ù‡Cþ§½´ ù‡Cþdmake·-1‘\§@oXÚ‚¸CþŠòC X" XJ·‚3‚¸Cþ¥˜ /CFLAGS0‚¸Cþ§@o·‚ Ҍ±3¤kMakefile¥¦^ù‡Cþ "ùéu·‚¦^Ú ˜?Èëêk'ŒÐ?"XJMakefile¥½Â CFLAGS§@oK¬¦^Makefile¥ù‡Cþ§XJvk½ ÂK¦^Xڂ¸CþŠ§˜‡5ڇ5ژ§é”/ ÛCþ0Ú/ÛÜCþ0A5" Cui Tao tcui@lsec.ac.cc.

A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I gÄzCþI $@ L«5K¥8I©‡8"3ª5K¥§XJkõ‡8I§@ o/$@0Ò´šu8I¥ª½Â8Ü" Cui Tao tcui@lsec.cc.cn make && automake .ac.

cn make && automake .o0§ /$@0Ò´/foo. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I gÄzCþII $% =8I´¼ê¥©‡¥§L«5K¥8I¤ ¶"~X§X J˜‡8I´/foo.o)0§@o§/$%0Ò´/bar.a(bar.a0"XJ8IØ´¼ê¥©‡£Unixe ´[.ac.a]§Windowse´[.lib]¤§@o§ÙŠ˜" Cui Tao tcui@lsec.cc.

ac.cn make && automake . A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I gÄzCþIII $< 68I¥1˜‡8I¶i"XJ68I´±ª£= /%0¤½Â§@o/$ <0ò´Îܪ˜X©‡ 8"5¿§Ù´˜‡˜‡Ñ5" Cui Tao tcui@lsec.cc.

ac.cn make && automake . A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I gÄzCþIV $? ¤k'8I#68I8Ü"±˜‚©…" Cui Tao tcui@lsec.cc.

ac.cc.cn make && automake . A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Cþp?$Ž I CþŠO†: $var:a=b rCþ/var0¥¤k±/a0iG/(—0/a0O†¤ /b0iG"ùp/(—0¿g´/˜‚0½´/(å Î0 rCþŠ2¤Cþ x=y y=z a := $($(x)) Cui Tao tcui@lsec.

A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I {0 z^5K¥·-ÚöŠXÚShell·-1´˜—" make¬U^SÅ^‰1·-§z^·-mÞ7L ±[Tab]…mÞ" make·-%@´//bin/sh0)º‰1" Cui Tao tcui@lsec.cc.ac.cn make && automake .

ac.cc. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I {0 z^5K¥·-ÚöŠXÚShell·-1´˜—" make¬U^SÅ^‰1·-§z^·-mÞ7L ±[Tab]…mÞ" make·-%@´//bin/sh0)º‰1" Cui Tao tcui@lsec.cn make && automake .

A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I {0 z^5K¥·-ÚöŠXÚShell·-1´˜—" make¬U^SÅ^‰1·-§z^·-mÞ7L ±[Tab]…mÞ" make·-%@´//bin/sh0)º‰1" Cui Tao tcui@lsec.ac.cn make && automake .cc.

A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ·-‰1 68I#u8Iž§Ò´5K8II‡# ž§make¬˜^˜^‰1Ù ·-"I‡5¿´§XJ \‡4þ˜^·-(JA^3e˜^·-ž§\AT¦^©Ò ©…ùü^·-" Cui Tao tcui@lsec.cn make && automake .ac.cc.

pwd Cui Tao tcui@lsec. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Example I «~˜µ exec: cd /home/hchen pwd «~µ exec: cd /home/hchen.ac.cc.cn make && automake .

0 Cui Tao tcui@lsec.cc.ac. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ·-ц z·-$1 §make¬uÿz‡·-ˆ£è§XJ·- ˆ£¤õ§@omake¬‰1e˜^·-§5K¥¤k·- ¤õˆ£ §ù‡5KҎ´¤õ¤ "XJ˜‡5K¥.cn make && automake . ‡·-ц £·-òÑèš"¤§@omakeÒ¬ªŽ‰1 c5K§ùòkŒUªŽ¤k5K‰1" XÛÑ·-ц??? 3·-c\þ/.

‡·-ц £·-òÑèš"¤§@omakeÒ¬ªŽ‰1 c5K§ùòkŒUªŽ¤k5K‰1" XÛÑ·-ц??? 3·-c\þ/.0 Cui Tao tcui@lsec.cc. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ·-ц z·-$1 §make¬uÿz‡·-ˆ£è§XJ·- ˆ£¤õ§@omake¬‰1e˜^·-§5K¥¤k·- ¤õˆ£ §ù‡5KҎ´¤õ¤ "XJ˜‡5K¥.cn make && automake .ac.

A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I ·-ц z·-$1 §make¬uÿz‡·-ˆ£è§XJ·- ˆ£¤õ§@omake¬‰1e˜^·-§5K¥¤k·- ¤õˆ£ §ù‡5KҎ´¤õ¤ "XJ˜‡5K¥.ac.0 Cui Tao tcui@lsec. ‡·-ц £·-òÑèš"¤§@omakeÒ¬ªŽ‰1 c5K§ùòkŒUªŽ¤k5K‰1" XÛÑ·-ц??? 3·-c\þ/.cn make && automake .cc.

§/–8I0¶ØUÚ©‡¶­¶§Ø.cn make && automake .o temp Cui Tao tcui@lsec.cc.ac.ÙҔ /– 8I0¿Â " ~Xµ clean: rm *. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I Ÿo´–8I? "/–8I0¿Ø´˜‡©‡§´˜‡I\§du/–8I0 Ø´©‡§¤±makeÃ{)¤§6'XÚû½§´Ä‡‰ 1"·‚kÏLw«/²ù‡/8I0âU4Ù)" .

PHONY: clean clean: rm *.PHONY0 .Ú©‡­¶ù«œ¹§·‚Œ±¦^˜‡AÏIP /. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I –8I(²  .cn make && automake .cc.ac.o temp Cui Tao tcui@lsec.

o prog3 : prog3.o cc -o prog2 prog2.cc.cn make && automake .o utils.o cc -o prog3 prog3.o sort.o cc -o prog1 prog1.o sort.o utils. A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I –8I6©‡ I –8I˜„vk6©‡"´§·‚Œ±–8I½¤ 6©‡"~Xµ all : prog1 prog2 prog3 .ac.o prog2 : prog2.o Cui Tao tcui@lsec.o utils.o utils.PHONY : all prog1 : prog1.

A Simple Example Makefile5K Makefile{0 MakefileCþ XÛMakefile Makefile·- Makefile–8I –8I6©‡ II Makefile¥1˜‡8I¬ŠÙ%@8I"·‚(² ˜‡ /all0–8I§Ù6uÙ§n‡8I"du–8IA5 ´§o´‰1§¤±Ù6@n‡8IÒo´ØX/all0 ù‡8I#"¤±§Ù§n‡8I5Ko´¬ûÆ"Òˆ  ·‚˜í)¤õ‡8I8" Cui Tao tcui@lsec.ac.cn make && automake .cc.

Autoconf ÚAutomake {0 Part III Autoconf Automake Cui Tao tcui@lsec.cn make && automake .ac.cc.

ac.in Cui Tao tcui@lsec.cn make && automake .cc. Autoconf ÚAutomake {0 Outline 6 Autoconf ÚAutomake {0 {0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.

{0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.in {0 Autoconf´˜‡^u)¤Œ±gÄ/˜^‡ “蝱·Aõ «UnixaXÚshell.

óä"Autoconf)¤˜.

Ï~ ¡configure"Automake´˜±^ugÄ)¤Makefile.cn make && automake .ac.cc.in©‡ óä" Cui Tao tcui@lsec.

cc. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.cn make && automake .ac.in 6§ Cui Tao tcui@lsec.

c autoscan : )¤configure.1. tcui@lsec.in # -*.cc.0) AC_CONFIG_SRCDIR([hello.Autoconf -*- # Process this file with autoconf to produce a # configure script. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.scan configure.cc. AC_PREREQ(2. 1.c]) # Checks for programs. Cui Tao tcui@lsec.ac.cn make && automake .scan >>> configure.59) AC_INIT(HH.0.cn) AM_INIT_AUTOMAKE(hello.in {ü~f I Hello.ac.

cc.cn make && automake . # Checks for library functions. and compiler # characteristics. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile. # Checks for typedefs.in {ü~f II AC_PROG_CC # Checks for libraries. AC_OUTPUT(Makefile) aclocal : )¤aclocal. # Checks for header files.m4 autoconf: )¤configure Cui Tao tcui@lsec.ac. structures.

ac. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.am AUTOMAKE_OPTIONS=foreign bin_PROGRAMS=hello hello_SOURCES=hello.cn make && automake .in {ü~f III MïMakefile.c automake :)¤Makefile.cc.in Cui Tao tcui@lsec.

in Mïconfigure.in¥~^÷k: AC INIT AM INIT AUTOMAKE(PACKAGE.scan".cc.ac.cn make && automake . {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.in I ¦^autoscan·-)¤configure. Ãó?U ¤configure.in"configure.VERSION) AC CONFIG HEADER (header-to-create): ^‡¦^˜‡ ˜Þ©‡ AC OUTPUT COMMANDS (extra-cmds [. init-cmds]) AC PREFIX DEFAULT(prefix) AC PREFIX PROGRAM(program) AC PREREQ(version) : +n‡Ò§(v # Autoconf‡ Cui Tao tcui@lsec.

action-if-not-found]]) z‡3files¥‰Ñ©‡$1AC CHECK FILE" Cui Tao tcui@lsec.ac.cn make && automake . action-if-found [. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.in II AC PROG AWK : U^Sémawk!gawk!nawkÚawk§ ¿…rÑÑCþAWK Š˜¤1˜‡é§S¶"Ä kÏémawk´Ïâ`§´¯¢y" AC PROG CC : (½C?Èì"XJ3‚¸¥vk ½CC§Òégcc§XJvké§Ò¦^cc"rÑÑC þCC˜é?Èì¶i" AC PROG CXX AC PROG F77 AC CHECK FILES(files[.in Mïconfigure.cc.

ac.cc.other-libraries]]]) 6ucŠó£ë„éŠóÀJ¤§ÁãÏLu˜ ‡ÿÁ§S´ÄŒ±Ú¥library?1ë±¼C!C++½ öFortran 77¼êfunction§l (@¼êfunction ´Œ±¦ ^"library´¥Ä¶i¶~X§ u’-lmp’§Ò r’mp’Šëêlibrary" action-if-found´˜‡3†¥¤õ/?1 ëžÿ$1 shell·-L¶action-if-not-found´˜‡3†¥ë” }žÿ$1shell·-L"XJvk‰ Ñaction-if-found§"ŽĊҴr’-llibrary’V\ LIBS¥§¿…½Â‘HAVE LIBlibrary’£¿ ܦ^Œi 1¤" Cui Tao tcui@lsec. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.in III AC CHECK LIB(library.cn make && automake .in Mïconfigure.function[.action-if-found[.action-if-not- found[.

.cn make && automake . .ac.in Mïconfigure.in IV ... . . {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.. .cc.... AC OUTPUT(filename) Cui Tao tcui@lsec.

cc.m4 autoconf: )configure Cui Tao tcui@lsec.in Mïconfigure I aclocal : )aclocal. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.ac.cn make && automake .

ac.cc. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.in I )¤Makefile.cn make && automake .am automake –add-missing –add-missing : wŠautomake·‚\\u1˜‡^‡¤ 7aquinstallóä" Cui Tao tcui@lsec.in ¦^automake)¤Makefile.

in Makefile. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.am I AUTOMAKE OPTIONS ½automake À‘"Automake ̇´ÏmuGNU ^ N< ‘o^N@‡§¤±3‰1automake ž§¬u 8¹e´Ä3IOGNU ^N@‡¥A䩇.

Y§ ~X’NEWS’!’AUTHOR’!’ChangeLog’ ©‡.

" ¤foreign ž§automake ¬U^˜„^N@‡IO5u " bin PROGRAMS ½Â·‚¤‡)‰1.

.

¶"XJ‡)õ‡‰1.

§ z‡.

¶^˜xi…m" Cui Tao tcui@lsec.cc.ac.cn make && automake .

{0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.in Makefile.am II hello SOURCES ½Â’hello’ ù‡‰1.

¤I‡©.

"XJ’hello’ ù‡§ ª´dõ‡©.

¤)§7Lr§¤^©.

h’ n‡.ÑÑ 5§±˜xi…m"b’hello’ ù‡§ªI ‡’hello.c’!’hello.c’!’main.

c hello.Y{§K½ Âhello SOURCES= hello.h XJ·‚½Âõ‡ ‰1.c main.

§Kéz‡‰1.

ac.ч½Âƒé filename SOURCES" Cui Tao tcui@lsec.cc.cn make && automake .

in ¦^Makefile I make all )·‚½8I§=d‰~¥‰1. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.

"‹make  Œ±§dž¬m©?È©è§.àë(§¿…)‰1 .

" make clean ˜Øƒc¤?ȉ1.

98.

*.(object file.o)" make distclean Ø ˜Ø‰1.

Ú8.

§rconfigure ¤) Makefile˜ØK" Cui Tao tcui@lsec.cc.ac.cn make && automake .

in ¦^Makefile II make install ò§ªSC–XÚ¥"XJ©è?ÈÃا…‰1(J (§BŒ±r§ªSC–XÚý‰1. {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.

˜´»"XJ ·‚^bin PROGRAMS ã8{§§ª¬SC –/usr/local/bin ù‡8¹" make dist ò§ªÚƒ'.

YC¤˜‡Ø .

±øÑ Â(distribution) "‰138¹e¬)˜‡ ±PACKAGE-VERSION.gz ¶¡.tar.

in .Y"PACKAGE ÚVERSION ùü‡C괊âconfigure.

VERSION) ½Â" Cui Tao tcui@lsec.cn make && automake .ac.cc. ¥AM INIT AUTOMAKE(PACKAGE.

in ¦^Makefile III make distcheck Úmake dist aq§´\\uCàØ . {0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.

´Ä ~"ù‡8IØ r§ªÚƒ'.

gz .YC¤tar.

§„ ¬gÄrù‡Ø .

)m§‰1configure§¿…?1make all Ċ§(@?ÈÃØ৬w«ù‡tar.gz .

cc.cn make && automake .®²O ЌøÑ "ù‡uš~k^§uL'@‡§Ä þŒ±‰?ۘ‡äGNU uЂ¸<­#?È" Cui Tao tcui@lsec.ac.

{0 A Simple Example Autoconf ÚAutomake {0 ¦^autoconf)¤configure ¦^automake)¤Makefile.in — Thanks! ƒ'©.

cc.cn/ v tcui e1 Cui Tao tcui@lsec.ac.Œ3http : //lsec.cc.ac.cn make && automake .