Working through the Openismus’s example code for Automake (Part 2)
I’ve been working on dissecting so sample code from the Openismus site for Automake.
I was searching through code search to post a link here and I noticed that they had basic sample projects for creating and installing libraries. I’m still focused on reviewing the basic Automake, perhaps this will be a topic for another day.
Based on what I’ve learned from the most excellent EPITA – LRD tutorial, the main files, from which everything else sprouts are the configure.ac and makefile.am’s that occur in the project.
So… In the previous post I tore apart the configure.ac (which had deprecated features in it).
Today, I want to look at the makefile.am’s in the project:helloworld_cc-0.3.tar.gz
The sample project download on my machine and look like this:
jonas@Ubuntu4:~/helloworld_cc-0.3$ ls -1 -R
.:
aclocal.m4
AUTHORS
autogen.sh
ChangeLog
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
configure.ac
COPYING
depcomp
INSTALL
install-sh
libtool
ltmain.sh
Makefile
Makefile.am
Makefile.in
missing
mkinstalldirs
NEWS
README
src
stamp-h1
./src:
foofiles
hello
hello.cc
hello.h
hello.o
main.cc
main.o
Makefile
Makefile.am
Makefile.in./src/foofiles:
foo.cc
foo.h
foo.o
libfoo.a
Makefile
Makefile.am
Makefile.in
jonas@Ubuntu4:~/helloworld_cc-0.3$
There are 3 Makefile.am’s files to look at.
I was looking at these files:
I think that before I dive into this, I need to do a little basic research on what all this Makefile stuff is all about for context… I found some interesting stuff here which I need to digest.
On the most excellent EPITA – LRD tutorial, Automake starts around page 295.
Btw,, Openismus discusses the non self-explanatory macros pretty well as far as what’s going on..
The LRD tutorial talks (~311)about the FHS , This wiki link describes it pretty well.
I think I may have bit a few do many data sources in one bite here. This is somewhat overwhelming to someone who grew up in the Ms-dos world…. Yikes…..
Ok… Time to break this down into little itty bitty pieces so this goes down easier.
Makefile.am
SUBDIRS = src EXTRA_DIST=autogen.sh
Page 332 of the LRD tutorial discuss SUBDIRS
Points made:
- One Makefile ergo, one Makefile.am per directory
- You run make from the top directory
- It figures out where to go by navigate through the directories called out in SUBDIRS in the individual make files.
- All the Makefiles are declared in configure.ac
So the contents of configure.ac are;
AC_INIT(src/hello.cc) AM_INIT_AUTOMAKE(helloworld_cc,0.3) AM_CONFIG_HEADER(config.h) AC_PROG_CC AC_PROG_CXX AC_PROG_INSTALL AC_PROG_LIBTOOL AC_OUTPUT(Makefile src/Makefile src/foofiles/Makefile)
Wow that was scary. It makes perfect sense.
Lets see what I can find as far as that deal with the EXTRA_DIST:
Page 359 in the tutorial says, EXTRA_DIST comes into play in the creation of tarballs. It’s used for adding extra files above and beyond what is normally done in the process.
While reading the linked wiki page about tarballs there was some discussion about tarbombs. This is something I’m going to need to research in the furture, when I get to the point of having some applications I wish to distribute.
./src/Makefile.am
bin_PROGRAMS = hello
hello_SOURCES = hello.h hello.cc main.cc
SUBDIRS = foofiles
LDADD = foofiles/libfoo.a
The first three lines make sense to me, So that leaves LDADD. Basically has to do with letting up libraries. Page 427 of the tutorial EPITA – LRD tutorial, discusses that… Back in a few minutes….
Ok… this LDADD is still a bit fuzzy for me, gut here’s what I got out of the tutorial. LDADD is the command that you use when linking up a library. LDADD by itself without a lower case prefix is the global form.
According to the tutorial you’ll see the library name with a “la” suffix when you’re using a full library. not the “a” we have here… When Automake runs across the “la” will figure out whether it should has a .so or .dll extension depending on your os. The “.a” is a convenience used when building the library (I hope I read that right).
Ok.. (page 438) apparently to use a library you need to cover your bases so to speak in three spots: configure.ac (AC_PROG_LIBTOOL), Makefile.am (LDADD ) where you want to link, Makefile.am(LTLIBRARIES) what your linking.. Lets see
configure.ac
AC_INIT(src/hello.cc)
AM_INIT_AUTOMAKE(helloworld_cc,0.3)
AM_CONFIG_HEADER(config.h)
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_LIBTOOLAC_OUTPUT(Makefile src/Makefile src/foofiles/Makefile)
./src/Makefile.am
bin_PROGRAMS = hello
hello_SOURCES = hello.h hello.cc main.cc
SUBDIRS = foofilesLDADD = foofiles/libfoo.a
./src/foofiles/Makefile.am
noinst_LIBRARIES = libfoo.a
libfoo_a_SOURCES = foo.h foo.cc
INCLUDE = -I@top_srcdir@/
#$% I was hoping for a match between the tutorial and the code… There is a difference in that the tutorial refers to “LTLIBRARY” and the code has plain “LIBRARY” So I’m not sure is LT is used with .la extensions only or If “LIBRARY” is something deprecated… The tutorial really seems to like LTLIBRARY… Off to GNU land…
Ok… I’m still confused..
I found some reference http://ftp.gnu.org/old-gnu/Manuals/automake-1.6.1/html_chapter/automake_9.html#SEC30
Doesn’t say anything about deprecation but having old_gnu in the hyperlink doesn’t make me feel any better.
Ok…. Back to my favorite tutorial.. It looks like talks about _LIBRARIES and _LTLIBRARIES (Libtool libraries) Off to wikipedia
I’m not seeing this explicitely stated, but It sound like LTLIBRARIES invokes the big guns of libtool cross platform support, and plain old LIBRARIES doesn’t…. My head is starting to ache So I’m moving on to ./src/foofiles/Makefile.am
./src/foofiles/Makefile.am
noinst_LIBRARIES = libfoo.a
libfoo_a_SOURCES = foo.h foo.cc
INCLUDE = -I@top_srcdir@/
So here’s a link that describes whats going on with noinst_LIBRARIES
That link and couple of buzzword terms that I’ve seen and never bothered to understand.
Now it sort of makes sense why libfoo.a turns gets referenced as libfoo_a in the next line..
So…. that leaves “INCLUDE = -I@top_srcdir@/”
So… I found that top_srcdir is a makefile variable. I need think I know what’s going on here but not well enough to explain. I need to find a line that explains the use of @’s and $’s.
I found a link that sort explains the “@” aka the strudel. Basically here’s the pertinent code:
3.4 How derived variables are named
Sometimes a Makefile variable name is derived from some text the maintainer supplies. For instance, a program name listed in ‘_PROGRAMS’ is rewritten into the name of a ‘_SOURCES’ variable. In cases like this, Automake canonicalizes the text, so that program names and the like do not have to follow Makefile variable naming rules. All characters in the name except for letters, numbers, the strudel (@), and the underscore are turned into underscores when making variable references.
For example, if your program is named sniff-glue, the derived variable name would be ‘sniff_glue_SOURCES’, not ‘sniff-glue_SOURCES’. Similarly the sources for a library named libmumble++.a should be listed in the ‘libmumble___a_SOURCES’ variable.
The strudel is an addition, to make the use of Autoconf substitutions in variable names less obfuscating.
I need to move on too somthing else….
