1 # This is a list of all non-source files that are part of the distribution.
2 AUXFILES := Makefile Readme.txt
4 # Directories belonging to the project
5 PROJDIRS := functions includes internals platform/example
6 # All source files of the project
7 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
8 # All header files of the project
9 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
10 # All object files in the library
11 OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
12 # All test drivers (.t)
13 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
14 # All regression test drivers (.r)
15 REGFILES := $(patsubst %.c,%_r,$(SRCFILES))
16 # All library dependency files (.d)
17 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
18 # All test driver dependency files (_t.d)
19 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
20 # All regression test driver dependency files (_r.d)
21 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
22 # All files belonging to the source distribution
23 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
25 WARNINGS := -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wuninitialized -Wstrict-prototypes
26 CFLAGS := -fno-builtin -g -std=c99 -I./internals -I./testing -I./platform/example/include -I./platform/example/internals $(WARNINGS) $(USERFLAGS)
28 .PHONY: all clean srcdist tests testdrivers regtests regtestdrivers todos fixmes help
30 all: pdclib.a testdrivers regtestdrivers
32 @echo "========================"
33 @echo "Executing library tests:"
34 @echo "========================"
36 @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
38 @echo "==========================="
39 @echo "Executing regression tests:"
40 @echo "==========================="
42 @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
63 -@rc=0; count=0; failed=""; for file in $(TSTFILES); do echo " TST $$file"; ./$$file; test=$$?; if [ $$test != 0 ]; then rc=`expr $$rc + $$test`; failed="$$failed $$file"; fi; count=`expr $$count + 1`; done; echo; echo "Tests executed (linking PDCLib): $$count Tests failed: $$rc"; echo; for file in $$failed; do echo "Failed: $$file"; done; echo
65 testdrivers: $(TSTFILES)
68 regtests: regtestdrivers
69 -@rc=0; count=0; failed=""; for file in $(REGFILES); do echo " RTST $$file"; ./$$file; test=$$?; if [ $$test != 0 ]; then rc=`expr $$rc + $$test`; failed="$$failed $$file"; fi; count=`expr $$count + 1`; done; echo; echo "Tests executed (linking system libc): $$count Tests failed: $$rc"; echo; for file in $$failed; do echo "Failed: $$file"; done; echo
71 regtestdrivers: $(REGFILES)
74 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
77 -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) pdclib.a pdclib.tgz scanf_testdata_*)
80 @tar czf pdclib.tgz $(ALLFILES)
83 -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
86 -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
89 @echo "Available make targets:"
91 @echo "all - build pdclib.a"
92 @echo "clean - remove all object files, dependency files and test drivers"
93 @echo "srcdist - build pdclib.tgz (source tarball)"
94 @echo "tests - build and run test drivers (link pdclib.a)"
95 @echo " testdrivers - build but do not run test drivers"
96 @echo "regtests - build and run regression test drivers (link system clib)"
97 @echo " regtestdrivers - build but do not run regression test drivers"
98 @echo "todos - list all TODO comments in the sources"
99 @echo "fixmes - list all FIXME comments in the sources"
100 @echo "%.o - build an individual object file"
101 @echo "%.t - build an individual test driver"
102 @echo "%.r - build an individual regression test driver"
103 @echo "help - print this list"
105 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
106 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
109 @echo " CC $(patsubst functions/%,%,$@)"
110 @$(CC) $(CFLAGS) -MMD -MP -I./includes -c $< -o $@
112 %_t: %.c Makefile pdclib.a
113 @echo " CC $(patsubst functions/%,%,$@)"
114 @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./includes $< pdclib.a -o $@
117 @echo " CC $(patsubst functions/%,%,$@)"
118 @$(CC) $(CFLAGS) -Wno-deprecated-declarations -Wno-format -MMD -MP -DTEST -DREGTEST $< -o $@