首页 > 编程知识 正文

automake教程,升级automake版本

时间:2023-05-05 09:45:35 阅读:49349 作者:1500

iwroteacharminglittleutilityforlinuxcalled

getkey,thatcapturesthekeystrokesanddisplaysthemonthescreenusingosd.itscalledgekeyandhasacoupleof.cfilesandahandcraftedmatedmam

butiwantedtousetheauto-tools (autoconfandautomake ) tocreateaconfigurescriptandamakefilesothatmyutilitycouldbyinstallledlike

./configure make make install

wheniwenthuntingforautotoolstutorials,theyweretooelementary (basedonahello.c,with no dependency check ) or too long,1000 p代理

myprogramhasacoupleofdependencies (xosd,Xtst,X11 ) anditissmallenoughtounderstand.soidecidedtousethisprogramtowriteaquiquited

thesearethestepsifollowedtoachievethatandherearethefilesthati ' llbeusingforthisexample。

getkey_example.tar.gz

要求工具:

makesurethefollowingtoolsareavailableonthesystem,before getting started。

tar

化妆

宏基

autoconf

自动跟踪

thistutorialisbasedonautoconfver 2.63。

Setup:

nordertogeneratetheconfigurescriptandthemakefiles,weneedtodefineasetofrulesanddependencies.thisisdoneviatwofiles '

configure.ac' and '

Makefile.am '。

generatingtheconfigurescript :

1.leavethedefaultmakefileintheprojectfolderandrun '

autoscan'. It will create a vanilla

configure.scan文件。

2.nowmovethemakefiletoadifferentplace (soit doesn ' tinterferewiththeautogeneratedfilesinfuture )。

mv Makefile ./。

3. Rename

configure.scan to

configure.AC (thisusedtobeconfigure.inforoldversions,it is deprecated now )。

4 .编辑

configure.acandmodifytheselines。

WAS:

AC _ init ([全包名称]、[版本]、[错误报告-地址] )。

IS:

AC_init([Getkey]、[0.1]、[电子邮件-地址] )。

WAS:

# fix me :更换` main ' withafunctionin `-lx11 ' :

交流_检查跳的前辈([X11],[main] )。

# fix me :更换` main ' withafunctionin `-LX tst ' :

AC_CHECK跳跃的前辈([Xtst]

, [main])

# FIXME: Replace `main' with a function in `-lxosd':

AC_CHECK跳跃的学姐([xosd], [main]) Chose one function from each of the libraries used in the program and replace '

main' with the function name. Any one function is enough to verify a library.

IS:

AC_CHECK跳跃的学姐([X11], 任性的篮球, [],生动的酒窝/p>

echo "X11 library is required for this program"

exit -1])

AC_CHECK跳跃的学姐([Xtst], 寂寞的饼干, [],生动的酒窝/p>

echo "Xtst devel library is missing. Xtst is required for this program"

exit -1])

AC_CHECK跳跃的学姐([xosd], [xosd_create], [],生动的酒窝/p>

echo "xosd devel library is missing. xosd is required for this program"

exit -1])

SYNTAX:

AC_CHECK跳跃的学姐([libname],[func-name],[action-if-found],[action-if-not-found]) The line breaks are essential in the fourth parameter to the function AC_CHECK跳跃的学姐(). This is to make sure that configure script will exit when it can't find a dependency.

5. In configure.ac check for the line that has AC_CONFIG_FILES(). This tells the autoconf tool what are the output files. It should typically be

AC_CONFIG_FILES([Makefile])

6. Run autoconf.

autoconf

This will create the first version of configure script.

Generating the Makefile:

1. Add this line to the

configure.ac

AM_INIT_AUTOMAKE([getkey], [0.1]) This instructs automake to generate makefiles after the configure script is run.

This will also define two constants PACKAGE(=getkey) and VERSION(=0.1) during make. This can be used in the code to display version specific print outs.

If you don't have a config.h file for configuration, then comment out the line: (I didn't use this in getkey)

AC_CONFIG_HEADERS([config.h])

2. Create a file named Makefile.am and add these lines.

AUTOMAKE_OPTIONS = foreign

bin_PROGRAMS = getkey

getkey_SOURCES = getkey.c circ_list.c

The first line

AUTOMAKE_OPTIONS = foreign is to let automake know that it is not a standard GNU package.

A standard GNU package requires certain folders and files to be present, such as doc, src, INSTALL, COPYING, etc.

The CFLAGS and LDFLAGS is copied from the current Makefile that we moved to a different location.

bin_PROGRAMS = getkey is the name of the resulting executable.

getkey_SOURCES = getkey.c circ_list.c, this is the list of sources that will compile to result in getkey. List all the source files here.

If you have more than one resulting executable you can do

bin_PROGRAMS = prog1 prog2 prog3

bin_PROGRAMS = getkey

getkey_SOURCES = getkey.c circ_list.c 3. For our grand finale we run these commands

aclocal

autoconf

automake -a

aclocal is a tools that generates aclocal.m4 based on the configure.ac file which is used as an input to the autoconf tool.

autoconf will generate the configure script and

automake takes Makefile.am as input and creates Makefile.in.

Now we have the final version of our configure script.

Ready to go:

1. Test out the configure script and the Makefile.

./configure

make

2. Create a package. Now that everything is working as expected, we can create a package for distribution.

make dist

This will create a tar.gz file with the package name and version number. Now it is ready for release to the world. Here you go

getkey-0.1.tar.gz.

References:

http://sourceware.org/autobook/autobook/autobook_toc.html#SEC_Contents

http://www.amath.washington.edu/~lf/tutorials/autoconf/toolsmanual_toc.html

http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。