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