Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓÆµ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Model Center   Code  
»áÔ±   
   
 
     
   
 ¶©ÔÄ
  ¾èÖú
¹ØÓÚmakefileµÄÉú³ÉÔ­ÀíÒÔ¼°makeÏà¹ØÃüÁîµÄʹÓÃ
 
  1874  次浏览      28
 2018-8-1
 
±à¼­ÍƼö:
±¾ÎÄÀ´×ÔÓÚcnblogs£¬½éÉÜÁËÉú³Éconfigure ¹ý³ÌÖи÷ÎļþÖ®¼äµÄ¹ØÏµ£¬ ´úÂëʵÀý¡£

Ò»¡¢Éú³Éconfigure¹ý³ÌÖи÷ÎļþÖ®¼äµÄ¹ØÏµÍ¼

¶þ¡¢Ïêϸ½éÉÜ

autoscan: ɨÃèÔ´´úÂëÒÔËÑѰÆÕͨµÄ¿ÉÒÆÖ²ÐÔÎÊÌ⣬±ÈÈç¼ì²é±àÒëÆ÷£¬¿â£¬Í·ÎļþµÈ£¬Éú³ÉÎļþconfigure.scan,ËüÊÇconfigure.acµÄÒ»¸ö³ûÐΡ£

aclocal:¸ù¾ÝÒѾ­°²×°µÄºê£¬Óû§¶¨ÒåºêºÍacinclude.m4ÎļþÖеĺ꽫configure.acÎļþËùÐèÒªµÄºê¼¯Öж¨Òåµ½Îļþ aclocal.m4ÖС£aclocalÊÇÒ»¸öperl ½Å±¾³ÌÐò£¬ËüµÄ¶¨ÒåÊÇ£º¡°aclocal - create aclocal.m4 by scanning configure.ac¡±

automake:½«Makefile.amÖж¨ÒåµÄ½á¹¹½¨Á¢Makefile.in£¬È»ºóconfigure½Å±¾½«Éú³ÉµÄMakefile.inÎļþת»» ΪMakefile¡£Èç¹ûÔÚconfigure.acÖж¨ÒåÁËÒ»Ð©ÌØÊâµÄºê£¬±ÈÈçAC_PROG_LIBTOOL£¬Ëü»áµ÷ÓÃlibtoolize£¬·ñÔòËü »á×Ô¼º²úÉúconfig.guessºÍconfig.sub

autoconf:½«configure.acÖеĺêÕ¹¿ª£¬Éú³Éconfigure½Å±¾¡£Õâ¸ö¹ý³Ì¿ÉÄÜÒªÓõ½aclocal.m4Öж¨ÒåµÄºê¡£

Èý¡¢ÊµÀý

1.²âÊÔ´úÂë(¶¨ÒåÁ½¸öÎļþhello.hºÍhello.c)

/*hello.c*/ #include <iostream>
#include "hello.h"
using namespace std;
int main()
{
CHello a;
return 0;
}

/*hello.h*/ #ifndef __HELLO_H__
#define __HELLO_H__
#include <iostream>
using namespace std;
class CHello
{
public:
CHello(){ cout<<"Hello!"<<endl;}
~CHello(){ cout<<"Bye!"<<endl;}
};
#endif

2.²Ù×÷²½Öè

(1)°²×°ÒÀÀµµÄ°ü

[root@bogon autoconfig] # yum -y install automake autoconf

automake°üÀ¨:aclocal¡¢automakeµÈ

autoconf°üÀ¨£ºautoscan¡¢autoconfµÈ

(2)autoscan

[root@bogon autoconfig]# ll
-rw-r--r-- 1 root root 105 Jun 4 hello.cpp
-rw-r--r-- 1 root root 189 Jun 4 hello.h
[root@bogon autoconfig]# autoscan
[root@bogon autoconfig]# ll
total 12
-rw-r--r-- 1 root root 0 Jun 4 autoscan.log
-rw-r--r-- 1 root root 481 Jun 4 configure.scan
-rw-r--r-- 1 root root 105 Jun 4 hello.cpp
-rw-r--r-- 1 root root 189 Jun 4 hello.h

(3)aclocal

[root@bogon autoconfig] # mv configure.scan configure.ac
[root@bogon autoconfig] # vim configure.ac /*½«ÏÂÃæºìÉ«¼Ó´ÖµÄ²¿·ÖÐ޸ĵô*/
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(hello, 1.0, admin@163.com) AM_INIT_AUTOMAKE(hello, 1.0)
AC_CONFIG_SRCDIR([hello.cpp])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT(Makefile)
[root@bogon autoconfig]# aclocal
[root@bogon autoconfig]# ll
total 52
-rw-r--r-- 1 root root 37794 Jun 4 aclocal.m4
drwxr-xr-x 2 root root 51 Jun 4 autom4te.cache
-rw-r--r-- 1 root root 0 Jun 4 autoscan.log
-rw-r--r-- 1 root root 492 Jun 4 configure.ac
-rw-r--r-- 1 root root 105 Jun 4 hello.cpp
-rw-r--r-- 1 root root 189 Jun 4 hello.h

ÏÂÃæ¸ø³ö±¾ÎļþµÄ¼òҪ˵Ã÷£¨ËùÓÐÒÔ¡±#¡±ºÅ¿ªÊ¼µÄÐÐΪעÊÍ£©£º ¡¤ AC_PREREQ ºêÉùÃ÷±¾ÎļþÒªÇóµÄautoconf°æ±¾£¬±¾ÀýʹÓõİ汾Ϊ2.59¡£ ¡¤ AC_INIT ºêÓÃÀ´¶¨ÒåÈí¼þµÄÃû³ÆºÍ°æ±¾µÈÐÅÏ¢£¬¡±FULL-PACKAGE-NAME¡±ÎªÈí¼þ°üÃû³Æ£¬¡±VERSION¡±ÎªÈí¼þ°æ±¾ºÅ£¬¡±BUG-REPORT-ADDRESS¡±ÎªBUG±¨¸æµØÖ·£¨Ò»°ãΪÈí¼þ×÷ÕßÓʼþµØÖ·£©¡£ ¡¤AC_CONFIG_SRCDIR ºêÓÃÀ´Õì²âËùÖ¸¶¨µÄÔ´ÂëÎļþÊÇ·ñ´æÔÚ£¬À´È·¶¨Ô´ÂëĿ¼µÄÓÐЧÐÔ¡£´Ë´¦Îªµ±Ç°Ä¿Â¼ÏµÄhello.c¡£ ¡¤AC_CONFIG_HEADER ºêÓÃÓÚÉú³Éconfig.hÎļþ£¬ÒÔ±ãautoheaderʹÓᣠ¡¤AC_PROG_CC ÓÃÀ´Ö¸¶¨±àÒëÆ÷£¬Èç¹û²»Ö¸¶¨£¬Ñ¡ÓÃĬÈÏgcc¡£ ¡¤AC_OUTPUT ÓÃÀ´É趨 configure ËùÒª²úÉúµÄÎļþ£¬Èç¹ûÊÇmakefile£¬configure»á°ÑËü¼ì²é³öÀ´µÄ½á¹û´øÈëmakefile.inÎļþ²úÉúºÏÊʵÄmakefile¡£Ê¹ÓÃAutomakeʱ£¬»¹ÐèҪһЩÆäËûµÄ²ÎÊý£¬ÕâЩ¶îÍâµÄºêÓÃaclocal¹¤¾ß²úÉú¡£

(3)autoconf

[root@bogon autoconfig]# autoconf
[root@bogon autoconfig]# ll
total 204
-rw-r--r-- 1 root root 37794 Jun 4 aclocal.m4
drwxr-xr-x 2 root root 81 Jun 4 autom4te.cache
-rw-r--r-- 1 root root 0 Jun 4 autoscan.log
-rwxr-xr-x 1 root root 154727 Jun 4 configure
-rw-r--r-- 1 root root 492 Jun 4 configure.ac
-rw-r--r-- 1 root root 105 Jun 4 hello.cpp
-rw-r--r-- 1 root root 189 Jun 4 hello.h

´Ëʱ¿ÉÒÔ¿´µ½ÒѾ­Éú³ÉÁËconfigure

(4)autoheader

[root@bogon autoconfig]# autoheader
[root@bogon autoconfig]# ll
total 208
-rw-r--r-- 1 root root 37794 Jun 4 aclocal.m4
drwxr-xr-x 2 root root 81 Jun 4 autom4te.cache
-rw-r--r-- 1 root root 0 Jun 4 autoscan.log
-rw-r--r-- 1 root root 625 Jun 4 config.h.in
-rwxr-xr-x 1 root root 154727 Jun 4 configure
-rw-r--r-- 1 root root 492 Jun 4 configure.ac
-rw-r--r-- 1 root root 105 Jun 4 hello.cpp
-rw-r--r-- 1 root root 189 Jun 4 hello.h

autoheaderÉú³ÉÁËconfigure.h.inÈç¹ûÔÚconfigure.acÖж¨ÒåÁËAC_CONFIG_HEADER£¬ÄÇô´ËÎļþ¾ÍÐèÒª£»

(5)Makefile.am

[root@bogon autoconfig]# vim Makefile.am
[root@bogon autoconfig]# cat Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.cpp hello.h

¡¤ AUTOMAKE_OPTIONS ΪÉèÖÃAutomakeµÄÑ¡Ïî¡£ÓÉÓÚGNU¶Ô×Ô¼º·¢²¼µÄÈí¼þÓÐÑϸñµÄ¹æ·¶£¬±ÈÈç±ØÐ븽´øÐí¿ÉÖ¤ÉùÃ÷ÎļþCOPYINGµÈ£¬·ñÔòAutomakeÖ´ÐÐʱ»á±¨´í¡£AutomakeÌṩÁË3ÖÖÈí¼þµÈ¼¶£ºforeign¡¢gnuºÍgnits£¬¹©Óû§Ñ¡Ôñ£¬Ä¬Èϵȼ¶Îªgnu¡£±¾ÀýʹÐèÓÃforeignµÈ¼¶£¬ËüÖ»¼ì²â±ØÐëµÄÎļþ¡£ ¡¤ bin_PROGRAMS ¶¨ÒåÒª²úÉúµÄÖ´ÐÐÎļþÃû¡£Èç¹ûÒª²úÉú¶à¸öÖ´ÐÐÎļþ£¬Ã¿¸öÎļþÃûÓÿոñ¸ô¿ª¡£ ¡¤ hello_SOURCES ¶¨Ò塱hello¡±Õâ¸öÖ´ÐгÌÐòËùÐèÒªµÄԭʼÎļþ¡£Èç¹û¡±hello¡±Õâ¸ö³ÌÐòÊÇÓɶà¸öԭʼÎļþËù²úÉúµÄ£¬Ôò±ØÐë°ÑËüËùÓõ½µÄËùÓÐԭʼÎļþ¶¼ÁгöÀ´£¬²¢Óÿոñ¸ô¿ª¡£ÀýÈ磺ÈôÄ¿±êÌ塱hello¡±ÐèÒª¡±hello.c¡±¡¢¡±hello.h¡±Á½¸öÒÀÀµÎļþ£¬Ôò¶¨Òåhello_SOURCES=hello.c hello.h¡£

(6)automake

[root@bogon autoconfig]# automake --add-missing
configure.ac:6: warning: AM_ INIT_AUTOMAKE : two- and three-arguments forms are deprecated . For more info, see:
configure.ac:6: http://www.gnu.org /software /automake /manual /automake .html #Modernize- AM_005fINIT_ 005fAUTOMAKE - invocation
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
[root@bogon autoconfig]# ll
total 236
-rw-r--r-- 1 root root 37794 Jun 4 aclocal.m4
drwxr-xr-x 2 root root 81 Jun 4 autom4te.cache
-rw-r--r-- 1 root root 0 Jun 4 autoscan.log
-rw-r--r-- 1 root root 625 Jun 4 config.h.in
-rwxr-xr-x 1 root root 154727 Jun 4 configure
-rw-r--r-- 1 root root 492 Jun 4 configure.ac
-rw-r--r-- 1 root root 105 Jun 4 hello.cpp
-rw-r--r-- 1 root root 189 Jun 4 hello.h
lrwxrwxrwx 1 root root 35 Jun 4 install-sh -> /usr /share /automake- 1.13 /install-sh
-rw-r--r-- 1 root root 79 Jun 4 Makefile.am
-rw-r--r-- 1 root root 22227 Jun 4 Makefile.in
lrwxrwxrwx 1 root root 32 Jun 4 missing -> /usr/share / automake-1.13 / missing

´Ë²½Ö÷ÒªÊÇΪÁËÉú³ÉMakefile.in£¬¼ÓÉÏ--add-missing²ÎÊýºó£¬»á²¹È«È±ÉٵĽű¾£»

(6)²âÊÔ

[root@bogon autoconfig]# ./configure
[root@bogon autoconfig]# make
[root@bogon autoconfig]# ./hello
Hello!
Bye!

ºÍƽʱ°²×°Ðí¶à¿ªÔ´Èí¼þÒ»Ñù²Ù×÷

(7)´ò°ü

[root@bogon autoconfig]# make dist
[root@bogon autoconfig]# ll
total 436
-rw-r--r-- 1 root root 37794 Jun 4 aclocal.m4
drwxr-xr-x 2 root root 81 Jun 4 autom4te.cache
-rw-r--r-- 1 root root 0 Jun 4 autoscan.log
-rw-r--r-- 1 root root 758 Jun 4 config.h
-rw-r--r-- 1 root root 625 Jun 4 config.h.in
-rw-r--r-- 1 root root 11031 Jun 4 config.log
-rwxr-xr-x 1 root root 32557 Jun 4 config.status
-rwxr-xr-x 1 root root 154727 Jun 4 configure
-rw-r--r-- 1 root root 492 Jun 4 configure.ac
lrwxrwxrwx 1 root root 32 Jun 4 depcomp -> /usr / share /automake-1.13/depcomp
-rwxr-xr-x 1 root root 22250 Jun 4 hello
-rw-r--r-- 1 root root 72021 Jun 4 hello-1.0.tar.gz
-rw-r--r-- 1 root root 105 Jun 4 hello.cpp
-rw-r--r-- 1 root root 189 Jun 4 hello.h
-rw-r--r-- 1 root root 26008 Jun 4 hello.o
lrwxrwxrwx 1 root root 35 Jun 4 install-sh -> /usr /share /automake- 1.13/install-sh
-rw-r--r-- 1 root root 23564 Jun 4 Makefile
-rw-r--r-- 1 root root 79 Jun 4 Makefile.am
-rw-r--r-- 1 root root 23869 Jun 4 Makefile.in
lrwxrwxrwx 1 root root 32 Jun 4 missing -> /usr / share / automake-1.13 /missing
-rw-r--r-- 1 root root 23 Jun 4 stamp-h1

Èç¹ûϸÐĵϰ¿ÉÒÔ·¢ÏÖ£¬ÈËȺÖÐÒѾ­³öÏÖÁËhello-1.0.tar.gz¾ÍÊǽ«ÒѾ­±àÒëºÃµÄÎļþ½øÐÐÁË´ò°ü¡£

make all£º²úÉúÎÒÃÇÉ趨µÄÄ¿±ê£¬¼´´Ë·¶ÀýÖеĿÉÖ´ÐÐÎļþ¡£Ö»´òmakeÒ²¿ÉÒÔ£¬´Ëʱ»á¿ªÊ¼±àÒëԭʼÂ룬ȻºóÁ¬½á£¬²¢ÇÒ²úÉú¿ÉÖ´ÐÐÎļþ¡£

make clean£ºÇå³ý±àÒë²úÉúµÄ¿ÉÖ´ÐÐÎļþ¼°Ä¿±êÎļþ(object file£¬*.o)¡£

make distclean£º³ýÁËÇå³ý¿ÉÖ´ÐÐÎļþºÍÄ¿±êÎļþÍ⣬°ÑconfigureËù²úÉúµÄMakefileÒ²Çå³ýµô¡£

make install£º½«³ÌÐò°²×°ÖÁϵͳÖС£Èç¹ûԭʼÂë±àÒëÎÞÎó£¬ÇÒÖ´Ðнá¹ûÕýÈ·£¬±ã¿ÉÒ԰ѳÌÐò°²×°ÖÁϵͳԤÉèµÄ¿ÉÖ´ÐÐÎļþ´æ·Å·¾¶¡£Èç¹ûÓÃbin_PROGRAMSºêµÄ»°£¬³ÌÐò»á±»°²×°ÖÁ/usr/local/binÕâ¸öĿ¼¡£

make dist£º½«³ÌÐòºÍÏà¹ØµÄµµ°¸°ü×°³ÉÒ»¸öѹËõÎļþÒÔ¹©·¢²¼¡£Ö´ÐÐÍêÔÚĿ¼Ï»á²úÉúÒ»¸öÒÔPACKAGE-VERSION.tar.gzΪÃû³ÆµÄÎļþ¡£ PACKAGEºÍVERSIONÕâÁ½¸ö±äÊýÊǸù¾Ýconfigure.inÎļþÖÐAM_INIT_AUTOMAKE(PACKAGE£¬VERSION)µÄ¶¨Òå¡£ÔÚ´Ë·¶ÀýÖлá²úÉútest-1.0.tar.gzµÄµµ°¸¡£

make distcheck£ººÍmake distÀàËÆ£¬µ«ÊǼÓÈë¼ì²é°ü×°ºóµÄѹËõÎļþÊÇ·ñÕý³£¡£Õâ¸öÄ¿±ê³ýÁ˰ѳÌÐòºÍÏà¹ØÎļþ°ü×°³Étar.gzÎļþÍ⣬»¹»á×Ô¶¯°ÑÕâ¸öѹËõÎļþ½â¿ª£¬Ö´ÐÐ configure£¬²¢ÇÒ½øÐÐmake all µÄ¶¯×÷£¬È·ÈϱàÒëÎÞÎóºó£¬»áÏÔʾÕâ¸ötar.gzÎļþ¿É¹©·¢²¼ÁË¡£Õâ¸ö¼ì²é·Ç³£ÓÐÓ㬼ì²é¹ý¹ØµÄ°ü£¬»ù±¾ÉÏ¿ÉÒÔ¸øÈκÎÒ»¸ö¾ß±¸GNU¿ª·¢»·¾³-µÄÈËÈ¥ÖØÐ±àÒë¡£

   
1874 ´Îä¯ÀÀ       28
Ïà¹ØÎÄÕÂ

Éî¶È½âÎö£ºÇåÀíÀôúÂë
ÈçºÎ±àд³öÓµ±§±ä»¯µÄ´úÂë
ÖØ¹¹-ʹ´úÂë¸ü¼ò½àÓÅÃÀ
ÍŶÓÏîÄ¿¿ª·¢"±àÂë¹æ·¶"ϵÁÐÎÄÕÂ
Ïà¹ØÎĵµ

ÖØ¹¹-¸ÄÉÆ¼ÈÓдúÂëµÄÉè¼Æ
Èí¼þÖØ¹¹v2
´úÂëÕû½àÖ®µÀ
¸ßÖÊÁ¿±à³Ì¹æ·¶
Ïà¹Ø¿Î³Ì

»ùÓÚHTML5¿Í»§¶Ë¡¢Web¶ËµÄÓ¦Óÿª·¢
HTML 5+CSS ¿ª·¢
ǶÈëʽC¸ßÖÊÁ¿±à³Ì
C++¸ß¼¶±à³Ì