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