A software, from zero to release (.tar.gz)
Author: Zhao software (http://chiosoft.51.net)
E-mail: chiosoft@tom.com
※ Please indicate the source ※
This article teaches you how to use AutoConf, Automake, etc. to make a software published in source code (.tar.gz) and use custom parameters when executing configure. (In fact, this is my own notes ^ _ ^)
First, outline and basics
We get a package (general .tar.gz or .tar.bz2 format), we can compile the installation with ./confiugure ,make ,make install, where you can run ./configure Add different parameters according to your needs (available ./configure --help to view the parameter table).
Let me talk about it first. What will it be generated after it ?/Configure? After running the system, config.h and multiple makefiles are generated according to the actual situation of the user. Makefile is the template used when running Make; and config.h records the user's custom parameters in macro (Marco), the compiler can pre-compile the source code according to config.h. Thereby generating a personalized executive file.
Second, our "software"
Now we can do your own "software". In order to get more actual, you will use multiple source programs, first build a directory TT, used to put our things, then build a SRC directory under TT, in general The source code is placed in the SRC (it seems to be an incompatible rule: p). The overall architecture is as follows:
| -configure.in | -makefile.am | -acconfig.h | -
1.
Configure.in This is the most important document, and the entire installation process is dominated by it.
2.
Makefile.am Automake will generate makefile.in based on it, and then turn makefile.in into the final makefile, which generally says there should be a makefile.am in the top directory and individual catalogs.
3.
Acconfig.h AutoHeader will generate config.h.in according to it, and then turn config.h.in by ./configure .in into the final config.h
4.
Tt.c QQ.c QQ.H This is our source program.
※ Source code content: (part of the green part is used to achieve personalized compilation)
Tt.c # include
QQ.c # include
※ Operation process:
1. First of all the teachers come to some name.
2. If POPO is coming, you will report your own name.
3. Next, the turn to QQ report, if POPO has come, QQ will ask POPO.
Obviously, the POPO is attended, and it is completely depends on whether the POPO macro (Macro) is defined, we can achieve different effects as needed to decide whether it is to define it before compiling.
If config.h exists, Makefile will pass the macro Have_config_h to the compiler, so our program should not enter config.h incrude if there is no Have_config_h.
Third, the production process
Please follow the following execution order to do:
The first step is written in configure.in
There are two ways to generate configure.in, one is written from zero, and another method is to generate configure.scan with AutoScan, execute AutoScan, which contains some template content, as long as the name is changed when used .in .in can.
There are two commands used in configure.in, one is based on the AC, indicating that it is provided by AutoConf, and the other is to start with AM, and the representative is provided by Automake.
In Configure.in, we can complete a lot of detection actions, such as the program, header files, libraries, etc. required to compile, the function is very powerful, but we only detect the compiler and header file here, please see
GNU Manuals Online
The behavior noted in "DNL" comment (the green part in the code).
Configure.indnl Initialization AutoConf, parameter is the file AC_INIT (SRC / TT.C) DNL where the entrance function is located, the parameter is the software name and version number am_init_automake (tt, 0.1.0) DNL tells Automake, we use the configuration files we used. To config.ham_config_header (config.h) DNL is part of the custom parameter, see the following description ac_arg_enable (popo, [--enable-popo is present], enable_popo = no) if Test "$ enable_popo" = YES; THEN Echo "POPO IS Here!" AC_DEFINE (POPO) Else Echo "Popo isn't Here!" FIDNL Detection Compiler Ac_Prog_ccDNL Detection Standard C's header AC_HEADER_STDCDNL output file, generally top-level directory and subdirectories There should be makefile output AC_OUTPUT (Makefile SRC / Makefile)
./configure's custom parameter has two kinds, one is a switching type (--Nable-xxx or --disable-xxx), the other is an open form, that is, back to fill in a string of characters (--with- XXX = yyyy) parameter. The above code is used in the switch type. The first parameter is the parameter name, the second is the description (the content displayed after "./configure --help"), the last parameter is the default value. Generally speaking, the default value and user prompt should be mutually exclusive, that is, the default value is NO, it should be prompted to modify the user with Enable and vice versa.
As you can see from the code, if you enable_popo is YES, use ac_define to define the POPO macro (Macro), otherwise it will not be defined, we are using the macro used here, be sure to declare in aconfig.h. .
Step 2 Run ACLOCAL to run aclocal in TT directory, will generate aclocal.m4.
The third step is written acconfig.h
The macro (Macro) used in Configure.in should be declared in this file, generally using #undef to declare.
Acconfig.h # undef Popo
Step 4 Run AutoHeader
After running AutoHeader, CONFIG.H.H will be generated according to configure.in, acconfig.h, and system preset acconfig.h.
The fifth step is written Makefile.am
In general, there should be a makefile.am in the top directory and subdirectories.
MakefileAutomake_Options = foreignsubdirs = SRC
The first line is to tell Automake not to detect whether there is files such as Authors, Readmes in the directory.
The second line is to tell Automake to process the subdirectory of the SRC.
SRC / MakefileAutomake_Options = forignbin_programs = tttt_sources = tt.c qq.c qq.h
The first line is the same as before.
The second line is the name of the target execution file.
The third line is to generate all the source programs and header file names required for TT implementation files.
Sixth step running Automake
You can then perform Automake, enter the command line.
Automake -a and
Automake -a SRC / Makefile
Using "Automake -a" or "Automake - ADD-MIUTOMAKE - ADD-MISSING", INSTALL.SH, MKINSTALLDIRS will automatically make up, otherwise it will be wrong, remember!
Step 7 Run AutoConf
Finally, you can execute AutoConf, and will generate the final Configure after completion!
Fourth, compile & test
Compile with defaults:
[root @ chiosoft tt] # ./configurechecking for ... Popo isn't he! Checking for ... [root @ chiosoft tt] # make ... [root @ chiosoft tt ] # SRC / TTHELLO, I am Teacher (23), PLS Tell Me Your Names! my name is qq
In the default, we didn't define the macro POPO, so "Popo isn't Here!" When ./configure is output, only QQ is only reported when running.
Take a look at this:
[root @ chiosoft tt] # ./configure - help ...-- enable and --with options recognized: --enable-popo popo is present [root @ chiosoft tt] # ./configure --enable -popochecking for ... popo is here! checking for ... [root @ chiosoft tt] # make ... [root @ chiosoft tt] # src / tthello, I am Teacher 23), PLS Tell Me Your Names! My name is popo! My name is qqqqq: hey popo, long time no see. You can see "POPO is here!", The execution result is completely different!
In addition, we can also install make install, preset is installed to / usr / local / bin, of course, these can be modified.
5. Generate a release package tarball
Ok, so far, our small software has been tested, it can be released, there are many files under TT, some are what we write, and some are temporary files generated during compile. What do you need to pack it into the release package? ? Of course, you can pick yourself, but make several very convenient features to us with the makefile generated by Automake.
We can use make Dist or make distcheck to generate the corresponding Tarball, where the latter will help us test whether the release package can work properly, so personal recommends using Make Distcheck.
See it? The release package TT-0.1.0.tar.gz has been put on TT, is there aware that the software name and version number used here is the two parameters that am_init_automake in configure.in! Now you can try to decompress it.