39 Make
39 Make
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
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)
# @command suppresses the echoing of the command
$(OBJS): compare_sorts.h
$(CC) $(CFLAGS) $(INCLS) –c $*.c
all : helloworld
helloworld.o : helloworld.cc
$(CC) $(FLAGS) –c $*.cc –o $@ -I$(INC_DIR)
# note –I gcc option
helloworld: helloworld.o
$(CC) -o helloworld helloworld.o $(LIBS) –L$(LIB_DIR)
# note –L gcc option
clean:
rm -f *.o helloworld
The real Problem
How do we handle platform specific issues?
– Providing a different Makefile for each architecture
– Using Autoconf, Automake and Libtool
autoscan autoconf
configure.scan configure
GNU automake
Makefile.am Makefile.in
automake configure
Makefile
configure.ac
dnl Comment … …
AC_INIT(project_name, 1.2.8)
AM_INIT_AUTOMAKE
AC_OUTPUT
Makefile.am
bin_PROGRAMS = foo
foo_SOURCES=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