Add 'install' targets
[fw/pdclib] / Makefile
1 # $Id$
2
3 DESTDIR=
4 prefix=/home/keithp/sat
5 libdir=$(prefix)/lib
6 includedir=$(prefix)/include
7
8 CC=arm-none-eabi-gcc
9
10 # This is where you chose which platform to compile for (see 'make links' / './platform')
11 PLATFORM := altos
12
13 # This is a list of all non-source files that are part of the distribution.
14 AUXFILES := Makefile Readme.txt
15
16 # Directories belonging to the project
17 PROJDIRS := functions includes internals
18 # All source files of the project
19 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
20 BUILDFILES := $(shell find -L build -type f -name "*.c")
21 # All header files of the project
22 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
23 BUILDHDRFILES := $(shell find -L build -type f -name "*.h")
24 # All .c files in functions/_PDCLIB that do not have a regression test driver
25 INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
26 # All object files in the library
27 OBJFILES := $(patsubst %.c,%.o,$(BUILDFILES))
28 # All test drivers (.t)
29 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
30 # All regression test drivers (.r)
31 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES)))
32 # All library dependency files (.d)
33 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
34 # All test driver dependency files (_t.d)
35 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
36 # All regression test driver dependency files (_r.d)
37 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
38 # All files belonging to the source distribution
39 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
40
41 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 
42 PLATFORM_FLAGS=-nostdinc -mlittle-endian -mthumb -mcpu=cortex-m3 -ffreestanding -nostdlib
43 CFLAGS := -fno-builtin -Os -g -std=c99 -I./build/internals -I./testing $(WARNINGS) $(USERFLAGS) $(PLATFORM_FLAGS)
44
45 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
46
47 all: pdclib.a
48
49 check: all testdrivers regtestdrivers
50         @echo
51         @echo "========================"
52         @echo "Executing library tests:"
53         @echo "========================"
54         @echo
55         @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
56         @echo
57         @echo "==========================="
58         @echo "Executing regression tests:"
59         @echo "==========================="
60         @echo
61         @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
62
63 pdclib.a: $(OBJFILES)
64         @echo " AR      $@"
65         @ar rc pdclib.a $?
66         @echo
67
68 install: install-lib install-hdr
69
70 install-lib: pdclib.a
71         install -D -c pdclib.a $(DESTDIR)$(libdir)/pdclib.a
72
73 install-hdr: $(BUILDHDRFILES)
74         for file in $(BUILDHDRFILES); do \
75                 install -D -c $$file $(DESTDIR)$(includedir)/.; \
76         done
77
78 test: functions/$(FILE)
79         functions/$(FILE)
80
81 tests: testdrivers
82         -@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
83
84 testdrivers: $(TSTFILES)
85         @echo
86
87 regtests: regtestdrivers
88         -@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
89
90 regtestdrivers: $(REGFILES)
91         @echo
92
93 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
94
95 clean:
96         -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) pdclib.a pdclib.tgz scanf_testdata_*)
97
98 srcdist:
99         @tar czf pdclib.tgz $(ALLFILES)
100
101 todos:
102         -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
103
104 fixmes:
105         -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
106
107 find:
108         @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
109
110 links:
111         @echo "Linking platform/$(PLATFORM)..."
112         @for dir in $$(find functions includes internals -type d); do mkdir -p build/$$dir; done
113         @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
114         @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
115
116 unlink:
117         @echo "Unlinking platform files..."
118         @for dir in $(PROJDIRS); do find build/$$dir -type l -exec rm {} +; done
119
120 help:
121         @echo "Available make targets:"
122         @echo
123         @echo "all              - build pdclib.a"
124         @echo "clean            - remove all object files, dependency files and test drivers"
125         @echo "srcdist          - build pdclib.tgz (source tarball)"
126         @echo "test             - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
127         @echo "tests            - build and run test drivers (link pdclib.a)"
128         @echo "  testdrivers    - build but do not run test drivers"
129         @echo "regtests         - build and run regression test drivers (link system clib)"
130         @echo "  regtestdrivers - build but do not run regression test drivers"
131         @echo "todos            - list all TODO comments in the sources"
132         @echo "fixmes           - list all FIXME comments in the sources"
133         @echo "find             - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
134         @echo "links            - link platform files (development only)"
135         @echo "unlink           - remove links to platform files (development only)"
136         @echo "%.o              - build an individual object file"
137         @echo "%.t              - build an individual test driver"
138         @echo "%.r              - build an individual regression test driver"
139         @echo "help             - print this list"
140         @echo
141         @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
142         @echo "(Usage: USERFLAGS=\"flags\" make [...])."
143
144 %.o: %.c Makefile
145         echo " CC       $(patsubst functions/%,%,$@)"
146         $(CC) $(CFLAGS) -MMD -MP -I./build/includes -c $< -o $@
147
148 %_t: %.c Makefile pdclib.a
149         @echo " CC      $(patsubst functions/%,%,$@)"
150         @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./build/includes $< pdclib.a -o $@
151
152 %_r: %.c Makefile
153         @echo " CC      $(patsubst functions/%,%,$@)"
154         @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@
155