Fix .pyc cleanup rule
[gfxprim.git] / include.mk
blob6505a3dda3e23dedb103d717c8f15e83de2a52fd
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 # Potential python dependencies for generated files and scripts
36 # Add .pyc files to CLEAN list
38 PYTHON_FILES=$(shell find "${PYLIBSDIR}" -name *.py)
39 CLEAN+=$(patsubst %.py, %.pyc, ${PYTHON_FILES})
42 # 1. Generate and include dependencies for all C sources
43 # 2. Generate OBJECTS list from CSOURCES list
44 # 3. Adds OBJECTS to CLEAN list
46 ifdef CSOURCES
47 DEPFILES=$(subst .c,.dep,$(CSOURCES))
48 ifeq ($(COMPILE),yes)
49 -include $(DEPFILES)
50 endif
51 CLEAN+=$(subst .c,.dep,$(CSOURCES))
52 OBJECTS=$(CSOURCES:.c=.o)
53 CLEAN+=$(OBJECTS)
54 endif
57 # Automatically include library headers
59 ifdef LIBNAME
60 INCLUDE+=$(LIBNAME)
61 endif
64 # If there was anything in INCLUDE list, create CFLAGS for each entry
66 ifdef INCLUDE
67 CFLAGS+=$(addprefix -I$(TOPDIR)/include/, $(INCLUDE))
68 endif
71 # Walk trought SUBDIRS, this code works even for -jX
73 $(SUBDIRS):
74 ifdef VERBOSE
75 $(MAKE) -C $@ $(MAKECMDGOALS)
76 else
77 @export CURSUBDIR="$$CURSUBDIR/$@" && echo "DIR $$CURSUBDIR" &&\
78 $(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)
79 endif
82 # Actual make rules
84 $(DEPFILES): %.dep: %.c
85 ifdef VERBOSE
86 $(CC) -MM $(CFLAGS) $< -o $@
87 else
88 @echo "DEP -I(include $(INCLUDE)) $@"
89 @$(CC) -MM $(CFLAGS) $< -o $@
90 endif
92 $(OBJECTS): %.o: %.c
93 ifdef VERBOSE
94 $(CC) $(CFLAGS) -c $< -o $@
95 else
96 @echo "CC -I(include $(INCLUDE)) $@"
97 @$(CC) $(CFLAGS) -c $< -o $@
98 endif
100 ifdef CLEAN
101 clean:
102 ifdef VERBOSE
103 rm -f $(CLEAN)
104 else
105 @echo "RM $(CLEAN)"
106 @rm -f $(CLEAN)
107 endif
108 endif