Makefile, makefile. In, and makefile. AM

Source: Internet
Author: User

Recently I have been studying open-source things and found many makefile. am, makefile. In, and makefile files. What is the relationship between them? What tools can be used for generating?

Writing makefile is troublesome for beginners and senior Linux programmers. Furthermore, developers should focus on programming code, it is obviously unwise to spend too much energy on makefile files. In addition, for different processor architectures, compilers and environments are often different, especially compilation of various programs in some embedded systems, as a result, the porting problem also makes the preparation of makefile files complicated, and also becomes very important. Linux experts have long thought of these issues, so they have developed some tools that can automatically generate makefile files. They are the following tools:
> GNU automake
> GNU Autoconf
> GNU M4
> Perl
> GNU libtool
Therefore, you must install the above software in your operating system. Otherwise, you cannot automatically generate makefile files or encounter various problems during the generation process. Use Autoconf/automake/autoheader to handle various portability issues. Use these tools to collect system configuration information and create makefile files. Then you can compile the source code with a simple command like "./configure; make.

Make the MAKEFILE file in the following steps:
1> Create a compilation directory, source code directory, and source code file (that is, the source file to be compiled)
[Root @ localhost leaf] # mkdir testmk
[Root @ localhost leaf] # cd testmk
[Root @ localhost testmk] # vi hello. c
Edit the following content in the hello. c file:
/* Filename: Hello. C */
# Include <stdio. h>

Int main (INT argc, char ** argv)
{
Printf ("% s/n", "Hello, world! ")
Return 0;
}
2> Use autoscan to generate a template file Configure. Scan for the configure. In file:
[Root @ localhost testmk] # autoscan
[Root @ localhost testmk] # ls
Configure. Scan hello. c
3> rename Configure. Scan to configure. In and compile the file 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 the aclocal. M4 file.
[Root @ localhost testmk] # aclocal
[Root @ localhost testmk] # ls
Aclocal. M4 Configure. In hello. c
5> execute Autoconf to generate a confiure File
[Root @ localhost testmk] # Autoconf
[Root @ localhost testmk] # ls
Aclocal. M4 [autom4te. cache] configure Configure. In hello. c
6> Create the makefile. Am file and edit the content as follows:
Automake_options = foreign
Bin_programs = Hello
Hello_sources = Hello. c
Hello is the name of the executable file generated after compilation, and the third line is followed by the source file list
7> execute the automake program. The automake program will generate some files based on makefile. am. The most important of them is the 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> execute the configure script to generate the MAKEFILE file we need.
[Root @ localhost testmk] #./configure
Checking for a BSD-compatible install.../usr/bin/install-C
Checking whether build environment is sane... yes
Checking for gawk... gawk
Checking whether make sets $ (make)... yes
Checking for GCC... gcc
Checking for C compiler default output... 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 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> at last, just execute make:
[Root @ localhost testmk] # Make
Source = 'hello. c' object = 'hello. o' libtool = No/
Depfile = '. deps/Hello. po' tmpdepfile = '. deps/Hello. TPO '/
Depmode = gcc3/bin/sh./depcomp/
Gcc-dpackage_name = ""-dpackage_tarname = ""-dpackage_version = ""-dpackage_string = "-dpackage_bugreport =" "-dpackage =" hello "-dversion =" 1.0 "-I. -I. -G-O2-C 'test-F' hello. c' | echo '. /''hello. c
Gcc-g-O2-O hello. o

Note:
1. The above content is successfully tested in the RedHat Linux 9.0 environment.
2. Prepared by Yu Mingxi, Chen Xiangyang, and Fang Han, the Linux programming authoritative guide.
3. Other domestic and foreign website materials
4. program files and versions in RedHat 9.0
Autoconf-2.57-3.noarch.rpm
Automake-1.6.3-5.noarch.rpm
Gcc-3.2.2-5.i386.rpm

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.