Operate Makefile

xiaoxiao2021-03-06  106

People who write in Unix have probably touched Makefile, especially in c to develop program.

people. It is really convenient to develop and compile the program with make, but to write a Makefile

It is not simple. Introduction to Makefile does not have much file, the GNU Make is a few

The files of the papaypage, Overview is overfold, it is no wonder that many people will hear unix colors.

This article will introduce how to use GNU AutoConf and Automake to assist us

"Automatic" produces Makefile files, and the development of the software can be like Apache,

Mysql and common gnu software, as long as `` ./configure '', `` `` ',

`` make install '' can be installed into the system. If you have an open Open

Source's software, or just want to write a write in the UNIX system. I hope this introduction file can

Help you easily access the hall of UNIX Programming.

1 Introduction

Makefile is basically "target", "DependenCIES) and

A series of rules composed of "Actions". Make will depend on Makefile rules

To determine how to compile (Compile) and links. In fact, make Make can do

Not just compiled and connecting, such as FreeBSD port collection,

Makefile can also download the original program kit, extract, patch

(patch), set, then compile, install it into the system.

Makefile Basic Construction Although simple, proper use of these rules can also become many

The same trick. But therefore, many when you start learning to write makefile, you will feel that there is no specification.

Cycurve, Makefile written by everyone is not very the same, I don't know where to start, and

It is often limited to its own development environment, as long as the environment variables are different or the path is changed, it may

Makefile has to be modified. Although there is GNU Makefile Conventions (GNU

Makefile formula to book some standards for writing Makefile when designing GNU

Quasi-and standardization, but content is very complicated, and often do some adjustments, in order to reduce program

The designer maintained the burden of Makefile, so there was Automake.

Program designers only need to write some pre-defined huge gauges (Macro), handed over to Automake Processing

A Makefile.IN file that is available for AutoConf is then generated. Re-use

AutoConf generated automatic setting file Configure can generate a GNU Makefile

A convention of Makeifle.

2. Before going on

Before you start trying with Automake, please confirm your system to install the following software:

GNU Automake

2. gnu autoconf

3. GNU M4

4. Perl

5. GNU Libtool (if you need shared library)

I will suggest that you should also use the GNU C / C compiler, GNU Make and other GNU

Tool program is developed as an environment, these tools belong to Open Source Software

Not only free and powerful. If you use Red Hat Linux to find all the above

The soft RPM file, freebsd also has ready-made packages to be installed directly, or you can also download the original gear back DIY. The following example is in Red Hat

LINUX 5.2 CLE2 is completed.

3. A simple example

The Makefile generated by Automake can also make the program compilation and links.

How to generate program files (such as Manual Page, INFO files, DVI files)

Taking the original program package to disperse, it is considered, so the original program is stored.

The directory architecture is best in line with GNU standard practice, and I will take Hello.c as an example.

child.

Built a new subdirectory in the working directory, then build a one under the DEVEL

`` Hello '' subdirectory, this directory will be used as us to store this Hello and related

Places of archives:

% MKDir Devel

% CD Devel

% MKDIR Hello

% CD Hello

Write a Hello.c file with the editor.

#include

INT main (int Argc, char ** argv)

{

Printf (`` Hello, GNU! / n ');

Return 0;

}

Next, use AutoConf and Automake to help us produce your Makefile file.

1. Produce a sharxt of configure.in with AutoScan, perform AutoScan

Have a configure.scan file, we can use it as configure.in

Set of blueprints.

% AutoScan

% LS

Configure.scan hello.c

2. Edit the configure.scan file, as shown below, and change its file name

Configure.in

DNL Process this file with autoc to produce a conce

Fighe script.

AC_INIT (Hello.c)

AM_INIT_AUTOMAKE (Hello, 1.0)

DNL CHECKS for Program.

AC_PROG_CC

DNL CHECKS for Libraries.

DNL CHECKS for Header Files.

DNL CHECKS for Typedefs, Structures, And Compiler Ch

Aracteristics.

DNL Checks for Library Functions.

AC_OUTPUT (MAKEFILE)

3. Execute aclocal and autoconf, which generate ACLOCAL.M4 and CONFIGUREs.

File

% ACLOCAL

% AutoConf

% LS

Aclocal.m4 configure configure.in Hello.c

4. Edit the Makefile.Am file, the content is as follows

Automake_Options = Foreign

BIN_PROGRAMS = Hello

Hello_sources = Hello.c

5. Execute Automake --Add-missing, Automake will generate according to Makefile.Am file

Some files contain the most important makefile.in

% Automake --Add-missing

Automake: configure.in: installing `./install-sh '

Automake: configure.in: installing `./mkinstallDirs'Automake: configure.in: installing` ./missing '

6. Finally, execute ./configure,

% ./configure

Creating cache ./config.cache

Checking for a BSD Compatible Install ... / usr / bin / in

Stall -c

Checking WHether Build Environment Is Sane ... YES

Checking WHETHER Make Set $ ​​{make} ... YES

Checking for Working Aclocal ... Found

Checking for Working AutoConf ... Found

Checking for Working Automake ... Found

Checking for Working AutoHeader ... found

Checking for working makeinfo ... found

Checking for GCC ... GCC

Checking WHETHER THE C Compiler (GCC) Works ... YES

Checking WHETHER THE C Compiler (GCC) IS A Cross-Co

MPILER ... NO

Checking WHETHER WE Are Using GNU C ... YES

Checking WHETER GCC Accepts -g ... YES

Updating cache ./config.cache

Creating ./config.status

Creating makefile

Now you have produced a Makefile file in your directory, the next `` Make '' directive

Start compilation of Hello.c into executive files, execute ./hello and gnu sound!

% make

GCC -DPackage = / "Hello /" -dversion = / "1.0 /" -i. -i. -g -O2 -c HE

Llo.c

GCC -G -O2 -O Hello Hello.o

% ./hello

Hello! GNU!

You can also try `` make clean ',' 'make install' ',' 'make dist' '

What is the result. You can also give you the boss of the produced makefile show, let him

This is a look at you :-)

4. A exploration

The above process of producing Makefile is very different from the way it is written in the past, abandoning the tradition

Define the rules of make, using Automake only need to use some of the already defined giant

I.e. We write the giant set and goals (Target) in the Makefile.Am file, Automake

After reading the Makefile.Am file, this string has defined this string to expand and generate the corresponding

Makefile.in file, then then by configure this shell script

Makefile.in produces suitable Makefile.

[Figure 1: Process for producing Makefile using AutoConf and Automake]

The above figure shows the files you want to use in the examples in the previous section and the generated files, as an asterisk

(*) Represents the executable file. In this example, you can use the AutoConf and Automake Tools.

The generated file has configure.scan, ACLOCAL.M4, Configure, makefile.in, which requires us to join the settlers configure.in and makefile.am.

4.1 Edit Configure.in

AutoConf is a tool for generating a 'configure' file. 'configure' is a

Shell Script, which automatically sets the original program to meet the Unix system on a variety of different platforms

The characteristics of the system, and produce a suitable Makefile file or C standard according to the system parameters and the environment.

Header file, allowing the original program to be easily edited on these different platforms

Translated. AutoConf reads the configure.in file and generates 'configure'.

Shell script.

The content of the Configure.in file is a series of gnu m4, these giants have passed

The autoconf will become a shell script for checking system features. Configure.in

The order of the gap is not particularly regulations, but every configure.in file must be all

Join the AC_INIT gather before gathering, then add AC_OUTPUT giant at the end of all gauges

set. We can first scan the original gear with AutoScan to generate a configure.scan file.

Do some modifications to configure.scan to configure.IN files. Used in the example

The gauge is as follows:

DNL

The words behind this gather will not be processed and can be considered as an annotation.

AC_INIT (File)

This gauge is used to check the path where the original code is located, and AutoScan will automatically generate, we

Don't modify it.

AM_INIT_AUTOMAKE (Package, Version)

This is the huge set of automake, and package is the soft cover we have to produce.

The name of the part, Version is the version number.

AC_PROG_CC

Check the C compiler available to the system. If the original program is written with C, you need this giant.

set.

AC_OUTPUT (File)

Set the file to be generated by configure, if it is makefile,

Configure will take the result of it checks into the Makefile.IN file and then generate

Suitable Makefile.

In fact, when we use Automake, we must also have some other gatherings, these extra giants

Set us with ACLOCAL to help us. Perform ACLOCAL will generate aclocal.m4

Set, if there is no special purpose, we can do not need to modify it, the giant generated by ACLOCAL

I will tell Automake how to do it.

With the two files with configure.in and aclocal.m4, you can do AutoConf.

To generate Configure files.

4.2 Edit Makefile.Am

Next we want to edit the makefile.Am file, Automake will be based on configure.in

The gauge turns made to makefile.IN file. Makefile.Am file definitions we

The goal to produce:

Automake_Options

Set the option of Automake. Automake is mainly helping to develop a GNU software.

Maintain the software kit, so when executing Automake, check if there is a standard in the directory

The file files should be available in the gnu software kit, such as 'News', 'Author',

Files such as 'Changelog'. When it is Fornow, Automake will check the standard of the general software suite.

BIN_PROGRAMS

Define the implementation file name we have to produce. If you want to generate multiple execution files, each file name

Separate with a blank character.

Hello_sources

Define the original file required by 'Hello'. If 'Hello'

It is generated by multiple original files, and the original files used to be used must be listed.

The character is separated. Suppose the 'Hello' is needed to 'Hello.c', 'main.c',

Definition of three files of 'hello.h'

Hello_sources = hello.c main.c hello.h

If we define multiple execution files, you must define relative to each execution file.

Filename_sources.

Edit your Makefile.AM file, you can use Automake --Add-missing to generate

Makefile.in. Plus - ADD-MISSING Options is to tell Automake to help us

Enter the files necessary for packaging a software kit. AUTOMAKE produced made made of makefile.in

The file is completely conforming to the GNU Makefile, we only need to perform configure

Shell Script can produce a suitable Makefile file.

4.3 Using Makefile

There are several preset targets that use the makefile file generated by Configure to use, we

Just take the following brief description as follows:

Make all

Generate the goal we set, that is, the execution file in this example. Just play Make or this

When you start compiling the original code, then connect, and generate an execution file.

Make clean

Clear the previously compiled execution file and destination file (Object file, * .o).

Make distclean

In addition to clearing the executive file and destination, Configure generated Makefile

Also clear.

Make Install

The program is installed into the system. If the original code is compiled, the execution result is correct,

Install the program to the system-preset execution file storage path. If we use

BIN_PROGRAMS is a huge gather, the program will be installed to / usr / local / bin this purpose

record.

Make dist

Pack the program and related files into a compressed file for district.

Performed in the directory will generate a file with package-version.tar.gz name

case. Package and Version These two variables are based on the Configure.IN file

AM_INIT_AUTOMAKE (Package, Version) definition. In this example

'Hello-1.0.tar.gz' file.

Make disccheck

Similar to Make Dist, but add to whether the compressive file after the package is normal. This one

The target will automatically put this pressure in addition to the programs and related files into tar.gz files.

The scalet is unproced, executes configure, and performs the action of Make All, confirm compilation

After error, this tar.gz file is ready to spread. This check is not

Often useful, check the kits, basically give any GNU development ring

The people in the country are recompiled. In addition to the example of hello-1.tar.gz, in addition to RED

On Hat Linux, you can also correctly recompile in FreeBSD 2.2.x.

It should be noted that the software kit produced by using AutoConf and Automake is available in an environment where AutoConf and Automake is installed, because configure is

A shell script, it is designed to be under the SHELL of general Unix

carried out. But if you want to modify the configure.in and makefile.Am files, new

You must have AutoConf and Automake when configure and makefile.in are gear.

5. Related messages

AutoConf and Automake feature are very powerful, you can find from the INFO files they attach

Detailed usage. You can also find a lot of existing GNU software or Open Source software.

To related configure.in or makefile.Am file, they are learning AutoConf and

AUTOMAKE is more tips for the best examples.

This introduction only uses autoconf and automake's fur, if you join

Open source software development ranks, I hope this file can help you produce Makefile

There is a simple basis. Other related to the development of GNU program or C programming and makefile

Detailed use and skills, I suggest you from GNU Coding Standards3 (GNU coding standard rules)

Determined) read, containing GNU Makefile practice, as well as development of GNU software kit

Quick procedures and conventions. These GNU software's online description files can be

Http://www.gnu.org/ found on this website.

6. Conclusion

A Makefile does not seem to be like AuConf and Automake

It's so difficult to use AutoConf, it also makes us on different platforms or Unix

It is simple to spread and compile the program, which is coming to the developed personnel on UNIX system.

Say a lot of burdens. Use these GNU tool software to help us easier

Go to the development program, and it is easier to maintain the original code.

In 1998, it was a year of Open Source, and many Open Source

Software is generally welcomed and used by the public. Thanks to all Dedications for Open Source

People, I also hope that by this article can attract more people to add "freedom", "open" Open

Source ranks.

About this document ...

Makefile1

This document Was generated sale the latex2html translator

Version 98.2 Beta6 (August 14th, 1998)

Copyright (C) 1993, 1994, 1995, 1996, Nikos Drakos, Computer

Based Learning Unit, University of Leeds.

Copyright (C) 1997, 1998, Ross Moore, Mathematics Department,

Macquarie University, Sydney.

The Command Line Arguments WERE:

Latex2html -split 0 -show_section_numbers automake.tex

The Translation Was Initiated by on 1999-02-11

FootNotes

... / Title1

This document uses ChiLatex production.

... CLE2

CLE (Chinese Linux Extension, Linux Chinese Extension Kit),

http://cle.linux.org.tw / ... Standards3

GNU Coding Standards, Richard Stallman

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

New Post(0)