| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
PLATFORM := example |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
AUXFILES := Makefile Readme.txt |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
PROJDIRS := functions includes internals |
|---|
| 11 |
|
|---|
| 12 |
SRCFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.c") |
|---|
| 13 |
|
|---|
| 14 |
HDRFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.h") |
|---|
| 15 |
|
|---|
| 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 |
|
|---|
| 18 |
OBJFILES := $(patsubst %.c,%.o,$(SRCFILES)) |
|---|
| 19 |
|
|---|
| 20 |
TSTFILES := $(patsubst %.c,%.t,$(SRCFILES)) |
|---|
| 21 |
|
|---|
| 22 |
REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%.r,$(INTFILES)),$(patsubst %.c,%.r,$(SRCFILES))) |
|---|
| 23 |
|
|---|
| 24 |
DEPFILES := $(patsubst %.c,%.d,$(SRCFILES)) |
|---|
| 25 |
|
|---|
| 26 |
ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES) |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
PATCHFILES1 := $(shell ls platform/$(PLATFORM)/functions/_PDCLIB/*.c) |
|---|
| 30 |
|
|---|
| 31 |
PATCHFILES2 := $(shell ls platform/$(PLATFORM)/functions/stdlib/*.c) |
|---|
| 32 |
|
|---|
| 33 |
PATCHFILES3 := $(shell ls platform/$(PLATFORM)/functions/stdio/*.c) |
|---|
| 34 |
|
|---|
| 35 |
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 |
|---|
| 36 |
CFLAGS := -g -std=c99 -I./internals -I./testing $(WARNINGS) $(USERFLAGS) |
|---|
| 37 |
|
|---|
| 38 |
.PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help |
|---|
| 39 |
|
|---|
| 40 |
all: pdclib.a testdrivers regtestdrivers |
|---|
| 41 |
@echo |
|---|
| 42 |
@echo "========================" |
|---|
| 43 |
@echo "Executing library tests:" |
|---|
| 44 |
@echo "========================" |
|---|
| 45 |
@echo |
|---|
| 46 |
@$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed" |
|---|
| 47 |
@echo |
|---|
| 48 |
@echo "===========================" |
|---|
| 49 |
@echo "Executing regression tests:" |
|---|
| 50 |
@echo "===========================" |
|---|
| 51 |
@echo |
|---|
| 52 |
@$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed" |
|---|
| 53 |
|
|---|
| 54 |
pdclib.a: $(OBJFILES) |
|---|
| 55 |
@echo " AR $@" |
|---|
| 56 |
@ar rc pdclib.a $? |
|---|
| 57 |
@echo |
|---|
| 58 |
|
|---|
| 59 |
test: functions/$(FILE) |
|---|
| 60 |
functions/$(FILE) |
|---|
| 61 |
|
|---|
| 62 |
tests: testdrivers |
|---|
| 63 |
-@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 |
|---|
| 64 |
|
|---|
| 65 |
testdrivers: $(TSTFILES) |
|---|
| 66 |
@echo |
|---|
| 67 |
|
|---|
| 68 |
regtests: regtestdrivers |
|---|
| 69 |
-@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 |
|---|
| 70 |
|
|---|
| 71 |
regtestdrivers: $(REGFILES) |
|---|
| 72 |
@echo |
|---|
| 73 |
|
|---|
| 74 |
-include $(DEPFILES) |
|---|
| 75 |
|
|---|
| 76 |
clean: |
|---|
| 77 |
@for file in $(OBJFILES) $(DEPFILES) $(TSTFILES) $(REGFILES) pdclib.a pdclib.tgz scanf_testdata_*; do if [ -f $$file ]; then rm $$file; fi; done |
|---|
| 78 |
|
|---|
| 79 |
srcdist: |
|---|
| 80 |
@tar czf pdclib.tgz $(ALLFILES) |
|---|
| 81 |
|
|---|
| 82 |
todos: |
|---|
| 83 |
-@for file in $(ALLFILES); do grep -H TODO $$file; done; true |
|---|
| 84 |
|
|---|
| 85 |
fixmes: |
|---|
| 86 |
-@for file in $(ALLFILES); do grep -H FIXME $$file; done; true |
|---|
| 87 |
|
|---|
| 88 |
find: |
|---|
| 89 |
@find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND |
|---|
| 90 |
|
|---|
| 91 |
links: |
|---|
| 92 |
@echo "Linking platform/$(PLATFORM)..." |
|---|
| 93 |
@cd internals && ln -s ../platform/$(PLATFORM)/internals/_PDCLIB_config.h |
|---|
| 94 |
@cd includes && ln -s ../platform/$(PLATFORM)/includes/float.h |
|---|
| 95 |
@cd testing && ln -s ../platform/$(PLATFORM)/testing/printf_reference.txt |
|---|
| 96 |
@cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done |
|---|
| 97 |
@cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done |
|---|
| 98 |
@cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done |
|---|
| 99 |
|
|---|
| 100 |
unlink: |
|---|
| 101 |
@echo "Unlinking platform files..." |
|---|
| 102 |
@if [ -f internals/_PDCLIB_config.h ]; then rm internals/_PDCLIB_config.h; fi |
|---|
| 103 |
@if [ -f includes/float.h ]; then rm includes/float.h; fi |
|---|
| 104 |
@if [ -f testing/printf_reference.txt ]; then rm testing/printf_reference.txt; fi |
|---|
| 105 |
@cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done |
|---|
| 106 |
@cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done |
|---|
| 107 |
@cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done |
|---|
| 108 |
|
|---|
| 109 |
help: |
|---|
| 110 |
@echo "Available make targets:" |
|---|
| 111 |
@echo |
|---|
| 112 |
@echo "all - build pdclib.a" |
|---|
| 113 |
@echo "clean - remove all object files, dependency files and test drivers" |
|---|
| 114 |
@echo "srcdist - build pdclib.tgz (source tarball)" |
|---|
| 115 |
@echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)" |
|---|
| 116 |
@echo "tests - build and run test drivers (link pdclib.a)" |
|---|
| 117 |
@echo " testdrivers - build but do not run test drivers" |
|---|
| 118 |
@echo "regtests - build and run regression test drivers (link system clib)" |
|---|
| 119 |
@echo " regtestdrivers - build but do not run regression test drivers" |
|---|
| 120 |
@echo "todos - list all TODO comments in the sources" |
|---|
| 121 |
@echo "fixmes - list all FIXME comments in the sources" |
|---|
| 122 |
@echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)" |
|---|
| 123 |
@echo "links - link platform files (development only)" |
|---|
| 124 |
@echo "unlink - remove links to platform files (development only)" |
|---|
| 125 |
@echo "%.o - build an individual object file" |
|---|
| 126 |
@echo "%.t - build an individual test driver" |
|---|
| 127 |
@echo "%.r - build an individual regression test driver" |
|---|
| 128 |
@echo "help - print this list" |
|---|
| 129 |
@echo |
|---|
| 130 |
@echo "Any additional compiler flags you want to use can be passed as USERFLAGS" |
|---|
| 131 |
@echo "(Usage: USERFLAGS=\"flags\" make [...])." |
|---|
| 132 |
|
|---|
| 133 |
%.o: %.c Makefile |
|---|
| 134 |
@echo " CC $(patsubst functions/%,%,$@)" |
|---|
| 135 |
@$(CC) $(CFLAGS) -MMD -MP -MT "$*.d $*.t $*.o" -I./includes -c $< -o $@ |
|---|
| 136 |
|
|---|
| 137 |
%.t: %.c Makefile pdclib.a |
|---|
| 138 |
@echo " CC $(patsubst functions/%,%,$@)" |
|---|
| 139 |
@$(CC) $(CFLAGS) -DTEST -I./includes $< pdclib.a -o $@ |
|---|
| 140 |
|
|---|
| 141 |
%.r: %.c Makefile |
|---|
| 142 |
@echo " CC $(patsubst functions/%,%,$@)" |
|---|
| 143 |
@$(CC) $(CFLAGS) -Wno-format -DTEST -DREGTEST $< -o $@ |
|---|
| 144 |
|
|---|