Merge branch 'master' of git://repo.or.cz/gfxprim
[gfxprim.git] / include.mk
blob68fab644cccbfdda24e18ce3cba735c5e392f5ef
1 .PHONY: $(SUBDIRS) all clean help
3 all: $(SUBDIRS)
4 clean: $(SUBDIRS)
6 help:
7 @echo "*** Available targets ***"
8 @echo ""
9 @echo "help: prints this help"
10 @echo ""
11 @echo "clean: cleans current directory and all subdirectories"
12 @echo ""
13 @echo "all: make current directory and all subdirectories"
14 @echo ""
15 @echo "The default silent output could be turned off by defining"
16 @echo "'VERBOSE' shell variable as 'VERBOSE=1 make'"
17 @echo ""
19 include $(TOPDIR)/config.mk
22 # Determine mode (eg do not generate anything if not in compile mode
24 COMPILE=no
26 ifeq ($(MAKECMDGOALS),all)
27 COMPILE=yes
28 endif
30 ifeq ($(MAKECMDGOALS),)
31 COMPILE=yes
32 endif
35 # 1. Generate and include dependencies for all C sources
36 # 2. Generate OBJECTS list from CSOURCES list
37 # 3. Adds OBJECTS to CLEAN list
39 ifdef CSOURCES
40 DEPFILES=$(subst .c,.dep,$(CSOURCES))
41 ifeq ($(COMPILE),yes)
42 -include $(DEPFILES)
43 endif
44 CLEAN+=$(subst .c,.dep,$(CSOURCES))
45 OBJECTS=$(CSOURCES:.c=.o)
46 CLEAN+=$(OBJECTS)
47 endif
50 # Automatically include library headers
52 ifdef LIBNAME
53 INCLUDE+=$(LIBNAME)
54 endif
57 # If there was anything in INCLUDE list, create CFLAGS for each entry
59 ifdef INCLUDE
60 CFLAGS+=$(addprefix -I$(TOPDIR)/include/, $(INCLUDE))
61 endif
64 # Walk trought SUBDIRS, this code works even for -jX
66 $(SUBDIRS):
67 ifdef VERBOSE
68 $(MAKE) -C $@ $(MAKECMDGOALS)
69 else
70 @export CURSUBDIR="$$CURSUBDIR/$@" && echo "DIR $$CURSUBDIR" &&\
71 $(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)
72 endif
75 # Actual make rules
77 $(DEPFILES): %.dep: %.c
78 ifdef VERBOSE
79 $(CC) -MM $(CFLAGS) $< -o $@
80 else
81 @echo "DEP -I(include $(INCLUDE)) $@"
82 @$(CC) -MM $(CFLAGS) $< -o $@
83 endif
85 $(OBJECTS): %.o: %.c
86 ifdef VERBOSE
87 $(CC) $(CFLAGS) -c $< -o $@
88 else
89 @echo "CC -I(include $(INCLUDE)) $@"
90 @$(CC) $(CFLAGS) -c $< -o $@
91 endif
93 ifdef CLEAN
94 clean:
95 ifdef VERBOSE
96 rm -f $(CLEAN)
97 else
98 @echo "RM $(CLEAN)"
99 @rm -f $(CLEAN)
100 endif
101 endif