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.

资源下载链接为: https://pan.quark.cn/s/9e7ef05254f8 在苹果的生态系统中,IAP(应用内购买)是苹果应用商店(App Store)中应用开发者常采用的一种盈利模式,允许用户在应用内直接购买虚拟商品或服务。苹果为开发者提供了一份详细的人民币(CNY)IAP定价表,这份定价表具有以下特点: 价格分级:定价表由多个价格等级组成,开发者可根据虚拟商品的价值选择相应等级,等级越高,价格越高。例如,低等级可能对应基础功能解锁,高等级则对应高级服务或大量虚拟道具。 税收与分成:苹果会从应用内购买金额中抽取30%作为服务费或佣金,这是苹果生态的固定规则。不过,开发者实际到手的收入会因不同国家和地区的税收政策而有所变化,但定价表中的价格等级本身是固定的,便于开发者统一管理。 多级定价策略:通过设置不同价格等级,开发者可以根据商品或服务的类型与价值进行合理定价,以满足不同消费能力的用户需求,从而最大化应用的总收入。例如,一款游戏可以通过设置不同等级的虚拟货币包,吸引不同付费意愿的玩家。 特殊等级:除了标准等级外,定价表还包含备用等级和特殊等级(如备用等级A、备用等级B等),这些等级可能是为应对特殊情况或促销活动而设置的额外价格点,为开发者提供了更灵活的定价选择。 苹果IAP定价表是开发者设计应用内购机制的重要参考。它不仅为开发者提供了标准的收入分成模型,还允许开发者根据产品特性设定价格等级,以适应市场和满足不同用户需求。同时,开发者在使用定价表时,还需严格遵守苹果的《App Store审查指南》,包括30%的分成政策、使用苹果支付接口、提供清晰的产品描述和定价信息等。苹果对应用内交易有严格规定,以确保交易的透明性和安全性。总之,苹果IAP定价表是开发者在应用内购设计中不可或缺的工具,但开发者也需密切关注苹果政策变化,以确保应用的合规运营和收益最大化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值