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
31 # This is where you chose which platform to compile for (see 'make links' / './platform')
34 # This is a list of all non-source files that are part of the distribution.
35 AUXFILES := Makefile Readme.txt
37 # Directories belonging to the project
38 PROJDIRS := functions includes internals
39 # All source files of the project
40 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
41 BUILDFILES := $(shell find -L $(BUILD) -type f -name "*.c")
42 # All header files of the project
43 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
44 BUILDHDRFILES := $(shell find -L $(BUILD) -type f -name "*.h")
45 # All .c files in functions/_PDCLIB that do not have a regression test driver
46 INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
47 # All object files in the library
48 OBJFILES := $(patsubst %.c,%.o,$(BUILDFILES))
49 # All test drivers (.t)
50 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
51 # All regression test drivers (.r)
52 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES)))
53 # All library dependency files (.d)
54 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
55 # All test driver dependency files (_t.d)
56 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
57 # All regression test driver dependency files (_r.d)
58 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
59 # All files belonging to the source distribution
60 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
62 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
63 PLATFORM_FLAGS=-mlittle-endian -mthumb -mcpu=$(CPU) -ffreestanding $(CPU_FLAGS)
64 CFLAGS := -Os -g -std=c99 -I./$(BUILD)/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
66 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
69 PDCLIB=$(PDCLIBNAME)-$(CPU).a
72 +for i in $(CPUS); do make CPU=$$i links; make CPU=$$i $(PDCLIBNAME)-$$i.a; done
75 @echo '######' install
76 +for i in $(CPUS); do make CPU=$$i prefix=$(prefix) install-lib-$$i; done
79 @echo '######' install-hdr
80 +make CPU=$(FIRSTCPU) prefix=$(prefix) install-hdr-$(FIRSTCPU)
83 +for i in $(CPUS); do make CPU=$$i clean-$$i; rm -rf build-$$i; done
85 check: all testdrivers regtestdrivers
87 @echo "========================"
88 @echo "Executing library tests:"
89 @echo "========================"
91 @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
93 @echo "==========================="
94 @echo "Executing regression tests:"
95 @echo "==========================="
97 @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
99 $(PDCLIB): $(BUILD) $(OBJFILES)
101 @ar rc $@ $(OBJFILES)
104 install-$(CPU): install-$(CPU)-lib install-hdr
105 @echo '######' install-$(CPU)
107 install-lib-$(CPU): $(PDCLIB)
108 @echo '######' install-lib-$(CPU)
109 install -D -c $(PDCLIB) $(DESTDIR)$(libdir)/$(PDCLIB)
111 install-hdr-$(CPU): $(BUILD) $(BUILDHDRFILES)
112 @echo '######' install-hdr-$(CPU)
113 for file in $(BUILDHDRFILES); do \
114 install -m 0444 -D -c $$file $(DESTDIR)$(includedir)/.; \
117 test: functions/$(FILE)
121 -@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
123 testdrivers: $(TSTFILES)
126 regtests: regtestdrivers
127 -@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
129 regtestdrivers: $(REGFILES)
132 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
134 clean-$(CPU): $(BUILD)
135 -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) $(PDCLIB) pdclib.tgz scanf_testdata_*)
138 @tar czf pdclib.tgz $(ALLFILES)
141 -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
144 -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
147 @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
150 @echo "Linking platform/$(PLATFORM)..."
151 @for dir in $$(find functions includes internals -type d); do mkdir -p $(BUILD)/$$dir; done
152 @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
153 @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
154 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
157 @echo "Unlinking platform files..."
158 @for dir in $(PROJDIRS); do find $(BUILD)/$$dir -type l -exec rm {} +; done
161 @echo "Available make targets:"
163 @echo "all - build $(PDCLIB)"
164 @echo "clean - remove all object files, dependency files and test drivers"
165 @echo "srcdist - build pdclib.tgz (source tarball)"
166 @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
167 @echo "tests - build and run test drivers (link $(PDCLIB))"
168 @echo " testdrivers - build but do not run test drivers"
169 @echo "regtests - build and run regression test drivers (link system clib)"
170 @echo " regtestdrivers - build but do not run regression test drivers"
171 @echo "todos - list all TODO comments in the sources"
172 @echo "fixmes - list all FIXME comments in the sources"
173 @echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
174 @echo "links - link platform files (development only)"
175 @echo "unlink - remove links to platform files (development only)"
176 @echo "%.o - build an individual object file"
177 @echo "%.t - build an individual test driver"
178 @echo "%.r - build an individual regression test driver"
179 @echo "help - print this list"
181 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
182 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
185 @echo " CC $(patsubst functions/%,%,$@)"
186 @$(CC) $(CFLAGS) -MMD -MP -I./$(BUILD)/includes -c $< -o $@
188 %_t: %.c Makefile $(PDCLIB)
189 @echo " CC $(patsubst functions/%,%,$@)"
190 @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./$(BUILD)/includes $< $(PDCLIB) -o $@
193 @echo " CC $(patsubst functions/%,%,$@)"
194 @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@