On altos, the primitive input function is ao_getchar, not getchar
[fw/pdclib] / Makefile
1 # $Id$
2
3 ifndef prefix
4 prefix=/opt/cortex
5 endif
6
7 libdir=$(prefix)/lib
8 bindir=$(prefix)/bin
9 includedir=$(prefix)/include
10
11 #CPU=cortex-m3
12 CPUS=cortex-m0 cortex-m3 cortex-m4
13 FIRSTCPU=cortex-m0
14 CPU=none
15 BUILD=build-$(CPU)
16
17 # CPU specific compiler flags
18 ifeq ($(CPU),cortex-m0)
19 CPU_FLAGS=
20 endif
21 ifeq ($(CPU),cortex-m3)
22 CPU_FLAGS=
23 endif
24 ifeq ($(CPU),cortex-m4)
25 CPU_FLAGS=-mfloat-abi=hard
26 endif
27
28 #CC=$(bindir)/arm-none-eabi-gcc
29 CC=/usr/bin/arm-none-eabi-gcc
30 AR=/usr/bin/arm-none-eabi-ar
31
32 # This is where you chose which platform to compile for (see 'make links' / './platform')
33 PLATFORM := altos
34
35 # This is a list of all non-source files that are part of the distribution.
36 AUXFILES := Makefile Readme.txt
37
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)
62
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)
66
67 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
68
69 PDCLIBNAME=libpdclib
70 PDCLIB=$(PDCLIBNAME)-$(CPU).a
71
72 all:
73         +for i in $(CPUS); do make CPU=$$i links; make CPU=$$i $(PDCLIBNAME)-$$i.a; done
74
75 install: install-hdr
76         @echo '######' install
77         +for i in $(CPUS); do make CPU=$$i prefix=$(prefix) install-lib-$$i; done
78
79 install-hdr:
80         @echo '######' install-hdr
81         +make CPU=$(FIRSTCPU) prefix=$(prefix) install-hdr-$(FIRSTCPU)
82
83 clean:
84         +for i in $(CPUS); do make CPU=$$i clean-$$i; rm -rf build-$$i; done
85
86 check: all testdrivers regtestdrivers
87         @echo
88         @echo "========================"
89         @echo "Executing library tests:"
90         @echo "========================"
91         @echo
92         @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
93         @echo
94         @echo "==========================="
95         @echo "Executing regression tests:"
96         @echo "==========================="
97         @echo
98         @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
99
100 $(PDCLIB): $(BUILD) $(OBJFILES)
101         @echo " AR      $@"
102         @$(AR) rc $@ $(OBJFILES)
103         @echo
104
105 install-$(CPU): install-$(CPU)-lib install-hdr
106         @echo '######' install-$(CPU)
107
108 install-lib-$(CPU): $(PDCLIB)
109         @echo '######' install-lib-$(CPU)
110         install -D -c $(PDCLIB) $(DESTDIR)$(libdir)/$(PDCLIB)
111
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)/.; \
116         done
117
118 test: functions/$(FILE)
119         functions/$(FILE)
120
121 tests: testdrivers
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
123
124 testdrivers: $(TSTFILES)
125         @echo
126
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
129
130 regtestdrivers: $(REGFILES)
131         @echo
132
133 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
134
135 clean-$(CPU): $(BUILD)
136         -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) $(PDCLIB) pdclib.tgz scanf_testdata_*)
137
138 srcdist:
139         @tar czf pdclib.tgz $(ALLFILES)
140
141 todos:
142         -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
143
144 fixmes:
145         -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
146
147 find:
148         @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
149
150 links: $(BUILD)
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
156
157 unlink: $(BUILD)
158         @echo "Unlinking platform files..."
159         @for dir in $(PROJDIRS); do find $(BUILD)/$$dir -type l -exec rm {} +; done
160
161 help:
162         @echo "Available make targets:"
163         @echo
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"
181         @echo
182         @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
183         @echo "(Usage: USERFLAGS=\"flags\" make [...])."
184
185 %.o: %.c Makefile
186         @echo " CC      $(patsubst functions/%,%,$@)"
187         @$(CC) $(CFLAGS) -MMD -MP -I./$(BUILD)/includes -c $< -o $@
188
189 %_t: %.c Makefile $(PDCLIB)
190         @echo " CC      $(patsubst functions/%,%,$@)"
191         @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./$(BUILD)/includes $< $(PDCLIB) -o $@
192
193 %_r: %.c Makefile
194         @echo " CC      $(patsubst functions/%,%,$@)"
195         @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@
196
197 $(BUILD):
198         mkdir -p $(BUILD)