Professional Documents
Culture Documents
Motivation
Build process
–To build/install software
–Driven by make/ANT/…
Configuration process
–To control build process
–Driven by configure/configuration files/…
Mozilla Build Level
1,350 Makefiles
40,000 LOC build instructions
16,000 LOC configuration
Cyclic dependencies
Two-phase build process
Centralized build/configuration knowledge
Code duplication
Component implementations scattered
Motivation – continued
Problems:
main.o sum.o
tab
dependency action
Equivalent makefiles
main.o: sum.h
gcc –c main.c
sum.o: sum.h
gcc –c sum.c
Equivalent makefiles - continued
Operations performed:
gcc –c main.c
gcc –o sum main.o sum.o
main.o should be recompiled (main.c is
newer).
Consequently, main.o is newer than sum and
therefore sum should be recreated (by re-
linking).
Another makefile example
# Makefile to compare sorting routines
BASE = /home/blufox/base
CC = gcc
CFLAGS = -O –Wall
EFILE = $(BASE)/bin/compare_sorts
INCLS = -I$(LOC)/include
LIBS = $(LOC)/lib/g_lib.a \
$(LOC)/lib/h_lib.a
LOC = /usr/local
$(EFILE): $(OBJS)
@echo “linking …”
@$(CC) $(CFLAGS) –o $@ $(OBJS) $(LIBS)
$(OBJS): compare_sorts.h
$(CC) $(CFLAGS) $(INCLS) –c $*.c
else
sum.o: sum2.c sum.h
gcc –c sum2.c –o $@
endif
Make: Advanced Options
Text manipulation functions
– $(patsubst pattern,replacement,text)
– $(patsubst %.o,%.cc,<list of objfiles>)
Pattern rules
– Uses a pattern in the target with % as wildcard
– Matched % can be used in dependencies as well
– Simple Example:
%.o : %.cc
<tab>command …
Pattern rules with automatic variables
– $@ full target name
– $< first dependency
– $* string which matched % wildcard
– Advance Example:
%.o : %.cc
<tab>$(CC) $(CCFLAGS) –c $< $(INCPATHS)
Make: A Simple Example
CC=g++ # Compiler to use
FLAGS=-g # Compile flags
MASLAB_ROOT=maslab-software # Maslab software root directory
LIB_DIR=$(MASLAB_ROOT)/liborc # orc-related library directory
INC_DIR=$(MASLAB_ROOT)/liborc # orc-related include directory
LIBS=-lm –lpthread -lorc # Library files
all : helloworld
helloworld.o : helloworld.cc
$(CC) $(FLAGS) –c $*.cc –o $@
helloworld: helloworld.o
$(CC) -o helloworld helloworld.o $(LIBS)
clean:
rm -f *.o helloworld
Make: Example Makefile
MASLABROOT = /mnt/maslab/software/maslab-software-current
# This rule builds everything. You should put the names of all your
# programs in this list.
all : robotest
# This rule says how to turn any .cpp file into a .o file.
%.o : %.$(CCEXT)
$(CC) $(CCFLAGS) -c $< $(INCPATHS)
#----------------------------------------------------------------------
# robotest
PROGRAM_NAME = robotest
PROGRAM_OBJS = robotest.o BumpSensor.o Robot.o
GLOBAL_OBJS += $(PROGRAM_OBJS)
JUNK += $(PROGRAM_NAME)
$(PROGRAM_NAME): $(PROGRAM_OBJS)
$(CC) $(PROGRAM_OBJS) -o $(PROGRAM_NAME) $(LIBS) $(LIBPATHS)
chmod a+x $(PROGRAM_NAME)
Extending Example Makefile
So to add a new executable program, simply cut and
paste the robotest section and enter your own
PROGRAM_NAME and PROGRAM_OBJS
#----------------------------------------------------------------------
# Sensor Incremental Test
PROGRAM_NAME = sensor-test
PROGRAM_OBJS = sensor.t.o BumpSensor.o
GLOBAL_OBJS += $(PROGRAM_OBJS)
JUNK += $(PROGRAM_NAME)
$(PROGRAM_NAME): $(PROGRAM_OBJS)
$(CC) $(PROGRAM_OBJS) -o $(PROGRAM_NAME) $(LIBS) $(LIBPATHS)
chmod a+x $(PROGRAM_NAME)
Extending example Makefile
DEPENDS += $(patsubst %.o, %.d, $(GLOBAL_OBJS))
JUNK += $(DEPENDS)
include $(DEPENDS)
depend : $(DEPENDS)
%.d: %.$(CCEXT)
$(depend.cc) $< | $(depend.filt)
#======================================================================
# Miscellaneous Rules
#----------------------------------------------------------------------
# This rule cleans your directory. You could also add commands here
# to remove program files and any other files that should be cleaned
clean:
rm -f $(JUNK) *~ *.o core.[0-9]* core
ANT:
Another Nice Tool
What is Ant?
Java-based Build tool from Apache
De facto standard for building, packaging, and
installing Java applications
Accomplishes same objectives that make does on
Unix based systems
Files are written in XML
Why Ant?
Many claim.. That
– Unlike makefiles, Ant files work cross platform
- No need for multiple, complex makefiles
depending on the operating system.
- Tasks declared in platform independent way; Ant
engine translates to OS specific commands.
But still need to know (potentially) complex
path/install data. So not as general as they claim
Easy to create own Ant “tasks”, in addition to core
tasks
Installing Ant
Download Ant binary distribution from:
http://ant.apache.org/bindownload.cgi
Set ANT_HOME to where you installed Ant
Include $ANT_HOME/bin in PATH
Make sure JAVA_HOME is set to point to JDK
Running Ant
Type “ant” at the command line
Automatically looks for build.xml file in current
directory to run
Type “ant –buildfile buildfile.xml” to specify
another build file to run.
Ant Output
Sample build.xml
<project name="MyProject" default="dist" basedir=".">
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
</target>
firefox-1.0.tar.gz
autoscan autoconf
configure.scan configure
GNU automake
Makefile.am Makefile.in
automake configure
Makefile
configure.ac
dnl Comment … …
AC_INIT(main.c)
AM_INIT_AUTOMAKE(project_name, 1.2.8)
AC_OUTPUT([Makefile])
Makefile.am
bin_PROGRAMS = foo
/configure --prefix=… (default /usr/local)
foo_PROGRAMS=foo.c foo.h
noist_PROGRAMS=test
(make compiles, make install does nothing)
EXTRA_DIST=disclaimer.txt
Example
foo.c :
#include <stdio.h>
main()
{
printf(“Cum grano salis\n");
}
Makefile.am :
bin_PROGRAMS = foo
foo_SOURCES = foo.c
configure.ac :
AC_INIT(foo.c)
AM_INIT_AUTOMAKE(latin_words, 0.9)
AC_PROG_CC
AC_HEADER_STDC
AC_PROG_INSTALL
AC_OUTPUT([Makefile])
Summary
Source Code, configure.ac, Makefile.am
autoscan; aclocal; autoconf
Create NEWS README AUTHORS ChangeLog
automake –add-missing
./configure; make; make dist
Result: project_name-2.10.tar.gz
aclocal.m4 autom4te-2.53.cache ChangeLog config.status
configure.in COPYING install-sh Makefile.am missing NEWS
README AUTHORS autoscan.log config.log configure
configure.scan INSTALL Makefile.in mkinstalldirs code.c
References
GNU Autoconf, Automake, and Libtool
http://sources.redhat.com/autobook/autobook/autobook_toc.html