Generate Makefile new version.
2016-03-15 12:12
274 查看
2.4 A Small Hello World
In this section we recreate the amhello-1.0 package fromscratch. The first subsection shows how to call the Autotools toinstantiate the GNU Build System, while the second explains themeaning of theconfigure.ac and Makefile.am files readby the Autotools.
• Creating amhello: | Create amhello-1.0.tar.gz from scratch | |
• amhello's configure.ac Setup Explained: | ||
• amhello's Makefile.am Setup Explained: |
amhello's configure.ac Setup Explained, Up:
Hello World [Contents][Index]
2.4.1 Creating amhello-1.0.tar.gz
Here is how we can recreate amhello-1.0.tar.gz from scratch.The package is simple enough so that we will only need to write 5files. (You may copy them from the finalamhello-1.0.tar.gzthat is distributed with Automake if you do not want to write them.)
Create the following files in an empty directory.
src/main.c is the source file for the hello program. Westore it in the
src/ subdirectory, because later, when the packageevolves, it will ease the addition of a
man/ directory for manpages, a data/ directory for data files, etc.
~/amhello % cat src/main.c #include <config.h> #include <stdio.h> int main (void) { puts ("Hello World!"); puts ("This is " PACKAGE_STRING "."); return 0; }
README contains some very limited documentation for our littlepackage.
~/amhello % cat README This is a demonstration package for GNU Automake. Type 'info Automake' to read the Automake manual.
Makefile.am and src/Makefile.am contain Automakeinstructions for these two directories.
~/amhello % cat src/Makefile.am bin_PROGRAMS = hello hello_SOURCES = main.c ~/amhello % cat Makefile.am SUBDIRS = src dist_doc_DATA = README
Finally, configure.ac contains Autoconf instructions tocreate the
configurescript.
~/amhello % cat configure.ac AC_INIT([amhello], [1.0], [bug-automake@gnu.org]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([ Makefile src/Makefile ]) AC_OUTPUT
Once you have these five files, it is time to run the Autotools toinstantiate the build system. Do this using the
autoreconfcommand as follows:
~/amhello % autoreconf --install configure.ac: installing './install-sh' configure.ac: installing './missing' configure.ac: installing './compile' src/Makefile.am: installing './depcomp'
At this point the build system is complete.
In addition to the three scripts mentioned in its output, you can seethat
autoreconfcreated four other files: configure,config.h.in,
Makefile.in, and src/Makefile.in.The latter three files are templates that will be adapted to thesystem by
configureunder the names config.h,Makefile, and
src/Makefile. Let’s do this:
~/amhello % ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... no checking for mawk... mawk 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: creating src/Makefile config.status: creating config.h config.status: executing depfiles commands
You can see Makefile, src/Makefile, and config.hbeing created at the end after
configurehas probed thesystem. It is now possible to run all the targets we wish(see
Standard Targets). For instance:
~/amhello % make … ~/amhello % src/hello Hello World! This is amhello 1.0. ~/amhello % make distcheck … ============================================= amhello-1.0 archives ready for distribution: amhello-1.0.tar.gz =============================================
Note that running
autoreconfis only needed initially whenthe GNU Build System does not exist. When you later change someinstructions in a
Makefile.am or configure.ac, therelevant part of the build system will be regenerated automaticallywhen you execute
make.
相关文章推荐
- oracle——SQL复习03
- java 同步机制
- HDU-1205(吃糖果)
- ubuntu技巧--python查看已安装包
- 数据结构课设 求前缀表达式的值
- 初学Redis(3)——用Redis作为Mysql数据库的缓存
- 初学Redis(4)——简单实现Redis缓存中的排序功能
- android不一样的listView的empty
- Github注册过程
- 整合struts2+hibernate详细配置步骤及注意事项
- CuteFTP文件列表按名称排序,有中文文件名时,软件死掉的解决办法
- 关于三栏布局中浮动布局div块的先后顺序
- Swift 数组,字典
- apt-get安装总是失败
- 初学 Java Web 开发,请远离各种框架,从 Servlet 开发
- unix网络编程 select函数和shutdown函数
- 认识Redis
- 初学Redis(2)——用Redis作为Mysql数据库的缓存
- ORACLE绑定变量隐式转换导致性能问题
- 一篇高引用的综述文章是如何写成的