Professional Documents
Culture Documents
Auto Tools
Auto Tools
Hardware differences
Endian-ness Word size Executable file names Device file names File name conventions Compiler name & arguments Header file names & definitions Keywords
OS differences
Compiler differences
`configure` is created from configure.ac (using `autoconf`) configure.ac can be created automatically (using `autoscan`)
Creating `configure`:
1) Prepare sources and the Makefile.in 2) Run `autoscan` 3) Rename configure.scan to configure.ac 4) Run `autoconf` 5) ./configure 6) make
Still to consider:
1) Creating Makefile.in using Automake 2) Creating config.h.in 3) Using config.h to make our program portable
What is configure.ac?
#*Autoconf* #Processthisfilewithautoconftoproduceaconfigurescript. AC_PREREQ(2.59) AC_INIT(FULLPACKAGENAME,VERSION,BUGREPORTADDRESS) AC_CONFIG_SRCDIR([hello.c]) AC_CONFIG_HEADER([config.h]) #Checksforprograms. AC_PROG_CC #Checksforlibraries. #Checksforheaderfiles. #Checksfortypedefs,structures,andcompilercharacteristics. #Checksforlibraryfunctions. AC_CONFIG_FILES([Makefile]) AC_OUTPUT
What is configure?
#!/bin/sh #GuessvaluesforsystemdependentvariablesandcreateMakefiles. #GeneratedbyGNUAutoconf2.59forFULLPACKAGENAMEVERSION. # #Reportbugsto<BUGREPORTADDRESS>. # #Copyright(C)2003FreeSoftwareFoundation,Inc. #Thisconfigurescriptisfreesoftware;theFreeSoftwareFoundation #givesunlimitedpermissiontocopy,distributeandmodifyit. #### ##M4shInitialization.## #### #BeBournecompatible iftestn"${ZSH_VERSION+set}"&&(emulatesh)>/dev/null2>&1;then emulatesh NULLCMD=: #Zsh3.xand4.xperformswordsplittingon${1+"$@"},which #iscontrarytoourusage.Disablethisfeature. aliasg'${1+"$@"}'='"$@"' eliftestn"${BASH_VERSION+set}"&&(setoposix)>/dev/null2>&1;then setoposix fi DUALCASE=1;exportDUALCASE#forMKSsh
Portability problem!
gettimeofday() is not available on all systems!
GETTIMEOFDAY(2)LinuxProgrammersManualGETTIMEOFDAY(2) NAME gettimeofday,settimeofdayget/settime SYNOPSIS .............................................................................. CONFORMINGTO SVr4,BSD4.3.POSIX1003.12001describesgettimeofday()butnotset timeofday(). SEEALSO
Better Solution
Generating config.h
config.h is created by `configure` from config.h.in config.h.in is created by `autoheader` from the C sources and headers.
Sample session
$ls epoch.cMakefile $autoscan $ls autoscan.logconfigure.scanepoch.cMakefile $mvconfigure.scanconfigure.ac $ls autoscan.logconfigure.acepoch.cMakefile $autoheader $ls autom4te.cache/config.h.inepoch.c autoscan.logconfigure.acMakefile $mvMakefileMakefile.in $autoconf $ls autom4te.cache/config.h.inconfigure.acMakefile.in autoscan.log configure*epoch.c $./configure checkingforgcc...gcc checkingforCcompilerdefaultoutputfilename..a.out checkingwhethertheCcompilerworks...yes checkingwhetherwearecrosscompiling...no checkingforsuffixofexecutables... checkingforsuffixofobjectfiles...o checkingwhetherweareusingtheGNUCcompiler...yes checkingwhethergccacceptsg...yes checkingforgccoptiontoacceptANSIC...noneneeded checkinghowtoruntheCpreprocessor...gccE checkingforegrep...grepE checkingforANSICheaderfiles...yes checkingforsys/types.h...yes checkingforsys/stat.h...yes checkingforstdlib.h...yes checkingforstring.h...yes checkingformemory.h...yes checkingforstrings.h...yes checkingforinttypes.h...yes checkingforstdint.h...yes checkingforunistd.h...yes checkingsys/time.husability...yes checkingsys/time.hpresence...yes checkingforsys/time.h...yes checkingwhethertime.handsys/time.hmaybothbe included...yes checkingforgettimeofday...yes configure:creating./config.status config.status:creatingMakefile config.status:creatingconfig.h $ls autom4te.cache/config.h.inconfigure*Makefile autoscan.logconfig.logconfigure.acMakefile.in config.hconfig.status*epoch.c $make ccsO2Wallepoch.coepoch $ls autom4te.cache/config.h.inconfigure*epoch.c autoscan.logconfig.logconfigure.acMakefile config.hconfig.status*epoch*Makefile.in $./epoch 1077873582.855393 $
What is config.h?
/*config.h.Generatedbyconfigure.*/ /*config.h.in.Generatedfromconfigure.acbyautoheader.*/ /*Defineto1ifyouhavethe`gettimeofday'function.*/ #defineHAVE_GETTIMEOFDAY1 /*Defineto1ifyouhavethe<inttypes.h>headerfile.*/ #defineHAVE_INTTYPES_H1 /*Defineto1ifyouhavethe<memory.h>headerfile.*/ #defineHAVE_MEMORY_H1 /*Defineto1ifyouhavethe<stdint.h>headerfile.*/ #defineHAVE_STDINT_H1 /*Defineto1ifyouhavethe<stdlib.h>headerfile.*/ #defineHAVE_STDLIB_H1 /*Defineto1ifyouhavethe<strings.h>headerfile.*/ #defineHAVE_STRINGS_H1 /*Defineto1ifyouhavethe<string.h>headerfile.*/ #defineHAVE_STRING_H1 /*Defineto1ifyouhavethe<sys/stat.h>headerfile.*/ #defineHAVE_SYS_STAT_H1 /*Defineto1ifyouhavethe<sys/time.h>headerfile.*/ #defineHAVE_SYS_TIME_H1 /*Defineto1ifyouhavethe<sys/types.h>headerfile.*/ #defineHAVE_SYS_TYPES_H1 /*Defineto1ifyouhavethe<unistd.h>headerfile.*/ #defineHAVE_UNISTD_H1 /*Definetotheaddresswherebugreportsforthispackage shouldbesent.*/ #definePACKAGE_BUGREPORT"BUGREPORTADDRESS" /*Definetothefullnameofthispackage.*/ #definePACKAGE_NAME"FULLPACKAGENAME" /*Definetothefullnameandversionofthispackage.*/ #definePACKAGE_STRING"FULLPACKAGENAMEVERSION" /*Definetotheonesymbolshortnameofthispackage.*/ #definePACKAGE_TARNAME"fullpackagename" /*Definetotheversionofthispackage.*/ #definePACKAGE_VERSION"VERSION" /*Defineto1ifyouhavetheANSICheaderfiles.*/ #defineSTDC_HEADERS1 /*Defineto1ifyoucansafelyincludeboth<sys/time.h>and <time.h>.*/ #defineTIME_WITH_SYS_TIME1
autoscan Rename configure.scan to configure.ac autoheader Rename Makefile to Makefile.in autoconf ./configure make
What is Makefile.am?
#Makefile.amforepoch.c bin_PROGRAMS=epoch epoch_SOURCES=epoch.c
What is AM_INIT_AUTOMAKE?
File:automake1.7.info,Node:Complete,Next:Hello,Prev:Examples,Up:E\ Asimpleexample,starttofinish ================================= Let'ssupposeyoujustfinishedwriting`zardoz',aprogramtomake yourheadfloatfromvortextovortex.You'vebeenusingAutoconfto provideaportabilityframework,butyour`Makefile.in'shavebeen adhoc.Youwanttomakethembulletproof,soyouturntoAutomake. Thefirststepistoupdateyour`configure.in'toincludethe commandsthat`automake'needs.Thewaytodothisistoaddan `AM_INIT_AUTOMAKE'calljustafter`AC_INIT': AC_INIT(zardoz,1.0) AM_INIT_AUTOMAKE ... Sinceyourprogramdoesn'thaveanycomplicatingfactors(e.g.,it doesn'tuse`gettext',itdoesn'twanttobuildasharedlibrary), you'redonewiththispart.Thatwaseasy! zzInfo:(automake1.7.info.gz)Complete,52linesTop
Editing configure.ac
#*Autoconf* #Processthisfilewithautoconftoproduceaconfigurescript. AC_PREREQ(2.59) AC_INIT(FULLPACKAGENAME,VERSION,BUGREPORTADDRESS) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([epoch.c]) AC_CONFIG_HEADER([config.h]) #Checksforprograms. AC_PROG_CC #Checksforlibraries. #Checksforheaderfiles. AC_CHECK_HEADERS([sys/time.h]) #Checksfortypedefs,structures,andcompilercharacteristics. AC_HEADER_TIME #Checksforlibraryfunctions. AC_CHECK_FUNCS([gettimeofday]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT
What is Makefile.in?
#Makefile.ingeneratedbyautomake1.7.9fromMakefile.am. #@configure_input@ #Copyright1994,1995,1996,1997,1998,1999,2000,2001,2002,2003 #FreeSoftwareFoundation,Inc. #ThisMakefile.inisfreesoftware;theFreeSoftwareFoundation #givesunlimitedpermissiontocopyand/ordistributeit, #withorwithoutmodifications,aslongasthisnoticeispreserved. #Thisprogramisdistributedinthehopethatitwillbeuseful, #butWITHOUTANYWARRANTY,totheextentpermittedbylaw;without #eventheimpliedwarrantyofMERCHANTABILITYorFITNESSFORA #PARTICULARPURPOSE. @SET_MAKE@ srcdir=@srcdir@ top_srcdir=@top_srcdir@ VPATH=@srcdir@ pkgdatadir=$(datadir)/@PACKAGE@ pkglibdir=$(libdir)/@PACKAGE@ pkgincludedir=$(includedir)/@PACKAGE@ top_builddir=. am__cd=CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)"&&cd INSTALL=@INSTALL@ install_sh_DATA=$(install_sh)cm644 install_sh_PROGRAM=$(install_sh)c install_sh_SCRIPT=$(install_sh)c
./configure
$ls aclocal.m4config.h.inCOPYINGINSTALLMakefile.in autom4te.cache/configure*depcomp*installsh*missing* autoscan.logconfigure.acepoch.cMakefile.ammkinstalldirs* $./configure checkingforaBSDcompatibleinstall.../usr/bin/installc checkingwhetherbuildenvironmentissane...yes checkingforgawk...gawk checkingwhethermakesets$(MAKE)...yes checkingforgcc...gcc ... checkingsys/time.husability...yes checkingsys/time.hpresence...yes checkingforsys/time.h...yes checkingwhethertime.handsys/time.hmaybothbeincluded...yes checkingforgettimeofday...yes configure:creating./config.status config.status:creatingMakefile config.status:creatingconfig.h config.status:executingdepfilescommands $ls aclocal.m4config.h.inconfigure.acINSTALLMakefile.in autom4te.cache/config.logCOPYINGinstallsh*missing* autoscan.logconfig.status*depcomp*Makefilemkinstalldirs* config.hconfigure*epoch.cMakefile.amstamph1 $
srcdir=. top_srcdir=. pkgdatadir=$(datadir)/fullpackagename pkglibdir=$(libdir)/fullpackagename pkgincludedir=$(includedir)/fullpackagename top_builddir=. am__cd=CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)"&&cd INSTALL=/usr/bin/installc install_sh_DATA=$(install_sh)cm644 install_sh_PROGRAM=$(install_sh)c install_sh_SCRIPT=$(install_sh)c
Update configure.ac
3) Run `autoreconf`
Things to know...
Autoconf/Automake doesn't make a program portable YOU DO! Your program evolves to be more portable. You can add or write your own tests in m4. (Place them in acinclude.m4)
Resources
http://sources.redhat.com/autobook/
http://www.gnu.org/software/ac-archive/
http://www.cbreak.org/