4 prefix=/home/keithp/sat
6 includedir=$(prefix)/include
10 # This is where you chose which platform to compile for (see 'make links' / './platform')
13 # This is a list of all non-source files that are part of the distribution.
14 AUXFILES := Makefile Readme.txt
16 # Directories belonging to the project
17 PROJDIRS := functions includes internals
18 # All source files of the project
19 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
20 BUILDFILES := $(shell find -L build -type f -name "*.c")
21 # All header files of the project
22 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
23 BUILDHDRFILES := $(shell find -L build -type f -name "*.h")
24 # All .c files in functions/_PDCLIB that do not have a regression test driver
25 INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
26 # All object files in the library
27 OBJFILES := $(patsubst %.c,%.o,$(BUILDFILES))
28 # All test drivers (.t)
29 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
30 # All regression test drivers (.r)
31 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES)))
32 # All library dependency files (.d)
33 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
34 # All test driver dependency files (_t.d)
35 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
36 # All regression test driver dependency files (_r.d)
37 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
38 # All files belonging to the source distribution
39 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
41 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
42 PLATFORM_FLAGS=-nostdinc -mlittle-endian -mthumb -mcpu=cortex-m3 -ffreestanding -nostdlib
43 CFLAGS := -fno-builtin -Os -g -std=c99 -I./build/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
45 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
49 check: all testdrivers regtestdrivers
51 @echo "========================"
52 @echo "Executing library tests:"
53 @echo "========================"
55 @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
57 @echo "==========================="
58 @echo "Executing regression tests:"
59 @echo "==========================="
61 @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
68 install: install-lib install-hdr
71 install -D -c pdclib.a $(DESTDIR)$(libdir)/pdclib.a
73 install-hdr: $(BUILDHDRFILES)
74 for file in $(BUILDHDRFILES); do \
75 install -D -c $$file $(DESTDIR)$(includedir)/.; \
78 test: functions/$(FILE)
82 -@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
84 testdrivers: $(TSTFILES)
87 regtests: regtestdrivers
88 -@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
90 regtestdrivers: $(REGFILES)
93 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
96 -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) pdclib.a pdclib.tgz scanf_testdata_*)
99 @tar czf pdclib.tgz $(ALLFILES)
102 -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
105 -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
108 @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
111 @echo "Linking platform/$(PLATFORM)..."
112 @for dir in $$(find functions includes internals -type d); do mkdir -p build/$$dir; done
113 @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
114 @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
117 @echo "Unlinking platform files..."
118 @for dir in $(PROJDIRS); do find build/$$dir -type l -exec rm {} +; done
121 @echo "Available make targets:"
123 @echo "all - build pdclib.a"
124 @echo "clean - remove all object files, dependency files and test drivers"
125 @echo "srcdist - build pdclib.tgz (source tarball)"
126 @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
127 @echo "tests - build and run test drivers (link pdclib.a)"
128 @echo " testdrivers - build but do not run test drivers"
129 @echo "regtests - build and run regression test drivers (link system clib)"
130 @echo " regtestdrivers - build but do not run regression test drivers"
131 @echo "todos - list all TODO comments in the sources"
132 @echo "fixmes - list all FIXME comments in the sources"
133 @echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
134 @echo "links - link platform files (development only)"
135 @echo "unlink - remove links to platform files (development only)"
136 @echo "%.o - build an individual object file"
137 @echo "%.t - build an individual test driver"
138 @echo "%.r - build an individual regression test driver"
139 @echo "help - print this list"
141 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
142 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
145 echo " CC $(patsubst functions/%,%,$@)"
146 $(CC) $(CFLAGS) -MMD -MP -I./build/includes -c $< -o $@
148 %_t: %.c Makefile pdclib.a
149 @echo " CC $(patsubst functions/%,%,$@)"
150 @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./build/includes $< pdclib.a -o $@
153 @echo " CC $(patsubst functions/%,%,$@)"
154 @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@