Voici un beau Makefile (celui de vobcopy que j'ai modifié pour mes besoins, et un peu aussi pour "exempler") ; le makefile est en fin de post.
Ce Makefile utilise la variable CC pour désigner le compilateur à utiliser :
ligne 4 : CC ?= gcc
ce qui signifie : par défaut, j'utilise gcc si on ne spécifie pas "extérieurement" de valeur à CC
Par défaut, je le lance comme çà :
$ make
Je ne veux pas utiliser gcc mais gcc32.
Je fais :
$ export CC=gcc32
CC aura cette fois-ci pour valeur gcc32, puisqu'on vient de lui en donner une.
On pourrait faire aussi (sans export) :
$ make CC=gcc32
CC n'est qu'une variable qui sert à indiquer aux Makefile/configure le compilateur qu'ils doivent utiliser ; elle n'influe en rien sur le compilateur appelé directement par gcc :
$ export CC=gcc32 && gcc -v
gcc 4.1 ...
$ gcc32 -v
gcc 3.2 ...
Le Makefile d'exemple :
#This is the makefile for vobcopy, mainly written by rosenauer. These things
#below here are variable definitions. They get substituted in the (CC) and
#stuff places.
CC ?= gcc
#PREFIX += /usr/local
#BINDIR = ${PREFIX}/bin
#MANDIR = ${PREFIX}/man
PREFIX ?= /usr/local
BINDIR ?= ${PREFIX}/bin
MANDIR ?= ${PREFIX}/man
LFS = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
LDFLAGS += -ldvdread
#This specifies the conversion from .c to .o
.c.o:
$(CC) $(LFS) $(CFLAGS) -c $<
#Here is implicitly said that for vobcopy to be made *.o has to be made first
#make is kinda intelligent in that aspect.
vobcopy: vobcopy.o dvd.o
$(CC) -o vobcopy vobcopy.o dvd.o ${LDFLAGS}
disable_lfs:
$(CC) $(CFLAGS) -c vobcopy.c
$(CC) $(CFLAGS) -c dvd.c
$(CC) -o vobcopy vobcopy.o dvd.o -ldvdread
debug:
$(CC) -c vobcopy.c -Wall -ggdb -pedantic $(CFLAGS) $(LFS)
$(CC) -c dvd.c -Wall -ggdb -pedantic $(CFLAGS) $(LFS)
$(CC) -o vobcopy vobcopy.o dvd.o -ldvdread
deb:
echo "this here is really really experimental..."
dpkg-buildpackage -rfakeroot -us -uc -tc
clean :
rm -f vobcopy vobcopy.o dvd.o
distclean :
rm -f vobcopy.o dvd.o *~
install:
# mkdir -p $(MANDIR)/man1
# cp vobcopy $(BINDIR)/vobcopy
# cp vobcopy.1 $(MANDIR)/man1/vobcopy.1
install -d -m 755 $(BINDIR)
install -d -m 755 $(MANDIR)/man1
install -d -m 755 $(MANDIR)/de/man1
install -m 755 vobcopy $(BINDIR)/vobcopy
install -m 644 vobcopy.1 $(MANDIR)/man1/vobcopy.1
install -m 644 vobcopy.1.de $(MANDIR)/de/man1/vobcopy.1
uninstall:
rm -f $(BINDIR)/vobcopy
rm -f $(MANDIR)/man1/vobcopy.1
rm -f $(MANDIR)/de/man1/vobcopy.1