build: The backends module needs to add -lGP_backends.
[gfxprim.git] / post.mk
blobbafd7fb09e26f914804170931c85ae9dd03b9ef4
2 # Make no subdirs by default
4 ifndef SUBDIRS
5 SUBDIRS=
6 endif
8 .PHONY: $(SUBDIRS) all clean rebuild help
10 all: $(SUBDIRS)
11 clean: $(SUBDIRS)
12 rebuild: $(SUBDIRS)
14 help:
15 @echo "*** Available targets ***"
16 @echo ""
17 @echo "help: prints this help"
18 @echo ""
19 @echo "clean: cleans current directory and all subdirectories"
20 @echo ""
21 @echo "all: make current directory and all subdirectories"
22 @echo ""
23 @echo "rebuild: does clean and all"
24 @echo ""
25 @echo "The default silent output could be turned off by defining"
26 @echo "'VERBOSE' shell variable as 'VERBOSE=1 make'"
27 @echo ""
30 # Determine mode (eg do not generate anything if not in compile mode
32 COMPILE=no
34 ifeq ($(MAKECMDGOALS),all)
35 COMPILE=yes
36 endif
38 ifeq ($(MAKECMDGOALS),)
39 COMPILE=yes
40 endif
42 ifeq ($(MAKECMDGOALS),rebuild)
43 COMPILE=yes
44 endif
47 # 1. Generate and include dependencies for all C sources
48 # 2. Generate OBJECTS list from CSOURCES list
49 # 3. Adds OBJECTS to CLEAN list
51 ifdef CSOURCES
52 DEPFILES=$(subst .c,.dep,$(CSOURCES))
53 ifeq ($(COMPILE),yes)
54 -include $(DEPFILES)
55 endif
56 CLEAN+=$(subst .c,.dep,$(CSOURCES))
57 OBJECTS+=$(CSOURCES:.c=.o)
58 CLEAN+=$(OBJECTS)
59 endif
62 # Automatically include library headers
64 ifdef LIBNAME
65 INCLUDE+=$(LIBNAME)
66 endif
69 # If there was anything in INCLUDE list, create CFLAGS for each entry
71 ifdef INCLUDE
72 CFLAGS+=$(addprefix -I$(TOPDIR)/include/, $(INCLUDE))
73 endif
76 # Walk trought SUBDIRS, this code works even for -jX
78 $(SUBDIRS):
79 ifdef VERBOSE
80 $(MAKE) -C $@ $(MAKECMDGOALS)
81 else
82 @export CURSUBDIR="$$CURSUBDIR/$@" && echo "DIR $$CURSUBDIR" &&\
83 $(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)
84 endif
87 # Actual make rules
89 $(DEPFILES): %.dep: %.c
90 ifdef VERBOSE
91 $(CC) -MM $(CFLAGS) $< -o $@
92 else
93 @echo "DEP -I(include $(INCLUDE)) $@"
94 @$(CC) -MM $(CFLAGS) $< -o $@
95 endif
97 $(OBJECTS): %.o: %.c
98 ifdef VERBOSE
99 $(CC) $(CFLAGS) -c $< -o $@
100 else
101 @echo "CC -I(include $(INCLUDE)) $@"
102 @$(CC) $(CFLAGS) -c $< -o $@
103 endif
105 ifdef CLEAN
106 clean:
107 ifdef VERBOSE
108 rm -f $(CLEAN)
109 else
110 @echo "RM $(CLEAN)"
111 @rm -f $(CLEAN)
112 endif
113 endif
115 compile: $(DEPFILES) $(OBJECTS) $(ALL)
117 rebuild: clean
118 @$(MAKE) --no-print-directory all