7 includedir=$(prefix)/include
10 CPUS=cortex-m0 cortex-m3
15 CC=$(bindir)/arm-none-eabi-gcc
17 # This is where you chose which platform to compile for (see 'make links' / './platform')
20 # This is a list of all non-source files that are part of the distribution.
21 AUXFILES := Makefile Readme.txt
23 # Directories belonging to the project
24 PROJDIRS := functions includes internals
25 # All source files of the project
26 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
27 BUILDFILES := $(shell find -L $(BUILD) -type f -name "*.c")
28 # All header files of the project
29 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
30 BUILDHDRFILES := $(shell find -L $(BUILD) -type f -name "*.h")
31 # All .c files in functions/_PDCLIB that do not have a regression test driver
32 INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
33 # All object files in the library
34 OBJFILES := $(patsubst %.c,%.o,$(BUILDFILES))
35 # All test drivers (.t)
36 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
37 # All regression test drivers (.r)
38 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES)))
39 # All library dependency files (.d)
40 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
41 # All test driver dependency files (_t.d)
42 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
43 # All regression test driver dependency files (_r.d)
44 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
45 # All files belonging to the source distribution
46 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
48 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
49 PLATFORM_FLAGS=-nostdinc -mlittle-endian -mthumb -mcpu=$(CPU) -ffreestanding -nostdlib
50 CFLAGS := -fno-builtin -Os -g -std=c99 -I./$(BUILD)/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
52 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
54 PDCLIB=pdclib-$(CPU).a
57 +for i in $(CPUS); do make CPU=$$i links pdclib-$$i.a; done
60 +for i in $(CPUS); do make CPU=$$i install-lib-$$i; done
63 +make CPU=$(FIRSTCPU) install-hdr-$(FIRSTCPU)
66 +for i in $(CPUS); do make CPU=$$i clean-$$i; rm -rf build-$$i; done
69 check: all testdrivers regtestdrivers
71 @echo "========================"
72 @echo "Executing library tests:"
73 @echo "========================"
75 @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
77 @echo "==========================="
78 @echo "Executing regression tests:"
79 @echo "==========================="
81 @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
83 $(PDCLIB): $(BUILD) $(OBJFILES)
88 install-$(CPU): install-$(CPU)-lib install-hdr
90 install-lib-$(CPU): $(BUILD) $(PDCLIB)
91 install -D -c $(PDCLIB) $(DESTDIR)$(libdir)/$(PDCLIB)
93 install-hdr-$(CPU): $(BUILD) $(BUILDHDRFILES)
94 for file in $(BUILDHDRFILES); do \
95 install -D -c $$file $(DESTDIR)$(includedir)/.; \
98 test: functions/$(FILE)
102 -@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
104 testdrivers: $(TSTFILES)
107 regtests: regtestdrivers
108 -@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
110 regtestdrivers: $(REGFILES)
113 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
115 clean-$(CPU): $(BUILD)
116 -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) $(PDCLIB) pdclib.tgz scanf_testdata_*)
119 @tar czf pdclib.tgz $(ALLFILES)
122 -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
125 -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
128 @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
131 @echo "Linking platform/$(PLATFORM)..."
132 @for dir in $$(find functions includes internals -type d); do mkdir -p $(BUILD)/$$dir; done
133 @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
134 @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
137 @echo "Unlinking platform files..."
138 @for dir in $(PROJDIRS); do find $(BUILD)/$$dir -type l -exec rm {} +; done
141 @echo "Available make targets:"
143 @echo "all - build $(PDCLIB)"
144 @echo "clean - remove all object files, dependency files and test drivers"
145 @echo "srcdist - build pdclib.tgz (source tarball)"
146 @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
147 @echo "tests - build and run test drivers (link $(PDCLIB))"
148 @echo " testdrivers - build but do not run test drivers"
149 @echo "regtests - build and run regression test drivers (link system clib)"
150 @echo " regtestdrivers - build but do not run regression test drivers"
151 @echo "todos - list all TODO comments in the sources"
152 @echo "fixmes - list all FIXME comments in the sources"
153 @echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
154 @echo "links - link platform files (development only)"
155 @echo "unlink - remove links to platform files (development only)"
156 @echo "%.o - build an individual object file"
157 @echo "%.t - build an individual test driver"
158 @echo "%.r - build an individual regression test driver"
159 @echo "help - print this list"
161 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
162 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
165 echo " CC $(patsubst functions/%,%,$@)"
166 $(CC) $(CFLAGS) -MMD -MP -I./$(BUILD)/includes -c $< -o $@
168 %_t: %.c Makefile $(PDCLIB)
169 @echo " CC $(patsubst functions/%,%,$@)"
170 @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./$(BUILD)/includes $< $(PDCLIB) -o $@
173 @echo " CC $(patsubst functions/%,%,$@)"
174 @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@