1 # This is where you chose which platform to compile for (see 'make links' / './platform')
2 PLATFORM := example_cygwin
4 # This is a list of all non-source files that are part of the distribution.
5 AUXFILES := Makefile Readme.txt
7 # Directories belonging to the project
8 PROJDIRS := functions includes internals
9 # All source files of the project
10 SRCFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.c")
11 # All header files of the project
12 HDRFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -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 cleanstream fflush filemode eol errno seek prepread prepwrite allocpages
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 dependency files (.d)
22 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
23 # All files belonging to the source distribution
24 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
26 # All files in platform/$(PLATFORM)/functions/_PDCLIB (for development only)
27 PATCHFILES1 := $(shell ls platform/$(PLATFORM)/functions/_PDCLIB/*.c)
28 # All files in platform/$(PLATFORM)/functions/stdlib (for development only)
29 PATCHFILES2 := $(shell ls platform/$(PLATFORM)/functions/stdlib/*.c)
30 # All files in platform/$(PLATFORM)/functions/stdio (for development only)
31 PATCHFILES3 := $(shell ls platform/$(PLATFORM)/functions/stdio/*.c)
33 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 -fno-builtin
34 CFLAGS := -g -std=gnu99 -I./internals $(WARNINGS) $(USERFLAGS)
36 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
38 all: pdclib.a testdrivers regtestdrivers
40 @echo "========================"
41 @echo "Executing library tests:"
42 @echo "========================"
44 @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
46 @echo "==========================="
47 @echo "Executing regression tests:"
48 @echo "==========================="
50 @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
57 test: functions/$(FILE)
61 -@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
63 testdrivers: $(TSTFILES)
66 regtests: regtestdrivers
67 -@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
69 regtestdrivers: $(REGFILES)
75 @for file in $(OBJFILES) $(DEPFILES) $(TSTFILES) $(REGFILES) pdclib.a pdclib.tgz; do if [ -f $$file ]; then rm $$file; fi; done
78 @tar czf pdclib.tgz $(ALLFILES)
81 -@for file in $(ALLFILES); do grep -H TODO $$file; done; true
84 -@for file in $(ALLFILES); do grep -H FIXME $$file; done; true
87 @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
90 @echo "Linking platform/$(PLATFORM)..."
91 @cd internals && ln -s ../platform/$(PLATFORM)/internals/_PDCLIB_config.h
92 @cd includes && ln -s ../platform/$(PLATFORM)/includes/float.h
93 @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done
94 @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done
95 @cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done
98 @echo "Unlinking platform files..."
99 @if [ -f internals/_PDCLIB_config.h ]; then rm internals/_PDCLIB_config.h; fi
100 @if [ -f includes/float.h ]; then rm includes/float.h; fi
101 @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done
102 @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done
103 @cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done
106 @echo "Available make targets:"
108 @echo "all - build pdclib.a"
109 @echo "clean - remove all object files, dependency files and test drivers"
110 @echo "srcdist - build pdclib.tgz (source tarball)"
111 @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
112 @echo "tests - build and run test drivers (link pdclib.a)"
113 @echo " testdrivers - build but do not run test drivers"
114 @echo "regtests - build and run regression test drivers (link system clib)"
115 @echo " regtestdrivers - build but do not run regression test drivers"
116 @echo "todos - list all TODO comments in the sources"
117 @echo "fixmes - list all FIXME comments in the sources"
118 @echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
119 @echo "links - link platform files (development only)"
120 @echo "unlink - remove links to platform files (development only)"
121 @echo "%.o - build an individual object file"
122 @echo "%.t - build an individual test driver"
123 @echo "%.r - build an individual regression test driver"
124 @echo "help - print this list"
126 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
127 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
130 @echo " CC $(patsubst functions/%,%,$@)"
131 @$(CC) $(CFLAGS) -MMD -MP -MT "$*.d $*.t" -I./includes -c $< -o $@
133 %.t: %.c Makefile pdclib.a
134 @echo " CC $(patsubst functions/%,%,$@)"
135 @$(CC) $(CFLAGS) -DTEST -I./includes $< pdclib.a -o $@
138 @echo " CC $(patsubst functions/%,%,$@)"
139 @$(CC) $(CFLAGS) -Wno-format -DTEST -DREGTEST $< -o $@