Detailed process of Automatically Generating Makefile
Source: Internet
Author: User
The detailed process of Automatically Generating Makefile-Linux general technology-Linux programming and kernel information. The following is a detailed description. Since the graduation design and development platform is Linux, Makefile writing is essential for Linux. To be lazy, I want to use autotools to automatically generate Makefile, after reading a large amount of materials, I made a small experiment based on my understanding. The process was recorded in great detail!
My platform is:
HP 6510B Notebook
Fedora 8 32-bit
The Autotools tool is available in Fedora 8 and has not been upgraded!
To compile a simple source file main. c, you need to automatically generate a makefile. The steps are as follows:
Step 1:
----------
Create a file main. c In the/root/project/main directory. Its content is as follows:
------------------------------------------------
# Include
Int main (int argc, char ** argv)
{
Printf ("Hello, Auto Makefile! \ N ");
Return 0;
}
------------------------------------------------
The status is as follows:
[Root @ localhost main] # pwd
/Root/project/main
[Root @ localhost main] # ls
Main. c
[Root @ localhost main] #
Step 2:
----------
Run autoscan to automatically create two files: autoscan. log configure. scan.
The status is as follows:
[Root @ localhost main] # autoscan
[Root @ localhost main] # ls
Autoscan. log configure. scan main. c
[Root @ localhost main] #
Step 3:
----------
Change configure. scan to configure. in.
View configure. in:
------------------------------------------------
#-*-Autoconf -*-
# Process this file with autoconf to produce a configure script.
------------------------------------------------
#-*-Autoconf -*-
# Process this file with autoconf to produce a configure script.
# AC_PREREQ:
# Make sure that a new Autoconf version is used. If you want to create an Autoconf version for configure
# This is earlier than version, so an error message is printed in the standard error output and no configure is created.
AC_PREREQ (2.61)
#
# Initialize and define the basic information of the software, including the full name of the Set package, the version number, and the email address required to report the BUG
#
AC_INIT (FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
#
# Used to detect the existence of the specified source code file to determine the validity of the source code directory
#
AC_CONFIG_SRCDIR ([main. c])
#
# It is used to generate the config. h file for autoheader to use
#
AC_CONFIG_HEADER ([config. h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
#
# Create an output file. Call this macro once at the end of 'configure. in.
#
AC_OUTPUT
------------------------------------------------
Modify action:
1. Modify the parameters in AC_INIT: AC_INIT (main, 1.0, pgpxc@163.com)
2. Add the macro AM_INIT_AUTOMAKE, which is an essential macro for automake. Similarly, the PACKAGE is the name of the software suite to be generated, and the VERSION is the VERSION number.
3. Add the output file Makefile after AC_OUTPUT.
Modified results:
------------------------------------------------
#-*-Autoconf -*-
# Process this file with autoconf to produce a configure script.
Step 4:
Run aclocal to generate an "aclocal. m4" file and a buffer folder autom4te. cache. This file mainly processes the local macro definition.
The status is:
[Root @ localhost main] # aclocal
[Root @ localhost main] # ls
Aclocal. m4 autom4te. cache autoscan. log configure. in configure. in ~ Main. c
[Root @ localhost main] #
Step 5:
Run autoconf to generate configure
The status is:
[Root @ localhost main] # autoconf
[Root @ localhost main] # ls
Aclocal. m4 autoscan. log configure. in main. c
Autom4te. cache configure. in ~
[Root @ localhost main] #
Step 6:
Run autoheader to generate the config. h. in file. This tool usually copies the user-attached symbol definitions from the "acconfig. h" file, so there is no additional symbol definition here, so you do not need to create the "acconfig. h" file.
The status is:
[Root @ localhost main] # autoheader
[Root @ localhost main] # ls
Aclocal. m4 autoscan. log configure. in ~
Autom4te. cache config. h. in configure. in main. c
[Root @ localhost main] #
Step 7:
Automake will be run soon, but preparations should be made before this!
First
Create a Makefile. am. This step is an important step to create a Makefile. The script configuration file used by automake is Makefile. am. You need to create the corresponding file by yourself. Then, convert the automake tool to Makefile. in.
The contents of Makefile. am are as follows:
------------------------------------------------
AUTOMAKE_OPTIONS = foreign
Bin_PROGRAMS = main
Main_SOURCES = main. c
------------------------------------------------
The following describes the corresponding items of the script file.
AUTOMAKE_OPTIONS indicates the option to set automake. GNU (introduced in chapter 1st) has strict regulations on software released by itself, such as license declaration file COPYING. Otherwise, an error is reported during automake execution. Automake provides three software levels: foreign, gnu, and gnits, allowing users to choose to use them. The default level is gnu. In this example, the foreign level is used to detect only required files.
Bin_PROGRAMS defines the name of the execution file to be generated. If multiple execution files are to be generated, each file name is separated by a space.
Main_SOURCES defines the original file required by the execution program "main. If the "main" program is generated by multiple original files, all the original files used by the program must be listed and separated by spaces. For example, if the target body "main" requires "main. c "," sunq. c "," main. h ", The main_SOURCES = main. c sunq. c main. h. Note that if you want to define multiple execution files, you need to define the corresponding file_SOURCES for each execution program.
Second
Use automake to generate the "configure. in" file for it. Here, use the "-adding-missing" option to allow automake to automatically add some necessary script files.
The status after running is:
------------------------------------------------
[Root @ localhost main] # automake -- add-missing
Configure. in: 8: installing './missing'
Configure. in: 8: installing './install-Sh'
Makefile. am: installing './depcomp'
[Root @ localhost main] # ls
Aclocal. m4 config. h. in configure. in ~ Main. c Makefile. in
Autom4te. cache configure depcomp Makefile. am missing
Autoscan. log configure. in install-sh Makefile. am ~
[Root @ localhost main] #
------------------------------------------------
Step 8
Run configure. in this step, run the automatic configuration setting file configure to convert Makefile. in to the final Makefile.
The running result is as follows:
------------------------------------------------
[Root @ localhost main] #./configure
Checking for a BSD-compatible install.../usr/bin/install-c
Checking whether build environment is sane... yes
Checking for a thread-safe mkdir-p.../bin/mkdir-p
Checking for gawk... gawk
Checking whether make sets $ (MAKE)... yes
Checking for gcc... gcc
Checking for C compiler default output file name... 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 ISO c89... 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: creating config. h
Config. status: executing depfiles commands
[Root @ localhost main] # ls
Aclocal. m4 config. h. in configure. in main. c Makefile. in
Autom4te. cache config. log configure. in ~ Makefile missing
Autoscan. log config. status depcomp Makefile. am stamp-h1
Config. h configure install-sh Makefile. am ~
[Root @ localhost main] #
------------------------------------------------
Step 9
Run make to test the Makefile configuration file.
The status is as follows:
------------------------------------------------
[Root @ localhost main] # make
Cd. &/bin/sh/root/project/main/missing -- run aclocal-1.10
Cd. &/bin/sh/root/project/main/missing -- run automake-1.10 -- foreign
Cd. &/bin/sh/root/project/main/missing -- run autoconf
/Bin/sh./config. status -- recheck
Running CONFIG_SHELL =/bin/sh./configure -- no-create -- no-recursion
Checking for a BSD-compatible install.../usr/bin/install-c
Checking whether build environment is sane... yes
Checking for a thread-safe mkdir-p.../bin/mkdir-p
Checking for gawk... gawk
Checking whether make sets $ (MAKE)... yes
Checking for gcc... gcc
Checking for C compiler default output file name... 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 ISO c89... none needed
Checking for style of include used by make... GNU
Checking dependency style of gcc... gcc3
Configure: creating./config. status
/Bin/sh./config. status
Config. status: creating Makefile
Config. status: creating config. h
Config. status: config. h is unchanged
Config. status: executing depfiles commands
Cd. &/bin/sh/root/project/main/missing -- run autoheader
Rm-f stamp-h1
Touch config. h. in
Make all-am
Make [1]: Entering directory '/root/project/main'
Gcc-DHAVE_CONFIG_H-I.-g-O2-MT main. o-MD-MP-MF. deps/main. Tpo-c-o main. o main. c
Mv-f. deps/main. Tpo. deps/main. Po
Gcc-g-O2-o main. o
Cd. &/bin/sh./config. status config. h
Config. status: creating config. h
Config. status: config. h is unchanged
Make [1]: Leaving directory '/root/project/main'
[Root @ localhost main] # ls
Aclocal. m4 autoscan. log config. h. in config. status configure. in depcomp main. o Makefile. am Makefile. in stamp-h1
Autom4te. cache config. h config. log configure. in ~ Install-sh main. c Makefile. am ~ Missing
[Root @ localhost main] #
------------------------------------------------
Step 10
Run the generated file main:
------------------------------------------------
[Root @ localhost main] #./main
Hello, Auto Makefile!
[Root @ localhost main] #
------------------------------------------------
So far, all the steps have been completed. It took me two days to understand and complete this experiment! It is the most interesting thing to see the final results.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.