use autotools to make project
来源:互联网 发布:做小受的真实经历知乎 编辑:程序博客网 时间:2024/06/08 06:12
1.1. Write sources
- Create an empty directory called tut_prog and enter in it.
- In this new directory, create a new file named main.c containing:
#include <stdio.h> int main(){printf("Hello world!/n");return 0;}
1.2. Run Autoconf
- Write the following in a file named configure.ac:
AC_INIT([Tutorial Program], 1.0)AM_INIT_AUTOMAKEAC_PROG_CCAC_CONFIG_FILES(Makefile)AC_OUTPUT
The configure template script could be named configure.in.It is the name used in older version (before 2001) of Autoconf.Nevertheless, it is recommended to use configure.ac because the .in extensionis already used by files processed by configure andgenerated by Automake: Makefile.in and autoheader:config.h.in.
AC_INIT, AM_INIT_AUTOMAKE, etc... are M4 macros. M4 is a macro expanding softwareused by Autotools; we don't need to know about it. When Autoconf will processthis configure.in, the macros will be expanded and we will get a fresh huge configure script.
- AC_INIT
Is the first mandatory macro. We need to indicatethe name of the project and its version.
- AM_INIT_AUTOMAKE
Initialize environment for Automake.It is needed in all projects using Automake.
- AC_PROG_CC
Determine the C compiler to use.
- AC_CONFIG_FILES
Create each file by copying the corresponding template file (with .in extension)and substituting the output variable values.
- AC_OUTPUT
Marks the end of the configure template.
The use of some macros has changed between different versions of Autoconf:
- The package name and version was defined as arguments of AM_INIT_AUTOMAKE instead of AC_INIT.
- AC_OUTPUT was getting the list of generated files instead ofusing the additional macro AC_CONFIG_FILES.
Autoconf only knows its own macros but read additionalones in a file named aclocal.m4. These macros are used toextend Autoconf, it includes Automakemacro (starting with AM_) and other third party macros.For instance, if you develop a library called foo, you might want to write an AC_CHECK_FOR_FOOmacro so that developers using your library can check for its presence usingAutoconf.
aclocal scans configure.ac and create an aclocal.m4 file which contains the macros mentionedin configure.ac.aclocal is part of the Automakepackage and search by default in Automake macros andin a system path typically /usr/share/aclocal.
- Launch aclocal. It will create a new file namedaclocal.m4 in the current directory.
- Launch autoconf. It will create the configurescript configure.
On my system, I actually get an extra directory called autom4te.cache.That is for Autoconf internal purposes. You do not needto care about it.
1.3. Run Automake
- Write the following in a file named Makefile.am:
bin_PROGRAMS = tut_progtut_prog_SOURCES = main.c
In Makefile.am are the very essential data needed to build the project:the target program, called tut_prog, will be put in a $prefix/bin/ directory;to build it we need main.c. Note that we don't specify howthat will be built: Automake will figure it out.We haven't even mentioned the compiler in this pre-makefile.
Makefile.am will be processed by Automake;the result will be a Makefile.in.This Makefile.in is close to being a real makefile, but it contains variable names whichwill be replaced when the configure script will run, resulting in a real makefile(called Makefile). For instance, configure will write in thefinal Makefile what compilerto use (it is the compiler it found using the AC_PROG_CC macro).
- Run the command automake --add-missing --foreign. It will createa new file named Makefile.in as expected. Moreover, due to theswitch --add-missing you get a fewlinks to scripts necessary for building the project: depcomp, install.sh and missing.The other option --foreign tells to Automake that you don't want to follow GNU standard and youdon't need mandatory documentation files: INSTALL,NEWS, README, AUTHORS,ChangeLog and COPYING. I have used it hereto keep the number of created file to a minimum but else it is a good idea toprovide these files, you can start with empty files.
1.4. Build project
Run now the new configure script: ./configure. You getthe following output and it create the makefile for your program.
checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for a thread-safe mkdir -p... /bin/mkdir -pchecking for gawk... gawkchecking whether make sets $(MAKE)... yeschecking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables... checking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for style of include used by make... GNUchecking dependency style of gcc... gcc3configure: creating ./config.statusconfig.status: creating Makefileconfig.status: executing depfiles commands
Run now make, to build your program. You get the followingoutput and a new tut_prog executable
gcc -DPACKAGE_NAME=/"Tutorial/ Program/" -DPACKAGE_TARNAME=/"tutorial-program/" / -DPACKAGE_VERSION=/"1.0/" -DPACKAGE_STRING=/"Tutorial/ Program/ 1.0/" / -DPACKAGE_BUGREPORT=/"/" -DPACKAGE=/"tutorial-program/" -DVERSION=/"1.0/" / -I. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cmain.c: In function ‘main’:main.c:5: warning: return type of ‘main’ is not ‘int’mv -f .deps/main.Tpo .deps/main.Pogcc -g -O2 -o tut_prog main.o
Now, if you can write in /usr/local/bin, runmake install to install your program. Else you need tolog as root before or use sudo and run sudo make install.You should get.
make[1]: Entering directory `/home/seb/Projects/Tutorial'test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin" /usr/bin/install -c 'tut_prog' '/usr/local/bin/tut_prog'make[1]: Nothing to be done for `install-data-am'.make[1]: Leaving directory `/home/seb/Projects/Tutorial'
Then, if /user/local/bin is in your path, you can runyour program from everywhere.
1.5. Clean project
The program is installed, so you can clean the build directory runningmake clean. It removes all object files and theprogram but not the makefiles.
test -z "tut_prog" || rm -f tut_progrm -f *.o
You can still run the program installed in /user/local/bin.
To remove the installed program, run make uninstall.Like for the installation, you need to use have the writing right in thedirectory or use su or sudo.
rm -f '/usr/local/bin/tut_prog'
1.6. Generate project
Running aclocal, automake and autoconf one by one is fine for a tutorial tounderstand exactly what's happen. But, for a real work, it's a bit tediousespecially because there are other tools those could be needed likeautoheader, autopoint or libtoolize. After creating the project, themakefiles generated by configure should takecare of regenerating configure and allMakefile.in. Anyway, this lets a room for improvementand there are even two responses to this:
- autoreconf
It is another tool part of the Autoconf packagewhich is running all scripts in the right order. To start a new project, youcan just run autoreconf --install and it will callall necessary commands.
- autogen.sh
It is a script not part of Autotools, that it doingthe same thing. There is one named gnome-autogen.sh whichcomes with GNOME common development package but other project can write theirown ones.
- use autotools to make project
- Use Autotools to Produce Makefile
- some problem use html5 to make game
- use Emakefile to compile erlang project
- Use Maven3 to create JavaWeb Project
- How to use Log4net in your project
- How to use ppt to make an effective presentation
- springBoot: How to use RestTemplate to make an HttpRequest
- NDoc: How to Make Good Use of Your XML Comments?
- NDoc: How to Make Good Use of Your XML Comments?
- NDoc: How to Make Good Use of Your XML Comments?
- Regular Expression in C# - How to make use of Expresso
- c# how to make app use a specified configure file
- how to make Completion Handlers and use it in Swift
- Use python to make a table frame template instance
- Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly
- Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly
- Effective C++ 18. Make interfaces easy to use correctly and hard to use incorrectly
- VS2008利用宏添加注释模板
- java中使用泛型类型的好处
- C#编程实现访问系统文件夹的代码
- Visual Studio2008使用搜索
- 求助
- use autotools to make project
- POJ 1837
- js导出Excel弹出对话框
- hudson sonar插件升级后终于可以用中文TODO了
- ASP.NET MVC3 概览 一
- eclipse发布报错显示
- WPF Development: Frequently Used Types
- ASP.NET性能提升秘诀之管道与进程优化
- 要在技术和学术上有所成就,现在很多青年人最需要解决的其实不是知识问题,而是心理上的问题,是对“成功”定义的理解。