Ê×ÏÈ£¬ÎҺܲˡ£
ÍøÉÏÕÒÁËһƪ¹ØÓÚautomakeÉú³ÉmakefileµÄÎÄÕ¡£
Èý¡¢´ÓhelloworldÈëÊÖ
¡¡¡¡ÎÒÃÇ´Ó´ó¼Ò×ʹÓõÄÀý×Ó³ÌÐòhelloworld¿ªÊ¼¡£
¡¡¡¡ÏÂÃæµÄ¹ý³ÌÈç¹û¼òµ¥µØ˵À´¾ÍÊÇ£º
¡¡¡¡Ð½¨Èý¸öÎļþ£º
¡¡¡¡¡¡helloworld.c
¡¡¡¡¡¡configure.in
¡¡¡¡¡¡Makefile.am
¡¡¡¡È»ºóÖ´ÐУº
aclocal; autoconf; automake --add-missing; ./configure; make; ./helloworld
¡¡¡¡¾Í¿ÉÒÔ¿´µ½Makefile±»²úÉú³öÀ´£¬¶øÇÒ¿ÉÒÔ½«helloworld.c±àÒëͨ¹ý¡£
¡¡¡¡ºÜ¼òµ¥°É£¬¼¸ÌõÃüÁî¾Í¿ÉÒÔ×ö³öÒ»¸ö·ûºÏ¹ßÀýµÄMakefile£¬¸Ð¾õÈçºÎѽ¡£
¡¡¡¡ÏÖÔÚ¿ªÊ¼½éÉÜÏêϸµÄ¹ý³Ì£º
¡¡¡¡1¡¢½¨Ä¿Â¼
¡¡¡¡ÔÚÄãµÄ¹¤×÷Ŀ¼Ï½¨Ò»¸öhelloworldĿ¼£¬ÎÒÃÇÓÃËüÀ´´æ·Åhelloworld³ÌÐò¼°Ïà¹ØÎļþ£¬ÈçÔÚ/home/my/buildÏ£º
$ mkdir helloWord
$ cd helloworld
¡¡¡¡2¡¢ helloworld.c
¡¡¡¡È»ºóÓÃÄã×Ô¼º×îϲ»¶µÄ±à¼Æ÷дһ¸öhellowrold.cÎļþ£¬ÈçÃüÁvi helloworld.c¡£Ê¹ÓÃÏÂÃæµÄ´úÂë×÷Ϊhelloworld.cµÄÄÚÈÝ¡£
int main(int argc, char** argv)
{
PRintf("Hello, Linux World!\n");
return 0;
}
¡¡¡¡Íê³Éºó±£´æÍ˳ö¡£
¡¡¡¡ÏÖÔÚÔÚhelloworldĿ¼Ï¾ÍÓ¦¸ÃÓÐÒ»¸öÄã×Ô¼ºÐ´µÄhelloworld.cÁË¡£
¡¡¡¡3¡¢Éú³Éconfigure
¡¡¡¡ÎÒÃÇʹÓÃautoscanÃüÁîÀ´°ïÖúÎÒÃǸù¾ÝĿ¼ÏµÄÔ´´úÂëÉú³ÉÒ»¸öconfigure.inµÄÄ£°åÎļþ¡£
¡¡¡¡ÃüÁ
$ autoscan
$ ls
configure.scan helloworld.c
¡¡¡¡Ö´ÐкóÔÚhellowroldĿ¼Ï»áÉú³ÉÒ»¸öÎļþ£ºconfigure.scan£¬ÎÒÃÇ¿ÉÒÔÄÃËü×÷Ϊconfigure.inµÄÀ¶±¾¡£
¡¡¡¡ÏÖÔÚ½«configure.scan¸ÄÃûΪconfigure.in£¬²¢ÇÒ±à¼Ëü£¬°´ÏÂÃæµÄÄÚÈÝÐ޸ģ¬È¥µôÎ޹صÄÓï¾ä£º
============================configure.inÄÚÈÝ¿ªÊ¼=========================================
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_INIT(helloworld.c)
AM_INIT_AUTOMAKE(helloworld, 1.0)
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT(Makefile)
============================configure.in ÄÚÈݽáÊø=========================================
¡¡¡¡È»ºóÖ´ÐÐÃüÁîaclocalºÍautoconf£¬·Ö±ð»á²úÉúaclocal.m4¼°configureÁ½¸öÎļþ£º
$ aclocal
$ls
aclocal.m4 configure.in helloworld.c
$ autoconf
$ ls
aclocal.m4 autom4te.cache configure configure.in helloworld.c
¡¡¡¡´ó¼Ò¿ÉÒÔ¿´µ½configure.inÄÚÈÝÊÇһЩºê¶¨Ò壬ÕâЩºê¾autoconf´¦Àíºó»á±ä³É¼ì²éϵͳÌØÐÔ¡¢»·¾³±äÁ¿¡¢Èí¼þ±ØÐëµÄ²ÎÊýµÄshell½Å±¾¡£
¡¡¡¡autoconf ÊÇÓÃÀ´Éú³É×Ô¶¯ÅäÖÃÈí¼þÔ´´úÂë½Å±¾£¨configure£©µÄ¹¤¾ß¡£configure½Å±¾ÄܶÀÁ¢ÓÚautoconfÔËÐУ¬ÇÒÔÚÔËÐеĹý³ÌÖУ¬²»ÐèÒªÓû§µÄ¸ÉÔ¤¡£
¡¡¡¡ÒªÉú³ÉconfigureÎļþ£¬Äã±ØÐë¸æËßautoconfÈçºÎÕÒµ½ÄãËùÓõĺꡣ·½Ê½ÊÇʹÓÃaclocal³ÌÐòÀ´Éú³ÉÄãµÄ aclocal.m4¡£
¡¡¡¡aclocal¸ù¾Ýconfigure.inÎļþµÄÄÚÈÝ£¬×Ô¶¯Éú³Éaclocal.m4Îļþ¡£aclocalÊÇÒ»¸öperl ½Å±¾³ÌÐò£¬ËüµÄ¶¨ÒåÊÇ£º¡°aclocal - create aclocal.m4 by scanning configure.ac¡±¡£
¡¡¡¡autoconf´Óconfigure.inÕâ¸öÁоٱàÒëÈí¼þʱËùÐèÒª¸÷ÖÖ²ÎÊýµÄÄ£°åÎļþÖд´½¨configure¡£
¡¡¡¡autoconfÐèÒªGNU m4ºê´¦ÀíÆ÷À´´¦Àíaclocal.m4£¬Éú³Éconfigure½Å±¾¡£
¡¡¡¡m4ÊÇÒ»¸öºê´¦ÀíÆ÷¡£½«ÊäÈ뿽±´µ½Êä³ö£¬Í¬Ê±½«ºêÕ¹¿ª¡£ºê¿ÉÒÔÊÇÄÚǶµÄ£¬Ò²¿ÉÒÔÊÇÓû§¶¨ÒåµÄ¡£³ýÁË¿ÉÒÔÕ¹¿ªºê£¬m4»¹ÓÐһЩÄÚ½¨µÄº¯Êý£¬ÓÃÀ´ÒýÓÃÎļþ£¬Ö´ÐÐÃüÁÕûÊýÔËË㣬Îı¾²Ù×÷£¬Ñ»·µÈ¡£m4¼È¿ÉÒÔ×÷Ϊ±àÒëÆ÷µÄÇ°¶Ë£¬Ò²¿ÉÒÔµ¥¶À×÷Ϊһ¸öºê´¦ÀíÆ÷¡£
4¡¢Ð½¨Makefile.am
¡¡¡¡Ð½¨Makefile.amÎļþ£¬ÃüÁ
$ vi Makefile.am
¡¡¡¡ÄÚÈÝÈçÏÂ:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=helloworld.c
¡¡¡¡automake»á¸ù¾ÝÄãдµÄMakefile.amÀ´×Ô¶¯Éú³ÉMakefile.in¡£
¡¡¡¡Makefile.amÖж¨ÒåµÄºêºÍÄ¿±ê,»áÖ¸µ¼automakeÉú³ÉÖ¸¶¨µÄ´úÂë¡£ÀýÈ磬ºêbin_PROGRAMS½«µ¼Ö±àÒëºÍÁ¬½ÓµÄÄ¿±ê±»Éú³É¡£
¡¡¡¡5¡¢ÔËÐÐautomake
¡¡¡¡ÃüÁ
$ automake --add-missing
configure.in: installing `./install-sh'
configure.in: installing `./mkinstalldirs'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
¡¡¡¡automake»á¸ù¾ÝMakefile.amÎļþ²úÉúһЩÎļþ£¬°üº¬×îÖØÒªµÄMakefile.in¡£
¡¡¡¡6¡¢Ö´ÐÐconfigureÉú³ÉMakefile
$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output... 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 ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
$ ls -l Makefile
-rw-rw-r-- 1 yutao yutao 15035 Oct 15 10:40 Makefile
Äã¿ÉÒÔ¿´µ½£¬´ËʱMakefileÒѾ²úÉú³öÀ´ÁË¡£
7¡¢Ê¹ÓÃMakefile±àÒë´úÂë
$ make
if gcc -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -
DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -DPACKAGE="helloworld" -DVERSION="1.0"
-I. -I. -g -O2 -MT helloworld.o -MD -MP -MF ".deps/helloworld.Tpo" \
-c -o helloworld.o `test -f 'helloworld.c' || echo './'`helloworld.c; \
then mv -f ".deps/helloworld.Tpo" ".deps/helloworld.Po"; \
else rm -f ".deps/helloworld.Tpo"; exit 1; \
fi
gcc -g -O2 -o helloworld helloworld.o
¡¡¡¡ÔËÐÐhelloworld
$ ./helloworld
Hello, Linux World!
¡¡¡¡ÕâÑùhelloworld¾Í±àÒë³öÀ´ÁË£¬ÄãÈç¹û°´ÉÏÃæµÄ²½ÖèÀ´×öµÄ»°£¬Ó¦¸ÃÒ²»áºÜÈÝÒ׵رàÒë³öÕýÈ·µÄhelloworldÎļþ¡£Ä㻹¿ÉÒÔÊÔ×ÅʹÓÃһЩÆäËûµÄmakeÃüÁÈçmake clean£¬make install£¬make dist£¬¿´¿´ËüÃÇ»á¸øÄãʲôÑùµÄЧ¹û¡£¸Ð¾õÈçºÎ£¿×Ô¼ºÒ²ÄÜд³öÕâôרҵµÄMakefile£¬ÀÏ°åÒ»¶¨»á¶ÔÄã¹ÎÄ¿Ïà¿´¡£
ÎÒÔÚÔËÐÐ ./configureµÄʱºò£¬±¨´í-bash: ./configure: ûÓÐÄǸöÎļþ»òĿ¼
Ï£Íû¸ßÊÖ°ïÖúÎÒÏ¡£
alick ÓÚ 2011-04-30 01:27:16·¢±í:
ûÓÐÕâ¸öÎļþ¾ÍÊÇûÓÐÉú³ÉÕâ¸öÎļþ¡£ÊDz»ÊÇÖظ´ÉÏÃæ²Ù×÷ʱ£¬ÄÄÒ»²½Â©µôÁË£¿
ÁíÍ⣬helloworld.c µÃÕâÑù[code]
#include
int main(int argc, char** argv)
{
printf("Hello, Linux World!\n");
return 0;
}[/code]²»È»ÓÃÂ¥Ö÷Ìù³öÀ´µÄÄǸö±àÒëʱ±ØÈ»±¨´íµÄ
¶éÂäkiss ÓÚ 2011-04-29 16:26:27·¢±í:
ËäÈ»¶ÔÕâ¸ö²»ÊǺÜÃ÷°×,ÊDz»ÊÇûÓÐȨÏÞÄØ,È·¶¨ÓÐÕâ¸öÎļþµÄÇé¿öÏÂ,ÊÔÊÔ chmod +x ./configure