Make-howto

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Make-howto as PDF for free.

More details

  • Words: 2,624
  • Pages: 93
Outline

How to Use Make and Automake Cui Tao [email protected] The State Key Laboratory of Scientific and Engineering Computing The Institute of Computational Mathematics and Scientific Engineering Computing

April 21, 2005

Cui Tao [email protected]

make && automake

Outline

Part I: Compile ,Link and Debug 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 [email protected]

make && automake

Outline

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

Outline of Part I

1

Compile and Link

2

¥6

3



Cui Tao [email protected]

make && automake

Outline

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

Outline of Part I

1

Compile and Link

2

¥6

3



Cui Tao [email protected]

make && automake

Outline

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

Outline of Part I

1

Compile and Link

2

¥6

3



Cui Tao [email protected]

make && automake

Outline

Part I: Compile ,Link and Debug 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 [email protected]

make && automake

Outline

Part I: Compile ,Link and Debug 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 [email protected]

make && automake

Outline

Part I: Compile ,Link and Debug 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 [email protected]

make && automake

Compile and Link ¥6 NÁ

Part I Compile ,Link and Debug

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

Outline

1

Compile and Link

2

¥6

3



Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

Outline

1

Compile and Link

2

¥6

3



Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

Outline

1

Compile and Link

2

¥6

3



Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

?ÈóL§

ý?n£Pre-Processing¤ Ðm÷ \includeŠé¤¹SN

?È£Compiling¤ ®?£Assembling¤ ó£Linking¤

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

?ÈóL§

ý?n£Pre-Processing¤ Ðm÷ \includeŠé¤¹SN

?È£Compiling¤ ®?£Assembling¤ ó£Linking¤

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

?ÈóL§

ý?n£Pre-Processing¤ Ðm÷ \includeŠé¤¹SN

?È£Compiling¤ ®?£Assembling¤ ó£Linking¤

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

?ÈóL§

ý?n£Pre-Processing¤ Ðm÷ \includeŠé¤¹SN

?È£Compiling¤ ®?£Assembling¤ ó£Linking¤

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

?ÈóL§

gcc -E hello.c -o hello.i gcc -c hello.i -o hello.o gcc hello.o -o hello

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

1n¼ê¥

Þ©‡£.h¤Ú¥©‡£.so½ö.a¤8Ü XÛé¤I‡Þ©‡Ú¥©‡ºº

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

XÛ¦^GCC

-I: gcc foo.c -I /home/tcui/include -o foo -L: -l: gcc foo.c -L /home/xiaowp/lib -lfoo -o foo

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

XÛ¦^GCC

-I: gcc foo.c -I /home/tcui/include -o foo -L: -l: gcc foo.c -L /home/xiaowp/lib -lfoo -o foo

Cui Tao [email protected]

make && automake

Compile and Link ¥6 NÁ

Ä¥Ú·¥

Äó¥£Ï~±.so(—¤— first choice if without ’-static’ ·ó¥£Ï~±.a(—¤

Cui Tao [email protected]

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 [email protected]

make && automake

Compile and Link ¥6 NÁ

Example

Example: crash.c #include <stdio.h> int main(void) int input =0; printf(‘‘Input an integer:’’); scanf(‘‘%d’’, input); printf(‘‘The integer you input is %d ’’, input); return 0;

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

Part II Something about Makefile

Cui Tao [email protected]

make && automake

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 [email protected]

make && automake

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 [email protected]

make && automake

Makefile{0 XÛMakefile

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

Ÿo´Makefile?

A makefile details the files, dependencies, and rules by which an executable application is built.

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

Richard Stallman m ^‡+EÚk°§l5vk+L˜Uó]§l5vk¦^ LWindowsöŠXÚ"ù´¦̐µhttp://www.stallman.org/

ùpbþ˜Ü¦Cìµ

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

Roland McGrath

‡<̐´µhttp://www.frob.com/ roland/ §e¡´¦˜

¯,µ ܊? ¿‘oGNU make" ÚThomas Bushnell˜Ó? GNU Hurd" ?¿‘oXGNU C library" ܊?¿‘oXÜ©GNU Emacs"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

Makefile©‡¶

%@µGNUmakefile, makefile, and Makefile A½µmake -f filename man make

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

Ÿo´Makefile? Šö{0 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 [email protected] make && automake

Makefile{0 XÛMakefile

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

Ú^Ù§Makefile

3Makefile¦^include'…iŒ±rOMakefile¹?5" includeŠ{´µinclude ¡filename¿

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

Ÿo´Makefile? Šö{0 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 [email protected]

make && automake

Makefile{0 XÛMakefile

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

make‰1Ú½

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

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

make‰1Ú½

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

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

make‰1Ú½

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

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

make‰1Ú½

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

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

make‰1Ú½

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

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

make‰1Ú½

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

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

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

make‰1Ú½

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

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ 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 [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ 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 [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ 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 [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

Example-w«5K edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o main.o : main.c defs.h cc -c main.c kbd.o : kbd.c defs.h command.h cc -c kbd.c command.o : command.c defs.h command.h cc -c command.c display.o : display.c defs.h buffer.h cc -c display.c insert.o : insert.c defs.h buffer.h cc -c insert.c Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

Example(Y)

search.o : search.c defs.h buffer.h cc -c search.c files.o : files.c defs.h buffer.h command.h cc -c files.c utils.o : utils.c defs.h cc -c utils.c clean : rm -f edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

Ÿo´Û¹5K

/Û¹5K0Ò´˜«.~§make¬Uìù«/.~0%ì Ø[/5$1"~X§r.c©‡?Ȥ.o©‡ù˜5K§\Š ÒØ^Ñ5§make¬gÄíÑù«5K§¿)¤·‚I‡ .o©‡"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

~^Û¹5K ?ÈC§SÛ¹5K: $(CC)t-c $(CPPFLAGS) $(CFLAGS) ?ÈC++§SÛ¹5K: $(CXX) -c $(CPPFLAGS) $(CFLAGS)0" £ïƦ^/.cc0ŠC++ ©‡ M§ Ø´ /.C0¤ ?ÈPascal§SÛ¹5: $(PC) t-c $(PFLAGS) ?ÈFortran/Ratfor§SÛ¹5K: /.f0/$(FC) t-c $(FFLAGS) /.F0/$(FC) t-c $(FFLAGS) $(CPPFLAGS)0 /.f0/$(FC) t-c $(FFLAGS) $(RFLAGS)0 ý?nFortran/Ratfor§SÛ¹5K" .. .. .. Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ 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 [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ 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 [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

Û¹5K¥^Cþ II

CPPFLAGS : Cý?nìëê"£C ÚFortran ?È쏬^ ¤" FFLAGS : FortranŠó?Èìëê" LDFLAGS : óìëê"£Xµ/ld0¤ .. .. ..

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

ª5K

¦^ª5K5½Â˜‡Û¹5K"˜‡ª5KÒʇ˜ „5K§´35K¥§8I½ÂI‡k/%0iÎ" /%0¿g´L«˜‡½õ‡?¿iÎ"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

ª5K0

ª5K¥§–35K8I½Â¥‡¹/%0§ÄK§Ò ´˜„5K"8I¥/%0½ÂL«é©‡¶š§ /%0L«Ý?¿š˜iÎG"~Xµ /%.c0L«±/.c0(—©‡¶£©‡¶ݖ3¤§

/s.%.c0KL«±/s.0mÞ§/.c0(—©‡¶£©‡¶ ݖ5¤"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

ª5K«~

%.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

.o.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ }

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

5K¥ÏÎ I

make|±n«Ïε/*0§/?0Ú/[.. ..]0"ù´ ÚUnixB-Shell´ƒÓ" clean: rm -f *.o print: *.c lpr -p $? touch print

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

MakefileCþ

3Makefile¥½ÂCþ§Ò”´C/C++Šó¥÷˜§¦ “L ˜‡©iG§3Makefile¥‰1žÿÙ¬gÄ /Ðm3¤¦^/"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

Cþ¶

Cþ·¶iŒ±¹iÎ!êi§ey‚£Œ±´êim Þ¤§ØAT¹k/:0!/#0!/=0½´˜iӘ‚! £¤"Cþ´Œ¯a"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ 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 [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

gÄzCþI

$@ L«5K¥8I©‡8"3ª5K¥§XJkõ‡8I§@ o/$@0Ò´šu8I¥ª½Â8Ü"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

gÄzCþII

$% =8I´¼ê¥©‡¥§L«5K¥8I¤ ¶"~X§X J˜‡8I´/foo.a(bar.o)0§@o§/$%0Ò´/bar.o0§ /$@0Ò´/foo.a0"XJ8IØ´¼ê¥©‡£Unixe ´[.a]§Windowse´[.lib]¤§@o§ÙŠ˜"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

gÄzCþIII

$< 68I¥1˜‡8I¶i"XJ68I´±ª£= /%0¤½Â§@o/$ <0ò´Îܪ˜X©‡ 8"5¿§Ù´˜‡˜‡Ñ5"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

gÄzCþIV

$? ¤k'8I#68I8Ü"±˜‚©…"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ 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 [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

{0

z^5K¥·-ÚöŠXÚShell·-1´˜—" make¬U^SÅ^‰1·-§z^·-mÞ7L ±[Tab]…mÞ" make·-%@´//bin/sh0)º‰1"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

{0

z^5K¥·-ÚöŠXÚShell·-1´˜—" make¬U^SÅ^‰1·-§z^·-mÞ7L ±[Tab]…mÞ" make·-%@´//bin/sh0)º‰1"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

{0

z^5K¥·-ÚöŠXÚShell·-1´˜—" make¬U^SÅ^‰1·-§z^·-mÞ7L ±[Tab]…mÞ" make·-%@´//bin/sh0)º‰1"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

·-‰1

68I#u8Iž§Ò´5K8II‡# ž§make¬˜^˜^‰1Ù ·-"I‡5¿´§XJ \‡4þ˜^·-(JA^3e˜^·-ž§\AT¦^©Ò ©…ùü^·-"

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

Example I

«~˜µ exec: cd /home/hchen pwd «~µ exec: cd /home/hchen; pwd

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

·-ц

z·-$1 §make¬uÿz‡·-ˆ£è§XJ·ˆ£¤õ§@omake¬‰1e˜^·-§5K¥¤k·¤õˆ£ §ù‡5KҎ´¤õ¤ "XJ˜‡5K¥, ‡·-ц £·-òÑèš"¤§@omakeÒ¬ªŽ‰1 c5K§ùòkŒUªŽ¤k5K‰1" XÛÑ·-ц??? 3·-c\þ/- 0

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

·-ц

z·-$1 §make¬uÿz‡·-ˆ£è§XJ·ˆ£¤õ§@omake¬‰1e˜^·-§5K¥¤k·¤õˆ£ §ù‡5KҎ´¤õ¤ "XJ˜‡5K¥, ‡·-ц £·-òÑèš"¤§@omakeÒ¬ªŽ‰1 c5K§ùòkŒUªŽ¤k5K‰1" XÛÑ·-ц??? 3·-c\þ/- 0

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

·-ц

z·-$1 §make¬uÿz‡·-ˆ£è§XJ·ˆ£¤õ§@omake¬‰1e˜^·-§5K¥¤k·¤õˆ£ §ù‡5KҎ´¤õ¤ "XJ˜‡5K¥, ‡·-ц £·-òÑèš"¤§@omakeÒ¬ªŽ‰1 c5K§ùòkŒUªŽ¤k5K‰1" XÛÑ·-ц??? 3·-c\þ/- 0

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

Ÿo´–8I?

"/–8I0¿Ø´˜‡©‡§´˜‡I\§du/–8I0 Ø´©‡§¤±makeÃ{)¤§6'XÚû½§´Ä‡‰ 1"·‚kÏLw«/²ù‡/8I0âU4Ù)" ,§/–8I0¶ØUÚ©‡¶­¶§Ø,ÙҔ /– 8I0¿Â " ~Xµ clean: rm *.o temp

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

–8I(²

 ;Ú©‡­¶ù«œ¹§·‚Œ±¦^˜‡AÏIP /.PHONY0 .PHONY: clean clean: rm *.o temp

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ Makefile·Makefile–8I

–8I6©‡ I –8I˜„vk6©‡"´§·‚Œ±–8I½¤ 6©‡"~Xµ all : prog1 prog2 prog3 .PHONY : all prog1 cc -o prog2 cc -o prog3 cc -o

: prog1.o utils.o prog1 prog1.o utils.o : prog2.o prog2 prog2.o : prog3.o sort.o utils.o prog3 prog3.o sort.o utils.o

Cui Tao [email protected]

make && automake

Makefile{0 XÛMakefile

A Simple Example Makefile5K MakefileCþ 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 [email protected]

make && automake

Autoconf ÚAutomake {0

Part III Autoconf Automake

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

Outline

6

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

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

{0

Autoconf´˜‡^u)¤Œ±gÄ/˜^‡ “蝱·Aõ «UnixaXÚshell óä"Autoconf)¤˜ Ï~ ¡configure"Automake´˜±^ugÄ)¤Makefile.in©‡ óä"

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

Cui Tao [email protected]

make && automake



Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

{ü~f I Hello.c autoscan : )¤configure.scan configure.scan >>> configure.in # -*- Autoconf -*# Process this file with autoconf to produce a # configure script. AC_PREREQ(2.59) AC_INIT(HH, 1.0, [email protected]) AM_INIT_AUTOMAKE(hello,1.0) AC_CONFIG_SRCDIR([hello.c]) # Checks for programs. Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

{ü~f II AC_PROG_CC # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler # characteristics. # Checks for library functions. AC_OUTPUT(Makefile) aclocal : )¤aclocal.m4 autoconf: )¤configure Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

{ü~f III

MïMakefile.am AUTOMAKE_OPTIONS=foreign bin_PROGRAMS=hello hello_SOURCES=hello.c automake :)¤Makefile.in

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

Mïconfigure.in I ¦^autoscan·-)¤configure.scan", Ãó?U ¤configure.in"configure.in¥~^÷k: AC INIT AM INIT AUTOMAKE(PACKAGE,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 [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

Mïconfigure.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[, action-if-found [, action-if-not-found]]) z‡3files¥‰Ñ©‡$1AC CHECK FILE"

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

Mïconfigure.in III AC CHECK LIB(library,function[,action-if-found[,action-if-notfound[,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 [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

Mïconfigure.in IV

.. .. .. .. .. .. AC OUTPUT(filename)

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

Mïconfigure I

aclocal : )aclocal.m4 autoconf: )configure

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

¦^automake)¤Makefile.in I

)¤Makefile.am automake –add-missing –add-missing : wŠautomake·‚\\u1˜‡^‡¤ 7aquinstallóä"

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

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 [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

Makefile.am II

hello SOURCES ½Â’hello’ ù‡‰1 ¤I‡© "XJ’hello’ ù‡§ ª´dõ‡© ¤)§7Lr§¤^© ÑÑ 5§±˜xi…m"b’hello’ ù‡§ªI ‡’hello.c’!’main.c’!’hello.h’ n‡ Y{§K½ Âhello SOURCES= hello.c main.c hello.h XJ·‚½Âõ‡ ‰1 §Kéz‡‰1 ч½Âƒé filename SOURCES"

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

¦^Makefile I

make all )·‚½8I§=d‰~¥‰1 "‹make  Œ±§dž¬m©?È©è§,àë(§¿…)‰1 " make clean ˜Øƒc¤?ȉ1 98 (object file, *.o)" make distclean Ø ˜Ø‰1 Ú8 §rconfigure ¤) Makefile˜ØK"

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

¦^Makefile II make install ò§ªSC–XÚ¥"XJ©è?ÈÃا…‰1(J (§BŒ±r§ªSC–XÚý‰1 ˜´»"XJ ·‚^bin PROGRAMS ã8{§§ª¬SC –/usr/local/bin ù‡8¹" make dist ò§ªÚƒ' YC¤˜‡Ø  ±øÑ Â(distribution) "‰138¹e¬)˜‡ ±PACKAGE-VERSION.tar.gz ¶¡ Y"PACKAGE ÚVERSION ùü‡C괊âconfigure.in ¥AM INIT AUTOMAKE(PACKAGE, VERSION) ½Â"

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

¦^Makefile III

make distcheck Úmake dist aq§´\\uCàØ  ´Ä ~"ù‡8IØ r§ªÚƒ' YC¤tar.gz §„ ¬gÄrù‡Ø  )m§‰1configure§¿…?1make all Ċ§(@?ÈÃØ৬w«ù‡tar.gz ®²O ЌøÑ "ù‡uš~k^§uL'@‡§Ä þŒ±‰?ۘ‡äGNU uЂ¸<­#?È"

Cui Tao [email protected]

make && automake

Autoconf ÚAutomake {0

{0 A Simple Example ¦^autoconf)¤configure ¦^automake)¤Makefile.in

—

Thanks! ƒ'© Œ3http : //lsec.cc.ac.cn/ v tcui e1

Cui Tao [email protected]

make && automake