5 # This is where you chose which platform to compile for (see 'make links' / './platform')
8 # This is a list of all non-source files that are part of the distribution.
9 AUXFILES := Makefile Readme.txt
11 # Directories belonging to the project
12 PROJDIRS := functions includes internals
13 # All source files of the project
14 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
15 BUILDFILES := $(shell find -L build -type f -name "*.c")
16 # All header files of the project
17 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
18 # All .c files in functions/_PDCLIB that do not have a regression test driver
19 INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
20 # All object files in the library
21 OBJFILES := $(patsubst %.c,%.o,$(BUILDFILES))
22 # All test drivers (.t)
23 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
24 # All regression test drivers (.r)
25 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES)))
26 # All library dependency files (.d)
27 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
28 # All test driver dependency files (_t.d)
29 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
30 # All regression test driver dependency files (_r.d)
31 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
32 # All files belonging to the source distribution
33 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
35 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
36 PLATFORM_FLAGS=-nostdinc -mlittle-endian -mthumb -mcpu=cortex-m3 -ffreestanding -nostdlib
37 CFLAGS := -fno-builtin -Os -g -std=c99 -I./build/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
39 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
43 check: all testdrivers regtestdrivers
45 @echo "========================"
46 @echo "Executing library tests:"
47 @echo "========================"
49 @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
51 @echo "==========================="
52 @echo "Executing regression tests:"
53 @echo "==========================="
55 @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
62 test: functions/$(FILE)
66 -@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
68 testdrivers: $(TSTFILES)
71 regtests: regtestdrivers
72 -@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
74 regtestdrivers: $(REGFILES)
77 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
80 -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) pdclib.a pdclib.tgz scanf_testdata_*)
83 @tar czf pdclib.tgz $(ALLFILES)
86 -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
89 -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
92 @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
95 @echo "Linking platform/$(PLATFORM)..."
96 @for dir in $$(find functions includes internals -type d); do mkdir -p build/$$dir; done
97 @for file in $$(find platform/$(PLATFORM) -mindepth 2 -type f ! -path *.svn* -printf "%P\n"); do if [ ! -f build/$$file ]; then ln -s $$(dirname $$file | sed "s@[^/]*@..@g")/../platform/$(PLATFORM)/$$file build/$$file; fi; done
98 @for super in $(PROJDIRS); do for file in $$(find $$super -type f ! -path *.svn* -printf "%P\n"); do if [ ! -f build/$$super/$$file ]; then ln -s $$(echo $$file | sed "s@[^/]*@..@g")/../$$super/$$file build/$$super/$$file; fi; done; done
101 @echo "Unlinking platform files..."
102 @for dir in $(PROJDIRS); do find build/$$dir -type l -exec rm {} +; done
105 @echo "Available make targets:"
107 @echo "all - build pdclib.a"
108 @echo "clean - remove all object files, dependency files and test drivers"
109 @echo "srcdist - build pdclib.tgz (source tarball)"
110 @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
111 @echo "tests - build and run test drivers (link pdclib.a)"
112 @echo " testdrivers - build but do not run test drivers"
113 @echo "regtests - build and run regression test drivers (link system clib)"
114 @echo " regtestdrivers - build but do not run regression test drivers"
115 @echo "todos - list all TODO comments in the sources"
116 @echo "fixmes - list all FIXME comments in the sources"
117 @echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
118 @echo "links - link platform files (development only)"
119 @echo "unlink - remove links to platform files (development only)"
120 @echo "%.o - build an individual object file"
121 @echo "%.t - build an individual test driver"
122 @echo "%.r - build an individual regression test driver"
123 @echo "help - print this list"
125 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
126 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
129 echo " CC $(patsubst functions/%,%,$@)"
130 $(CC) $(CFLAGS) -MMD -MP -I./build/includes -c $< -o $@
132 %_t: %.c Makefile pdclib.a
133 @echo " CC $(patsubst functions/%,%,$@)"
134 @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./build/includes $< pdclib.a -o $@
137 @echo " CC $(patsubst functions/%,%,$@)"
138 @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@