| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
AUXFILES := Makefile Readme.txt |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
PROJDIRS := functions includes internals |
|---|
| 8 |
|
|---|
| 9 |
SRCFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.c") |
|---|
| 10 |
|
|---|
| 11 |
HDRFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.h") |
|---|
| 12 |
|
|---|
| 13 |
INTFILES := _Exit atomax digits open print rename seed stdinit strtox_main strtox_prelim |
|---|
| 14 |
|
|---|
| 15 |
OBJFILES := $(patsubst %.c,%.o,$(SRCFILES)) |
|---|
| 16 |
|
|---|
| 17 |
TSTFILES := $(patsubst %.c,%.t,$(SRCFILES)) |
|---|
| 18 |
|
|---|
| 19 |
REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%.r,$(INTFILES)),$(patsubst %.c,%.r,$(SRCFILES))) |
|---|
| 20 |
|
|---|
| 21 |
DEPFILES := $(patsubst %.c,%.d,$(SRCFILES)) |
|---|
| 22 |
|
|---|
| 23 |
ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES) |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
PATCHFILES1 := $(shell ls platform/example/functions/_PDCLIB/*.c) |
|---|
| 27 |
|
|---|
| 28 |
PATCHFILES2 := $(shell ls platform/example/functions/stdlib/*.c) |
|---|
| 29 |
|
|---|
| 30 |
CFLAGS := -Wall -pedantic -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wconversion -Wstrict-prototypes -fno-builtin |
|---|
| 31 |
|
|---|
| 32 |
.PHONY: all clean dist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help |
|---|
| 33 |
|
|---|
| 34 |
all: pdclib.a |
|---|
| 35 |
|
|---|
| 36 |
pdclib.a: $(OBJFILES) |
|---|
| 37 |
@echo " AR $@" |
|---|
| 38 |
@ar rc pdclib.a $? |
|---|
| 39 |
@echo |
|---|
| 40 |
|
|---|
| 41 |
test: $(FILE) |
|---|
| 42 |
$(FILE) |
|---|
| 43 |
|
|---|
| 44 |
tests: testdrivers |
|---|
| 45 |
-@rc=0; count=0; echo; for file in $(TSTFILES); do echo " TST $$file"; ./$$file; rc=`expr $$rc + $$?`; count=`expr $$count + 1`; done; echo; echo "Tests executed (linking PDCLib): $$count Tests failed: $$rc"; echo |
|---|
| 46 |
|
|---|
| 47 |
testdrivers: $(TSTFILES) |
|---|
| 48 |
|
|---|
| 49 |
regtests: regtestdrivers |
|---|
| 50 |
-@rc=0; count=0; echo; for file in $(REGFILES); do echo " RTST $$file"; ./$$file; rc=`expr $$rc + $$?`; count=`expr $$count + 1`; done; echo; echo "Tests executed (linking system libc): $$count Tests failed: $$rc"; echo |
|---|
| 51 |
|
|---|
| 52 |
regtestdrivers: $(REGFILES) |
|---|
| 53 |
|
|---|
| 54 |
-include $(DEPFILES) |
|---|
| 55 |
|
|---|
| 56 |
clean: |
|---|
| 57 |
@for file in $(OBJFILES) $(DEPFILES) $(TSTFILES) $(REGFILES) pdclib.a pdclib.tgz; do if [ -f $$file ]; then rm $$file; fi; done |
|---|
| 58 |
|
|---|
| 59 |
dist: |
|---|
| 60 |
@tar czf pdclib.tgz $(ALLFILES) |
|---|
| 61 |
|
|---|
| 62 |
todos: |
|---|
| 63 |
-@for file in $(ALLFILES); do grep -H TODO $$file; done; true |
|---|
| 64 |
|
|---|
| 65 |
fixmes: |
|---|
| 66 |
-@for file in $(ALLFILES); do grep -H FIXME $$file; done; true |
|---|
| 67 |
|
|---|
| 68 |
find: |
|---|
| 69 |
@find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND |
|---|
| 70 |
|
|---|
| 71 |
links: |
|---|
| 72 |
@echo "Linking platform/example..." |
|---|
| 73 |
@cd internals && ln -s ../platform/example/internals/_PDCLIB_config.h |
|---|
| 74 |
@cd includes && ln -s ../platform/example/includes/float.h |
|---|
| 75 |
@cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done |
|---|
| 76 |
@cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done |
|---|
| 77 |
|
|---|
| 78 |
unlink: |
|---|
| 79 |
@echo "Unlinking platform files..." |
|---|
| 80 |
@if [ -f internals/_PDCLIB_config.h ]; then rm internals/_PDCLIB_config.h; fi |
|---|
| 81 |
@if [ -f includes/float.h ]; then rm includes/float.h; fi |
|---|
| 82 |
@cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done |
|---|
| 83 |
@cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done |
|---|
| 84 |
|
|---|
| 85 |
help: |
|---|
| 86 |
@echo "Available make targets:" |
|---|
| 87 |
@echo |
|---|
| 88 |
@echo "all - build pdclib.a" |
|---|
| 89 |
@echo "clean - remove all object files, dependency files and test drivers" |
|---|
| 90 |
@echo "dist - build pdclib.tgz (source tarball)" |
|---|
| 91 |
@echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)" |
|---|
| 92 |
@echo "tests - build and run test drivers (link pdclib.a)" |
|---|
| 93 |
@echo " testdrivers - build but do not run test drivers" |
|---|
| 94 |
@echo "regtests - build and run regression test drivers (link system clib)" |
|---|
| 95 |
@echo " regtestdrivers - build but do not run regression test drivers" |
|---|
| 96 |
@echo "todos - list all TODO comments in the sources" |
|---|
| 97 |
@echo "fixmes - list all FIXME comments in the sources" |
|---|
| 98 |
@echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)" |
|---|
| 99 |
@echo "links - link example platform files (development only)" |
|---|
| 100 |
@echo "unlink - remove links to example platform files (development only)" |
|---|
| 101 |
@echo "%.o - build an individual object file" |
|---|
| 102 |
@echo "%.t - build an individual test driver" |
|---|
| 103 |
@echo "%.r - build an individual regression test driver" |
|---|
| 104 |
@echo "help - print this list" |
|---|
| 105 |
|
|---|
| 106 |
%.o: %.c Makefile |
|---|
| 107 |
@echo " CC $(patsubst functions/%,%,$@)" |
|---|
| 108 |
@$(CC) $(CFLAGS) -DNDEBUG -MMD -MP -MT "$*.d $*.t" -g -std=c99 -I./includes -I./internals -c $< -o $@ |
|---|
| 109 |
|
|---|
| 110 |
%.t: %.c Makefile pdclib.a |
|---|
| 111 |
@echo " CC $(patsubst functions/%,%,$@)" |
|---|
| 112 |
@$(CC) $(CFLAGS) -DTEST -std=c99 -I./includes -I./internals $< pdclib.a -o $@ |
|---|
| 113 |
|
|---|
| 114 |
%.r: %.c Makefile |
|---|
| 115 |
@echo " CC $(patsubst functions/%,%,$@)" |
|---|
| 116 |
@$(CC) $(CFLAGS) -Wno-format -DTEST -DREGTEST -std=c99 -I./internals $< -o $@ |
|---|