9 includedir=$(prefix)/include
12 CPUS=cortex-m0 cortex-m3
17 #CC=$(bindir)/arm-none-eabi-gcc
18 CC=/usr/bin/arm-none-eabi-gcc
20 # This is where you chose which platform to compile for (see 'make links' / './platform')
23 # This is a list of all non-source files that are part of the distribution.
24 AUXFILES := Makefile Readme.txt
26 # Directories belonging to the project
27 PROJDIRS := functions includes internals
28 # All source files of the project
29 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
30 BUILDFILES := $(shell find -L $(BUILD) -type f -name "*.c")
31 # All header files of the project
32 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
33 BUILDHDRFILES := $(shell find -L $(BUILD) -type f -name "*.h")
34 # All .c files in functions/_PDCLIB that do not have a regression test driver
35 INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
36 # All object files in the library
37 OBJFILES := $(patsubst %.c,%.o,$(BUILDFILES))
38 # All test drivers (.t)
39 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
40 # All regression test drivers (.r)
41 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES)))
42 # All library dependency files (.d)
43 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
44 # All test driver dependency files (_t.d)
45 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
46 # All regression test driver dependency files (_r.d)
47 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
48 # All files belonging to the source distribution
49 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
51 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
52 PLATFORM_FLAGS=-mlittle-endian -mthumb -mcpu=$(CPU) -ffreestanding
53 CFLAGS := -Os -g -std=c99 -I./$(BUILD)/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
55 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
58 PDCLIB=$(PDCLIBNAME)-$(CPU).a
61 +for i in $(CPUS); do make CPU=$$i links; make CPU=$$i $(PDCLIBNAME)-$$i.a; done
64 @echo '######' install
65 +for i in $(CPUS); do make CPU=$$i prefix=$(prefix) install-lib-$$i; done
68 @echo '######' install-hdr
69 +make CPU=$(FIRSTCPU) prefix=$(prefix) install-hdr-$(FIRSTCPU)
72 +for i in $(CPUS); do make CPU=$$i clean-$$i; rm -rf build-$$i; done
74 check: all testdrivers regtestdrivers
76 @echo "========================"
77 @echo "Executing library tests:"
78 @echo "========================"
80 @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
82 @echo "==========================="
83 @echo "Executing regression tests:"
84 @echo "==========================="
86 @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
88 $(PDCLIB): $(BUILD) $(OBJFILES)
93 install-$(CPU): install-$(CPU)-lib install-hdr
94 @echo '######' install-$(CPU)
96 install-lib-$(CPU): $(PDCLIB)
97 @echo '######' install-lib-$(CPU)
98 install -D -c $(PDCLIB) $(DESTDIR)$(libdir)/$(PDCLIB)
100 install-hdr-$(CPU): $(BUILD) $(BUILDHDRFILES)
101 @echo '######' install-hdr-$(CPU)
102 for file in $(BUILDHDRFILES); do \
103 install -m 0444 -D -c $$file $(DESTDIR)$(includedir)/.; \
106 test: functions/$(FILE)
110 -@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
112 testdrivers: $(TSTFILES)
115 regtests: regtestdrivers
116 -@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
118 regtestdrivers: $(REGFILES)
121 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
123 clean-$(CPU): $(BUILD)
124 -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) $(PDCLIB) pdclib.tgz scanf_testdata_*)
127 @tar czf pdclib.tgz $(ALLFILES)
130 -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
133 -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
136 @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
139 @echo "Linking platform/$(PLATFORM)..."
140 @for dir in $$(find functions includes internals -type d); do mkdir -p $(BUILD)/$$dir; done
141 @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
142 @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
143 if [ -f platform/$(PLATFORM)/include-exclude ]; then for ex in `cat platform/$(PLATFORM)/include-exclude`; do echo exclude $$ex; rm -f $(BUILD)/includes/$$ex; done; fi; true
146 @echo "Unlinking platform files..."
147 @for dir in $(PROJDIRS); do find $(BUILD)/$$dir -type l -exec rm {} +; done
150 @echo "Available make targets:"
152 @echo "all - build $(PDCLIB)"
153 @echo "clean - remove all object files, dependency files and test drivers"
154 @echo "srcdist - build pdclib.tgz (source tarball)"
155 @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
156 @echo "tests - build and run test drivers (link $(PDCLIB))"
157 @echo " testdrivers - build but do not run test drivers"
158 @echo "regtests - build and run regression test drivers (link system clib)"
159 @echo " regtestdrivers - build but do not run regression test drivers"
160 @echo "todos - list all TODO comments in the sources"
161 @echo "fixmes - list all FIXME comments in the sources"
162 @echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
163 @echo "links - link platform files (development only)"
164 @echo "unlink - remove links to platform files (development only)"
165 @echo "%.o - build an individual object file"
166 @echo "%.t - build an individual test driver"
167 @echo "%.r - build an individual regression test driver"
168 @echo "help - print this list"
170 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
171 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
174 @echo " CC $(patsubst functions/%,%,$@)"
175 @$(CC) $(CFLAGS) -MMD -MP -I./$(BUILD)/includes -c $< -o $@
177 %_t: %.c Makefile $(PDCLIB)
178 @echo " CC $(patsubst functions/%,%,$@)"
179 @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./$(BUILD)/includes $< $(PDCLIB) -o $@
182 @echo " CC $(patsubst functions/%,%,$@)"
183 @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@