Makefile的基本结构不是很复杂,但过多的源程序也会使makefile的编写很困难,而且有的应用场景对makefile的格式有要求, 这样自动生成一个公认的makefile就很有必要。 这里默认源码路径文件夹helloworld,源码文件helloworld.c 1、首先使用autoscan命令生成configure.scan文件,下面是文件内容 # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) AC_CONFIG_SRCDIR([helloworld.c]) AC_CONFIG_HEADERS([config.h]) # Checks for programs. AC_PROG_CC # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_OUTPUT 1、 AC_PREREQQ宏声明本文件要求的autoconf版本,这里是2.69 2、 AC_INIT定义软件的名称和信息。(DULL-PACKAGE-NAME为软件名,VERSION为软件的版本号,BUG-REPORT-ADDRESS为bug的报告地址,一般为软件作者的邮箱) 3、 AC_CONFIG_SRCDIR用来侦测指定的源码文件是否存在,确定源码目录的有效性。此处为当前目录下hello.c 4、 AC_CONFIG_HEADER用于生成config.h文件,以便autoheader使用 5、 AC_PROG_CC用来指定编译器,以便不指定的时候默认为gcc 6、 AC_OUTPUT用来设定config要产生的文件。如果是Makefile,config会把它检查出来的结果带入Makefile.in文件产生合适的Makefile. AM_INIT_AUTOMAKE宏需要自己进行添加,它是automake所必备的宏。 2 根据您的文件需要修改该文件并改名为configure.ac,下面是例子 # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT(helloworld, 1.0, 111111@qq.com) AM_INIT_AUTOMAKE(helloworld,1.0) AC_CONFIG_SRCDIR([helloworld.c]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE # Checks for programs. AC_PROG_CC # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_OUTPUT(Makefile) 5.使用aclocal工具生成aclocal.m4 aclocal 6.使用autoconf工具生成configure文件 autoconf 7.使用autoheader工具生成config.h.in文件 autoheader 8.创建Makefile.am文件 Automake工具会根据config.in中的参量把Makefile.am转换成Makefile.in文件。在使用Automake之前,要先手动建立Makefile.am文件。 vi Makefile.am AUTOMAKE_OPTIONS=foreign bin_PROGRAMS=helloworld helloworld_SOURCE=helloworld.c 9.使用Automake生成Makefile.in文件 要使用选项“--add-missing”可以让Automake自动添加一些必要的脚本文件。如下: automake --add-missing 10.配置自己的编译环境 运行自动配置设置文件configure,把Makefile.in编程最终的Makefile (该路径是A40i环境中的路径,请根据做自己环境修改) ./configure CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ AR=arm-linux-gnueabihf-ar RANLIB=arm-linux-gnueabihf-ranlib --host=arm-linux-gnueabihf --build=i686-linux-gnu --target=arm-linux-gnueabihf --enable-shared --disable-ipv6 --with-system-ffi ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no --enable-optimizations --prefix=/home/forlinx/work/lichee/out/sun8iw11p1/linux/common/buildroot/target/ 到这里就成功生成了Makefile |
|小黑屋|
飞凌嵌入式
( 冀ICP备12004394号-1 )
GMT+8, 2025-5-8 12:29
Powered by Discuz! X3.4
© 2001-2013 Comsenz Inc.