Talks on the Makefile File Production in the Linux Environment (1)

xiaoxiao2021-04-08  281

Transfer from: http://www.linuxmine.com/3690.html 2006-6-23

Author: linux treasury (http://www.linuxmine.com) from: linux treasury (http://www.linuxmine.com) Existing: http: //www.linuxmine.com/3690.html Contact: linuxmine # gmail .com doesn't understand? Welcome to the Linux Forum (http://bbs.linuxmine.com) to participate in discussion! Makefile file production on Linux Environment (1) Write: Leaf ZHOUEMAIL: Leaf_zhou_8@hotmail.com Free copy but prohibited from deletion 2003-10-12 Whether it is a presence of an initialist or a senior Linux program, writing a Makefile file is a very troublesome thing; more, developers should put the main energy on the program code, and there is too much in the Makefile file. The energy is obviously unmokent; there is also a different processor architecture, the compiler is often different, especially the compilation of various programs in some embedded systems, especially in some embedded systems, and the Makefile file is also It is important to complicate and this problem is also. The masters of Linux for these issues have long been thought of, so they have developed some tools that automatically generate the Makefile file. They are the following tools:> GNU Automake> GNU AutoConf> GNU M4> Perl> GNU Libtool So your operating system must have the above software, otherwise it is not able to automatically generate a Makefile file or a variety of processes during the generation. problem. Use the AutoConf / Automake / AutoHeader tool to handle various transplantability, with these tools to complete the collection of system configuration information, and make your Makefile file. Then just pass "./configure; make" when intending to compile the source code, you can get a clean and neat compilation.

Make the Makefile file requires the following steps: 1> Establish compilation directory and source directory and source file (ie, the source file to be compiled) [root @ localhost leaf] #mkdir testmk [root @ localhost leaf] #CD TestMk [root @ Localhost Testmk] #vi hello.c Editing Hello.c files as follows: / * filename: hello.c * / # include int main (int Argc, char ** argv) {printf ("% s / N "," Hello, World! ") Return 0;} 2> Template file for a configure.in file using the AutoScan tool CONFIGURE.SCAN file: [root @ localhost testmk] #autoscan [root @ localhost testmk] #lsconfigure. Scan Hello.c3> Create the configure.scan file to the configure.in file, and compile its contents as follows: [Root @ localhost testmk] #mv configure.scan configure.in [root @ localhost testmk] #vi configure.indnl process this file with autoconf to produce a configure script.AC_INIT (hello, 1.0) (hello.c) dnl Add the file by leafAM_INIT_AUTOMAKE dnl Checks for programs.AC_PROG_CCdnl Checks for libraries.dnl Checks for header files.dnl Checks for typedefs, structures, and compiler characteristics.dnl Checks for library functions.AC_OUTPUT (Makefile) 4> perform aclocal, will produce aclocal.m4 file [root @ localhost testmk] #aclocal [root @ localhost testmk] # lsaclocal.m4 configure.in hello.c5 > Execute AutoConf, generate confiure file [root @ localhost testmk] #autoconf [root @ localhost testmk] # lsaclocal.m4 [Autom4te.cache] configure configure.in Hello.c6> Create file makefile.am and edit its contents as follows: Automake_Options = foreignbin_programs = helloHello_Sources = hello.c where hello is the executable file name generated after compiling, and the third line is equal to the source file list 7> Execute the Automake program, the Automake program will generate some files according to Makefile.am. The most important thing is Makefile.in file: [root @ localhost testmk] #automake --add-missingconfigure.in: installing `./install-sh'configure.in: installing`/mkinstallDirs'Configure.in: installing` ./missing'mkefile.am: installing`/DEPComp'[Root@

Localhost Testmk] # lsaclocal.m4 [Autom4Te.cache] configure configure.in DepComphello.c install-sh makefile.am makefile.in missingmkinstallDirs8> Execute the configure script to generate the Makefile file we need. [Root @ localhost testmk] #. / Configurechecking for a BSD-compatible install ... / usr / bin / install -cchecking whether build environment is sane ... yeschecking for gawk ... gawkchecking whether make sets $ (MAKE). .. yeschecking for gcc ... gccchecking for C compiler default output ... a.outchecking whether the C compiler works ... yeschecking whether we are cross compiling ... nochecking for suffix of executables ... checking for suffix of object files ... ochecking whether we are using the GNU C compiler ... yeschecking whether gcc accepts -g ... yeschecking for gcc option to accept ANSI C ... none neededchecking for style of include used by make ... GNUchecking dependency style of gcc ... gcc3configure: creating ./config.statusconfig.status: creating Makefileconfig.status: executing depfiles commands9> to make the final implementation only done: [root @ localhost testmk] # makesource = 'hello.c' object = 'Hello.o' libtool = no /DEpfile='.deps/hello.po 'tmpdepfile ='. DEPS / HELLO.TPO '/ DepMode = GCC3 / bin / sh ./depcomp / gcc -dpackage_name = / "/" - DPAC Kage_tarname = / "/" -dpackage_string = / "/" -dpackage_bugreport = / "/" -dpackage = / "hello /" -dversion = / "1.0 /" -i. -I. - G -O2 -C `Test -f 'hello.c' || echo './'`helo.cccc -g-^ --o Hello Hello.o Note: 1. The above is tested in the Redhat Linux 9.0 environment .

转载请注明原文地址:https://www.9cbs.com/read-132662.html

New Post(0)