diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-19 00:24:33 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-19 00:24:33 +0200 |
| commit | a96e591f64bc1ddf4c0e46cfa49c5dec7e8c7720 (patch) | |
| tree | 1dfdcc8c91299a74b80ef896398fdb2c90c770b6 /Makefile | |
| parent | aa0b76649161fb180d9d43ab74c2eb58ff4a83b6 (diff) | |
migrate build system from BSD make (pmake) to GNU make
- Replace BSD make != shell assignment with $(shell ...) idiom
- Replace static $(OBJS): rule + sed hack with %.o: %.c pattern rule
- Use $(MAKE) for all recursive make invocations
- Update CLAUDE.md to document GNU make instead of pmake
- Build verified clean on Fedora (GCC 15, all 14 examples pass)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 67 |
1 files changed, 50 insertions, 17 deletions
@@ -1,35 +1,42 @@ -# THIS MAKEFILE ONLY WORKS WITH (NET)BSD MAKE AKA PMAKE! +# Works with GNU Make on Linux (Fedora and similar). BIN=fype -SRCS!=find ./src -name '*.c' +# Use $(shell ...) for command substitution (GNU make idiom) +SRCS=$(shell find ./src -name '*.c') OBJS=$(SRCS:.c=.o) CC?=cc -#CC=mingw32-gcc DEBUG=-g3 -ggdb3 CFLAGS+=-c -Wall -std=c99 -pedantic $(DEBUG) LDADD+= HEADER?=docs/header.txt -OSYSTEM!=uname +# Detect the OS name for updating build.h +OSYSTEM=$(shell uname) PREFIX=/usr/local -all: build $(OBJS) newline stats-tofile - @$(CC) -lm -o $(BIN) $(OBJS) $(LDADD) - @if test -z '$(DEBUG)'; then strip $(BIN) ; fi + +all: build $(OBJS) newline stats-tofile + @$(CC) -lm -o $(BIN) $(OBJS) $(LDADD) + @if test -z '$(DEBUG)'; then strip $(BIN); fi @awk '$$2 == "BUILDNR" { printf("===> Fype build number % 13s :% 6s%d\n", \ "", "", $$3); exit(0); }' src/build.h - @echo "===> Fype binary size : `du -hs $(BIN)`" + @echo "===> Fype binary size : `du -hs $(BIN)`" @#echo "===> `./$(BIN) -v | sed 's/Build .*//'`" @./fype -v > ./docs/version.txt @./fype -h > ./docs/help.txt @./fype -s > ./docs/synopses.txt @echo -$(OBJS): - $(CC) $(LDADD) $(CFLAGS) `echo $@ | sed 's/\.o/\.c/'` -o $@ + +# Compile each .c to its .o using a GNU make pattern rule; $< is the source file +%.o: %.c + $(CC) $(CFLAGS) $< -o $@ + clean: find ./ -name 1 -exec rm -f {} \; find ./ -name '*.o' -exec rm -f {} \; find ./ -name '*.bin' -exec rm -f {} \; find . -name '*.core' -exec rm -f {} \; if [ -f $(BIN) ]; then rm -f $(BIN); fi + +# Increment BUILDNR and update the OS_ define in build.h before compiling build: ctags @awk '{ \ if ($$2 == "BUILDNR") print $$1,$$2,$$3+1; \ @@ -37,22 +44,29 @@ build: ctags toupper("$(OSYSTEM)")); \ else print }' \ src/build.h >.tmp && mv -f .tmp src/build.h + printbuild: @awk '$$2 == "BUILDNR" { printf("%d\n", \ $$3); exit(0); }' src/build.h + +# Generate ctags for editor navigation ctags: - @# Generating Source-Tags for Vim ctags `find . -name '*.c'` + style: astyle check astyle: find ./src -name '*.[ch]' -exec sh -c 'astyle -s3 {}; rm -f {}.orig' \; + +# Check for source lines exceeding 80 characters check: for f in `find ./src -name '*.[ch]'`; do awk -v f=$$f \ '{ if (length($$0) > 80) { \ printf "Max line length reached @ %s:%d => %d\n", \ f, NR, length($$0) } }' $$f; done + touch: find ./src -name '*.c' -exec touch {} \; + stats: @sh -c 'wc=`find ./src -name "*.[ch]" | xargs wc -l`; \ echo "===> Num of C source files : `echo \"$$wc\" | \ @@ -64,22 +78,31 @@ stats: grep -E \"\\.fy$$\" | wc -l`"; \ echo "===> Num of Fype source lines : `echo \"$$wc\" | \ tail -n 1 | sed s/total//`"' + +# Use $(MAKE) for recursive invocations so the correct make binary is always used stats-tofile: - make stats | tee ./docs/stats.txt + $(MAKE) stats | tee ./docs/stats.txt + testrun: cat ./test.fy > ./test.out ./$(BIN) -V ./test.fy | tee -a ./test.out + tr: testrun test: all testrun t: test + run: ./$(BIN) ./test.fy + core: gdb $(BIN) $(BIN).core + gdb: gdb --args $(BIN) .//test.fy + newline: - @echo + @echo + examples: all echo > ./examples/all-examples.txt for i in ./examples/*.fy; do \ @@ -88,28 +111,38 @@ examples: all cat $$i >> ./examples/all-examples.txt; \ echo >> ./examples/all-examples.txt; \ done + replace: find ./src -name '*.[ch]' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \ w .tmp" {} && mv -f .tmp {}' \; + headers: @find ./src -name '*.[ch]' -exec sh -c 'export FILE={}; \ - make header' \; + $(MAKE) header' \; + header: @echo "===> Processing $(FILE)" - @sed -n '/*:/d; w .tmp' $(FILE) + @sed -n '/*:/d; w .tmp' $(FILE) @header=`sed 's/\(.*\)/ echo " \*: \1"/' $(HEADER)`; \ echo '/*:*' > $(FILE); eval "$$header" >> $(FILE); \ echo ' *:*/' >> $(FILE); cat .tmp >> $(FILE); rm -f .tmp + +# Create a release tarball; use $(MAKE) to call printbuild correctly tar: clean - sh -c 'build=`make printbuild`;cd ../;\ + sh -c 'build=`$(MAKE) -s printbuild`;cd ../;\ tar cvjf $(BIN)-$$build.tar.bz2 $(BIN)' + install: all cp ./$(BIN) $(PREFIX)/bin cp ./docs/pod/fype.1.gz $(PREFIX)/man/man1 + deinstall: rm $(PREFIX)/bin/$(BIN) rm $(PREFIX)/man/man1/fype.1.gz + uninstall: deinstall + +# Build man page from POD source pod: - @cd ./docs/pod; make clean all + @cd ./docs/pod; $(MAKE) clean all @cp ./docs/pod/fype.pod README.pod |
