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

xiaoxiao2021-03-06  42

LINUX Environment Makeup (1) Writing: Leaf Zhou Email: Leaf_zhou_8@hotmail.com Free copy but prohibitedly deleted 2003-10-12 No matter what a senior Linux programmer is written, write makefile files It is a very troublesome thing; more, developers should put the main energy on the programming code, and it costs too much in the makefile file obviously unblocked; and for different processor architectures Different compilers, the environment is different, especially the compilation of various procedures in the embedded system, so that the implication of the Makefile file is complicated, and this problem is important. 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 with the AutoScan tool to generate a configure.in file configure.scan file: [root @ localhost testmk] #autoscan [root @ localhost testmk] #LS Configure .scan hello.c 3> 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.in dnl Process this file with autoconf to produce a configure script. AC_INIT (hello.c) dnl Add the file by leaf AM_INIT_AUTOMAKE (hello, 1.0) dnl Checks for programs. AC_PROG_CC dnl 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> Execute ACLOCAL to generate aclocal.m4 file [root @ localhost testmk] #clocal [root @ localhost testmk] #L s aclocal.m4 configure.in Hello.c 5> Execute AutoConf, generate confiure file [root @ localhost testmk] #autoconf [root @ localhost testmk] #LS aclocal.m4 [Autom4Te.cache] configure configure.in Hello.c 6> Create a file Makefile.am and edit its contents as follows: Automake_Options = Foreign bin_programs = Hello Hello_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> Executing the Automake program, the Automake program generates some files according to Makefile.am, where the most important thing is Makefile.in file: [root @ localhost testmk] #automake --add-missing configure.in: installing `/install-sh ' Configure.in: installing `./mkinstalldirs 'configure.in: installing`/missing'

Makefile.am: installing `./depcomp '[root @ localhost testmk] #ls aclocal.m4 [autom4te.cache] configure configure.in depcomp hello.c install-sh Makefile.am Makefile.in missing mkinstalldirs 8> configure script Generate the Makefile file we need. [root @ localhost testmk] #. / configure checking for a bsd-compatible install ... / usr / bin / install ... product is checking for gawk ... gawk checking for gawk ... gawk checking WHETHER MAKE SETS $ (Make) ... YES Checking for GCC ... GCC Checking for C Compiler Default Output ... a.out checking WHETER THE C Compiler Works ... Yes Checking WETHER WEARE CROSS Compiling ... No Checking for Suffix Of Executables ... Checking for Suffix Of Object Files ... o Checking WHETHER WEE Are Using The GNU C Compiler ... Yes Checking WHETER 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 9> last executed only make you're done [Root @ localhost testmk] #make source = 'hello.c' {= 'hello.o' libtool = no / depfile = '. DEPS / HELLO.PO' TMPDEPFILE = '. DEPS / HELLO.TPO' / Deps = GCC3 / BIN / SH./DEPComp / GCC - DPACKAGE_NAME = / "/" / "-dpackage_version = /" / "-dpackage_bugreport = /" / "-dpackage = /" hello / "-dversion = /" 1.0 / " -I. -I. -G -O2 -C `Test -f 'hello.c' || echo './'`Hello.c gcc -g-^ -o hello hello.o Note: 1. All above Tested in the Redhat Linux 9.0 environment.

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

New Post(0)