3 # This is where you chose which platform to compile for (see 'make links' / './platform')
6 # This is a list of all non-source files that are part of the distribution.
7 AUXFILES := Makefile Readme.txt
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 remove rename seed stdinit strtox_main strtox_prelim cleanstream fflush filemode
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 dependency files (.d)
24 DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
25 # All files belonging to the source distribution
26 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
28 # All files in platform/$(PLATFORM)/functions/_PDCLIB (for development only)
29 PATCHFILES1 := $(shell ls platform/$(PLATFORM)/functions/_PDCLIB/*.c)
30 # All files in platform/$(PLATFORM)/functions/stdlib (for development only)
31 PATCHFILES2 := $(shell ls platform/$(PLATFORM)/functions/stdlib/*.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 -Wconversion -fno-builtin
34 CFLAGS := -g -std=c99 -I./internals $(WARNINGS) $(USERFLAGS)
36 .PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
45 test: functions/$(FILE)
49 -@rc=0; count=0; failed=""; echo; 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;
51 testdrivers: $(TSTFILES)
53 regtests: regtestdrivers
54 -@rc=0; count=0; failed=""; echo; 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;
56 regtestdrivers: $(REGFILES)
61 @for file in $(OBJFILES) $(DEPFILES) $(TSTFILES) $(REGFILES) pdclib.a pdclib.tgz; do if [ -f $$file ]; then rm $$file; fi; done
64 @tar czf pdclib.tgz $(ALLFILES)
67 -@for file in $(ALLFILES); do grep -H TODO $$file; done; true
70 -@for file in $(ALLFILES); do grep -H FIXME $$file; done; true
73 @find functions/ includes/ internals/ platform/ old_stdio/ -name "*\.[ch]" -type f | xargs grep $$FIND
76 @echo "Linking platform/$(PLATFORM)..."
77 @cd internals && ln -s ../platform/$(PLATFORM)/internals/_PDCLIB_config.h
78 @cd includes && ln -s ../platform/$(PLATFORM)/includes/float.h
79 @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done
80 @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done
83 @echo "Unlinking platform files..."
84 @if [ -f internals/_PDCLIB_config.h ]; then rm internals/_PDCLIB_config.h; fi
85 @if [ -f includes/float.h ]; then rm includes/float.h; fi
86 @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done
87 @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done
90 @echo "Available make targets:"
92 @echo "all - build pdclib.a"
93 @echo "clean - remove all object files, dependency files and test drivers"
94 @echo "srcdist - build pdclib.tgz (source tarball)"
95 @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
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 "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
103 @echo "links - link platform files (development only)"
104 @echo "unlink - remove links to platform files (development only)"
105 @echo "%.o - build an individual object file"
106 @echo "%.t - build an individual test driver"
107 @echo "%.r - build an individual regression test driver"
108 @echo "help - print this list"
110 @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
111 @echo "(Usage: USERFLAGS=\"flags\" make [...])."
114 @echo " CC $(patsubst functions/%,%,$@)"
115 @$(CC) $(CFLAGS) -MMD -MP -MT "$*.d $*.t" -I./includes -c $< -o $@
117 %.t: %.c Makefile pdclib.a
118 @echo " CC $(patsubst functions/%,%,$@)"
119 @$(CC) $(CFLAGS) -DTEST -I./includes $< pdclib.a -o $@
122 @echo " CC $(patsubst functions/%,%,$@)"
123 @$(CC) $(CFLAGS) -Wno-format -DTEST -DREGTEST $< -o $@