]> pd.if.org Git - pdclib/blob - Makefile
Various updates. Made assert() no longer rely on standard version. Removed _PDCLIB_C_...
[pdclib] / Makefile
1 # This is where you chose which platform to compile for (see 'make links' / './platform')
2 PLATFORM := example
3
4 # This is a list of all non-source files that are part of the distribution.
5 AUXFILES := Makefile Readme.txt
6
7 # Directories belonging to the project
8 PROJDIRS := functions includes internals
9 # All source files of the project
10 SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c")
11 # All header files of the project
12 HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h")
13 # All .c files in functions/_PDCLIB that do not have a regression test driver
14 INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
15 # All object files in the library
16 OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
17 # All test drivers (.t)
18 TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
19 # All regression test drivers (.r)
20 REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES)))
21 # All library dependency files (.d)
22 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
23 # All test driver dependency files (_t.d)
24 TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES))
25 # All regression test driver dependency files (_r.d)
26 REGDEPFILES := $(patsubst %,%.d,$(REGFILES))
27 # All files belonging to the source distribution
28 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
29
30 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 
31 CFLAGS := -fno-builtin -g -std=c99 -I./internals -I./testing $(WARNINGS) $(USERFLAGS)
32
33 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
34
35 all: pdclib.a testdrivers regtestdrivers
36         @echo
37         @echo "========================"
38         @echo "Executing library tests:"
39         @echo "========================"
40         @echo
41         @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
42         @echo
43         @echo "==========================="
44         @echo "Executing regression tests:"
45         @echo "==========================="
46         @echo
47         @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
48
49 pdclib.a: $(OBJFILES)
50         @echo " AR      $@"
51         @ar rc pdclib.a $?
52         @echo
53
54 test: functions/$(FILE)
55         functions/$(FILE)
56
57 tests: testdrivers
58         -@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
59
60 testdrivers: $(TSTFILES)
61         @echo
62
63 regtests: regtestdrivers
64         -@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
65
66 regtestdrivers: $(REGFILES)
67         @echo
68
69 -include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES)
70
71 clean:
72         -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) pdclib.a pdclib.tgz scanf_testdata_*)
73
74 srcdist:
75         @tar czf pdclib.tgz $(ALLFILES)
76
77 todos:
78         -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true
79
80 fixmes:
81         -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true
82
83 find:
84         @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
85
86 links:
87         @echo "Linking platform/$(PLATFORM)..."
88         @if [ ! -d functions/signal ]; then mkdir functions/signal; fi
89         @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
90
91 unlink:
92         @echo "Unlinking platform files..."
93         @for dir in $(PROJDIRS); do find $$dir -type l -exec rm {} +; done
94         @rmdir functions/signal
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) -Wno-deprecated-declarations -Wno-format -MMD -MP -DTEST -DREGTEST $< -o $@