9 includedir=$(prefix)/include
12 CPUS=cortex-m0 cortex-m3 cortex-m4
17 # CPU specific compiler flags
18 ifeq ($(CPU),cortex-m0)
21 ifeq ($(CPU),cortex-m3)
24 ifeq ($(CPU),cortex-m4)
25 CPU_FLAGS=-mfloat-abi=hard
28 #CC=$(bindir)/arm-none-eabi-gcc
29 CC=/usr/bin/arm-none-eabi-gcc
30 AR=/usr/bin/arm-none-eabi-ar
32 # This is where you chose which platform to compile for (see 'make links' / './platform')
35 # This is a list of all non-source files that are part of the distribution.
36 AUXFILES := Makefile Readme.txt
38 # Directories belonging to the project
39 PROJDIRS := functions includes internals
40 # All source files of the project
41 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
42 BUILDFILES := $(shell find -L $(BUILD) -type f -name "*.c")
43 # All header files of the project
44 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
45 BUILDHDRFILES := $(shell find -L $(BUILD) -type f -name "*.h")
46 # All .c files in functions/_PDCLIB that do not have a regression test driver
47 INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
48 # All object files in the library
49 OBJFILES := $(patsubst %.c,%.o,$(BUILDFILES))
50 # All test drivers (.t)
51 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
52 # All regression test drivers (.r)
53 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES)))
54 # All library dependency files (.d)
55 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
56 # All test driver dependency files (_t.d)
57 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
58 # All regression test driver dependency files (_r.d)
59 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
60 # All files belonging to the source distribution
61 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
63 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
64 PLATFORM_FLAGS=-mlittle-endian -mthumb -mcpu=$(CPU) -ffreestanding $(CPU_FLAGS)
65 CFLAGS := -Os -g -std=c99 -I./$(BUILD)/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
67 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
70 PDCLIB=$(PDCLIBNAME)-$(CPU).a
73 +for i in $(CPUS); do make CPU=$$i links; make CPU=$$i $(PDCLIBNAME)-$$i.a; done
76 @echo '######' install
77 +for i in $(CPUS); do make CPU=$$i prefix=$(prefix) install-lib-$$i; done
80 @echo '######' install-hdr
81 +make CPU=$(FIRSTCPU) prefix=$(prefix) install-hdr-$(FIRSTCPU)
84 +for i in $(CPUS); do make CPU=$$i clean-$$i; rm -rf build-$$i; done
86 check: all testdrivers regtestdrivers
88 @echo "========================"
89 @echo "Executing library tests:"
90 @echo "========================"
92 @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
94 @echo "==========================="
95 @echo "Executing regression tests:"
96 @echo "==========================="
98 @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
100 $(PDCLIB): $(BUILD) $(OBJFILES)
102 @$(AR) rc $@ $(OBJFILES)
105 install-$(CPU): install-$(CPU)-lib install-hdr
106 @echo '######' install-$(CPU)
108 install-lib-$(CPU): $(PDCLIB)
109 @echo '######' install-lib-$(CPU)
110 install -D -c $(PDCLIB) $(DESTDIR)$(libdir)/$(PDCLIB)
112 install-hdr-$(CPU): $(BUILD) $(BUILDHDRFILES)
113 @echo '######' install-hdr-$(CPU)
114 for file in $(BUILDHDRFILES); do \
115 install -m 0444 -D -c $$file $(DESTDIR)$(includedir)/.; \
118 test: functions/$(FILE)
122 -@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
124 testdrivers: $(TSTFILES)
127 regtests: regtestdrivers
128 -@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
130 regtestdrivers: $(REGFILES)
133 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
135 clean-$(CPU): $(BUILD)
136 -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) $(PDCLIB) pdclib.tgz scanf_testdata_*)
139 @tar czf pdclib.tgz $(ALLFILES)
142 -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
145 -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
148 @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
151 @echo "Linking platform/$(PLATFORM)..."
152 @for dir in $$(find functions includes internals -type d); do mkdir -p $(BUILD)/$$dir; done
153 @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
154 @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
155 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
158 @echo "Unlinking platform files..."
159 @for dir in $(PROJDIRS); do find $(BUILD)/$$dir -type l -exec rm {} +; done
162 @echo "Available make targets:"
164 @echo "all - build $(PDCLIB)"
165 @echo "clean - remove all object files, dependency files and test drivers"
166 @echo "srcdist - build pdclib.tgz (source tarball)"
167 @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
168 @echo "tests - build and run test drivers (link $(PDCLIB))"
169 @echo " testdrivers - build but do not run test drivers"
170 @echo "regtests - build and run regression test drivers (link system clib)"
171 @echo " regtestdrivers - build but do not run regression test drivers"
172 @echo "todos - list all TODO comments in the sources"
173 @echo "fixmes - list all FIXME comments in the sources"
174 @echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
175 @echo "links - link platform files (development only)"
176 @echo "unlink - remove links to platform files (development only)"
177 @echo "%.o - build an individual object file"
178 @echo "%.t - build an individual test driver"
179 @echo "%.r - build an individual regression test driver"
180 @echo "help - print this list"
182 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
183 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
186 @echo " CC $(patsubst functions/%,%,$@)"
187 @$(CC) $(CFLAGS) -MMD -MP -I./$(BUILD)/includes -c $< -o $@
189 %_t: %.c Makefile $(PDCLIB)
190 @echo " CC $(patsubst functions/%,%,$@)"
191 @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./$(BUILD)/includes $< $(PDCLIB) -o $@
194 @echo " CC $(patsubst functions/%,%,$@)"
195 @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@