ʹÓÃAutotoolsÔÚLinuxϵͳÉϾÙÐÐ×Ô¶¯»¯¹¹½¨µÄÉèÖü¼ÇÉ
ʹÓÃautotoolsÔÚlinuxϵͳÉϾÙÐÐ×Ô¶¯»¯¹¹½¨µÄÉèÖü¼ÇÉ
ÔÚ¿ª·¢ºÍÖÎÀíLinuxÉϵÄÈí¼þÏîĿʱ£¬×Ô¶¯»¯¹¹½¨ÊÇÒ»ÏîºÜÊÇÖ÷ÒªµÄÊÂÇ飬¿ÉÒÔ´ó´ó¼ò»¯¿ª·¢Á÷³ÌºÍïÔ̹ýʧ¡£AutotoolsÊÇÒ»¸ö±»ÆÕ±éʹÓõÄ×Ô¶¯»¯¹¹½¨¹¤¾ß£¬ËüÌṩÁËÒ»Ì×ÓÃÓÚÌìÉú¿ÉÒÆÖ²µÄMakefileµÄ¹¤¾ßÁ´¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃautotoolsÔÚlinuxϵͳÉϾÙÐÐ×Ô¶¯»¯¹¹½¨µÄÉèÖü¼ÇÉ£¬²¢¸ø³öһЩÊÊÓõĴúÂëʾÀý¡£
Ò»¡¢×°ÖÃAutotools
ÔÚLinuxϵͳÉÏ×°ÖÃAutotoolsºÜÊǼòÆÓ£¬Ö»ÐèÒªÔËÐÐÒÔÏÂÏÂÁî¼´¿É£º
$ sudo apt-get install autoconf automake libtool
µÇ¼ºó¸´ÖÆ
¶þ¡¢Ä¿Â¼½á¹¹
ÔÚʹÓÃAutotools¾ÙÐÐ×Ô¶¯»¯¹¹½¨Ö®Ç°£¬ÐèÒªÏÈÏàʶһÏÂÏîÄ¿µÄĿ¼½á¹¹¡£Ò»¸öµä·¶µÄÏîĿĿ¼½á¹¹Í¨³£°üÀ¨ÒÔÏÂÎļþºÍĿ¼£º
configure.ac£ºÕâÊÇAutotoolsµÄÉèÖÃÎļþ£¬ËüÐÎòÁËÏîÄ¿µÄ¹¹½¨ºÍ×°ÖÃÑ¡Ïî¡£
Makefile.am£ºÕâÊÇ×Ô¶¯ÌìÉúµÄMakefileÄ£°å£¬ÓÃÓÚÖ¸¶¨±àÒë¹æÔòºÍÒÀÀµ¹Øϵ¡£
src£ºÕâÊÇÔ´´úÂëĿ¼£¬ÓÃÓÚ´æ·ÅÏîÄ¿µÄÔ´´úÂëÎļþ¡£
include£ºÕâÊÇÍ·ÎļþĿ¼£¬ÓÃÓÚ´æ·ÅÏîÄ¿µÄÍ·Îļþ¡£
lib£ºÕâÊÇ¿âÎļþĿ¼£¬ÓÃÓÚ´æ·ÅÏîÄ¿µÄ¾²Ì¬¿âºÍ¶¯Ì¬¿â¡£
Èý¡¢±àдconfigure.acÎļþ
ÔÚÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪconfigure.acµÄÎļþ£¬ÕâÊÇAutotoolsµÄÉèÖÃÎļþ£¬¿ØÖÆ×ÅÏîÄ¿µÄ¹¹½¨Ñ¡Ïî¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄÉèÖÃÎļþʾÀý£º
AC_PREREQ([2.69]) AC_INIT([myproject], [1.0], [myemail@example.com]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_CONFIG_SRCDIR([src/myfile.c]) AC_CONFIG_HEADERS([config.h]) AC_PROG_CC AC_CONFIG_FILES([Makefile]) AC_OUTPUT
µÇ¼ºó¸´ÖÆ
ÉÏÊöʾÀýÖУ¬AC_INITÖ¸¶¨ÁËÏîÄ¿µÄÃû×Ö¡¢°æ±¾ºÍÁªÏµ·½·¨¡£AM_INIT_AUTOMAKEÓÃÓÚ³õʼ»¯Autotools£¬²¢Ö¸¶¨ÁËһЩ±àÒëÑ¡Ïî¡£AC_CONFIG_SRCDIRºÍAC_CONFIG_HEADERS»®·ÖÓÃÓÚÖ¸¶¨Ô´´úÂëÎļþºÍÉèÖÃÎļþµÄλÖá£AC_PROG_CCʹÓüì²â³ÌÐòÀ´È·¶¨ÏµÍ³ÉÏ¿ÉÓõÄC±àÒëÆ÷¡£AC_CONFIG_FILESÖ¸¶¨ÁËÒªÌìÉúµÄMakefileÎļþ¡£
ËÄ¡¢±àдMakefile.amÎļþ
ÔÚÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪMakefile.amµÄÎļþ£¬ÕâÊÇ×Ô¶¯ÌìÉúµÄMakefileÄ£°å¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý£º
AUTOMAKE_OPTIONS = foreign SUBDIRS = src
µÇ¼ºó¸´ÖÆ
ÉÏÊöʾÀýÖУ¬AUTOMAKE_OPTIONSÓÃÓÚÖ¸¶¨Ò»Ð©×Ô¶¯»¯¹¹½¨Ñ¡Ïî¡£SUBDIRSÖ¸¶¨ÁËÒª¹¹½¨µÄ×ÓĿ¼£¬ÕâÀïÊÇsrcĿ¼¡£
Îå¡¢±àдMakefile.inÎļþ
ͨ¹ýÔËÐÐÒÔÏÂÏÂÁAutotools½«Æ¾Ö¤Ç°ÃæµÄconfigure.acºÍMakefile.amÎļþÌìÉúMakefile.inÎļþ£º
$ autoreconf -f -i
µÇ¼ºó¸´ÖÆ
Áù¡¢ÌìÉúMakefileÎļþ
ͨ¹ýÔËÐÐÒÔÏÂÏÂÁAutotools½«Æ¾Ö¤Makefile.inÎļþÌìÉúMakefileÎļþ£º
$ ./configure
µÇ¼ºó¸´ÖÆ
Æß¡¢¹¹½¨ÏîÄ¿
ͨ¹ýÔËÐÐÒÔÏÂÏÂÁAutotools½«Æ¾Ö¤MakefileÎļþ¾ÙÐÐÏîÄ¿¹¹½¨£º
$ make
µÇ¼ºó¸´ÖÆ
°Ë¡¢×°ÖÃÏîÄ¿
ͨ¹ýÔËÐÐÒÔÏÂÏÂÁAutotools½«Æ¾Ö¤MakefileÎļþ¾ÙÐÐÏîĿװÖãº
$ make install
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁ°ÑÏîÄ¿µÄ¿ÉÖ´ÐÐÎļþ¡¢¿âÎļþºÍÍ·Îļþ¸´ÖƵ½Ö¸¶¨µÄĿ¼ÖС£
¾Å¡¢´úÂëʾÀý
¼ÙÉèÎÒÃÇÓÐÒ»¸ö¼òÆÓµÄÏîÄ¿£¬°üÀ¨Ò»¸öÃûΪmyprojectµÄ¿ÉÖ´ÐÐÎļþºÍÒ»¸öÃûΪmylibµÄ¾²Ì¬¿â¡£ÏÂÃæÊÇÒ»¸öʾÀýµÄMakefile.amÎļþµÄ´úÂ룺
AUTOMAKE_OPTIONS = foreign SUBDIRS = src lib bin_PROGRAMS = myproject myproject_SOURCES = src/main.c myproject_LDADD = lib/libmylib.a noinst_LIBRARIES = libmylib.a libmylib_a_SOURCES = lib/mylib.c
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸ö¿ÉÖ´ÐÐÎļþmyproject£¬ÔÚsrcĿ¼ÏÂÓÐÒ»¸ömain.cÔ´Îļþ¡£ÎÒÃÇ»¹½ç˵ÁËÒ»¸ö¾²Ì¬¿âlibmylib.a£¬ÔÚlibĿ¼ÏÂÓÐÒ»¸ömylib.cÔ´Îļþ¡£
ÔÚʹÓÃAutotoolsµÄÀú³ÌÖУ¬¿ÉÒÔƾ֤ÏÖÕæÏàÐζÔÉèÖÃÎļþºÍMakefileÎļþ¾ÙÐе÷½â£¬Öª×ãÏîÄ¿µÄÐèÇó¡£
×ܽ᣺
±¾ÎļòÒªÏÈÈÝÁËÔõÑùʹÓÃautotoolsÔÚlinuxϵͳÉϾÙÐÐ×Ô¶¯»¯¹¹½¨µÄÉèÖü¼ÇÉ£¬²¢¸ø³öÁËһЩÊÊÓõĴúÂëʾÀý¡£Í¨¹ýʹÓÃAutotools£¬ÎÒÃÇ¿ÉÒÔÀû±ãµØÌìÉú¿ÉÒÆÖ²µÄMakefileÎļþ£¬¼ò»¯ÏîÄ¿µÄ¹¹½¨ºÍ×°ÖÃÁ÷³Ì¡£Ï£Íû±¾ÎĶÔÄúÔÚLinuxÉϾÙÐÐÈí¼þ¿ª·¢ºÍÖÎÀíʱÓÐËù×ÊÖú£¡
ÒÔÉϾÍÊÇʹÓÃAutotoolsÔÚLinuxϵͳÉϾÙÐÐ×Ô¶¯»¯¹¹½¨µÄÉèÖü¼ÇɵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡