]> git.itanic.dy.fi Git - sdl-planets/blob - Makefile
Makefile: More advanced dependency tracking
[sdl-planets] / Makefile
1 SDL_CONFIG=$(shell sdl-config --cflags)
2 SDL_LIBS=$(shell sdl-config --libs)
3 CFLAGS=$(SDL_CONFIG) -Wall -O2 -g
4
5 LIBS=$(SDL_LIBS) -lm -lrt
6
7 CC=gcc
8 SPARSE=sparse
9 CHECKPATCH=/usr/src/linux/scripts/checkpatch.pl
10
11 PLANET_OBJS=main.o random.o vector.o planet.o camera.o quadtree.o
12 PLANET_DEBUG_OBJS= $(patsubst %.o,%-debug.o,$(PLANET_OBJS))
13 ALL_OBJS = $(PLANET_OBJS) $(PLANET_DEBUG_OBJS)
14 ALL_DEBS = $(patsubst %.o,.%.o.d,$(ALL_OBJS))
15
16 sdl-planet: $(PLANET_OBJS)
17         gcc $(LIBS) -o $@ $(PLANET_OBJS)
18
19 debug-planet: $(PLANET_DEBUG_OBJS)
20         gcc $(LIBS) -o $@ $(PLANET_DEBUG_OBJS) -DDEBUG
21
22 .c.o:
23         @echo -e "\tCC\t" $@
24         @$(CC) -MMD -MF .$@.d $(CFLAGS) -c $< -o $@
25         @cp .$@.d .$@.P; \
26             sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
27                 -e '/^$$/ d' -e 's/$$/ :/' < .$@.d >> .$@.P; \
28             mv .$@.P .$@.d
29
30 ifeq ($(C),1)
31         sparse $(CFLAGS) $<
32 endif
33 ifeq ($(C),2)
34         $(CHECKPATCH) -f $<
35 endif
36
37 %-debug.o: %.c
38         @echo -e "\tCC\t" $@
39         @$(CC) -MMD -MF .$@.d $(CFLAGS) -DDEBUG -O0 -c $< -o $@
40         @cp .$@.d .$@.P; \
41             sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
42                 -e '/^$$/ d' -e 's/$$/ :/' < .$@.d >> .$@.P; \
43             mv .$@.P .$@.d
44
45 TAGS:
46         @echo -e "\tTAGS\t"
47         @etags *.[ch]
48
49 clean:
50         rm -rfv $(ALL_OBJS) *~ sdl-planet TAGS $(ALL_DEBS) \
51                 debug-planet
52
53 .PHONY: all clean TAGS
54
55 -include $(ALL_DEBS)