use autotools to make project

1.1.  Write sources

  1. Create an empty directory called tut_prog and enter in it.
  2. In this new directory, create a new file named main.c containing:
Example 3-1 main.c:
#include <stdio.h> 
	
int main()
{
	printf("Hello world!/n");
	return 0;
}

1.2.  Run Autoconf

  1. Write the following in a file named configure.ac :
Example 3-2 minimal configure.ac:
AC_INIT([Tutorial Program], 1.0)
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_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 extension is already used by files processed by configure and generated by Automake : Makefile.in and autoheader : config.h.in .

AC_INIT, AM_INIT_AUTOMAKE, etc... are M4 macros. M4 is a macro expanding software used by Autotools ; we don't need to know about it. When Autoconf will process this 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 indicate the 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 of using the additional macro AC_CONFIG_FILES.

Autoconf only knows its own macros but read additional ones in a file named aclocal.m4 . These macros are used to extend Autoconf , it includes Automake macro (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_FOO macro so that developers using your library can check for its presence using Autoconf .

aclocal scans configure.ac and create an aclocal.m4 file which contains the macros mentioned in configure.ac . aclocal is part of the Automake package and search by default in Automake macros and in a system path typically /usr/share/aclocal .

  1. Launch aclocal . It will create a new file named aclocal.m4 in the current directory.
  2. Launch autoconf . It will create the configure script configure .

On my system, I actually get an extra directory called autom4te.cache . That is for Autoconf internal purposes. You do not need to care about it.

1.3.  Run Automake

  1. Write the following in a file named Makefile.am :
Example 3-3 minimal Makefile.am:
bin_PROGRAMS = tut_prog			
tut_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 how that 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 which will be replaced when the configure script will run, resulting in a real makefile (called Makefile). For instance, configure will write in the final Makefile what compiler to use (it is the compiler it found using the AC_PROG_CC macro).

  1. Run the command automake --add-missing --foreign . It will create a new file named Makefile.in as expected. Moreover, due to the switch --add-missing you get a few links 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 you don't need mandatory documentation files: INSTALL , NEWS , README , AUTHORS , ChangeLog and COPYING . I have used it here to keep the number of created file to a minimum but else it is a good idea to provide these files, you can start with empty files.

1.4.  Build project

  1. Run now the new configure script: ./configure . You get the following output and it create the makefile for your program.

    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: executing depfiles commands
    
  2. Run now make , to build your program. You get the following output 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.c
    main.c: In function ‘main’:
    main.c:5: warning: return type of ‘main’ is not ‘int’
    mv -f .deps/main.Tpo .deps/main.Po
    gcc  -g -O2   -o tut_prog main.o
    
  3. Now, if you can write in /usr/local/bin , run make install to install your program. Else you need to log 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 run your program from everywhere.

1.5.  Clean project

  1. The program is installed, so you can clean the build directory running make clean . It removes all object files and the program but not the makefiles.

    test -z "tut_prog" || rm -f tut_prog
    rm -f *.o
    

    You can still run the program installed in /user/local/bin .

  2. To remove the installed program, run make uninstall . Like for the installation, you need to use have the writing right in the directory 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 to understand exactly what's happen. But, for a real work, it's a bit tedious especially because there are other tools those could be needed like autoheader , autopoint or libtoolize . After creating the project, the makefiles generated by configure should take care of regenerating configure and all Makefile.in . Anyway, this lets a room for improvement and there are even two responses to this:

autoreconf

It is another tool part of the Autoconf package which is running all scripts in the right order. To start a new project, you can just run autoreconf --install and it will call all necessary commands.

autogen.sh

It is a script not part of Autotools , that it doing the same thing. There is one named gnome-autogen.sh which comes with GNOME common development package but other project can write their own ones.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
城市应急指挥系统是智慧城市建设的重要组成部分,旨在提高城市对突发事件的预防和处置能力。系统背景源于自然灾害和事故灾难频发,如汶川地震和日本大地震等,这些事件造成了巨大的人员伤亡和财产损失。随着城市化进程的加快,应急信息化建设面临信息资源分散、管理标准不统一等问题,需要通过统筹管理和技术创新来解决。 系统的设计思路是通过先进的技术手段,如物联网、射频识别、卫星定位等,构建一个具有强大信息感知和通信能力的网络和平台。这将促进不同部门和层次之间的信息共享、交流和整合,提高城市资源的利用效率,满足城市对各种信息的获取和使用需求。在“十二五”期间,应急信息化工作将依托这些技术,实现动态监控、风险管理、预警以及统一指挥调度。 应急指挥系统的建设目标是实现快速有效的应对各种突发事件,保障人民生命财产安全,减少社会危害和经济损失。系统将包括预测预警、模拟演练、辅助决策、态势分析等功能,以及应急值守、预案管理、GIS应用等基本应用。此外,还包括支撑平台的建设,如接警中心、视频会议、统一通信等基础设施。 系统的实施将涉及到应急网络建设、应急指挥、视频监控、卫星通信等多个方面。通过高度集成的系统,建立统一的信息接收和处理平台,实现多渠道接入和融合指挥调度。此外,还包括应急指挥中心基础平台建设、固定和移动应急指挥通信系统建设,以及应急队伍建设,确保能够迅速响应并有效处置各类突发事件。 项目的意义在于,它不仅是提升灾害监测预报水平和预警能力的重要科技支撑,也是实现预防和减轻重大灾害和事故损失的关键。通过实施城市应急指挥系统,可以加强社会管理和公共服务,构建和谐社会,为打造平安城市提供坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值