2022-02-10 23:30:11 -05:00
|
|
|
optimize := -ffast-math
|
2022-12-27 02:31:08 -05:00
|
|
|
warnbasic := -Wall -pedantic #-ansi # -std=c99
|
|
|
|
warnclang := -Wextra -Weverything \
|
2022-01-19 20:06:41 -05:00
|
|
|
-Wno-comma \
|
|
|
|
-Wno-logical-op-parentheses \
|
|
|
|
-Wno-parentheses \
|
|
|
|
-Wno-documentation-unknown-command \
|
|
|
|
-Wno-documentation \
|
|
|
|
-Wno-shift-op-parentheses \
|
|
|
|
-Wno-empty-body \
|
|
|
|
-Wno-padded \
|
2022-02-10 23:30:11 -05:00
|
|
|
-Wno-switch-enum \
|
2022-12-27 02:31:08 -05:00
|
|
|
-Wno-missing-noreturn \
|
|
|
|
-Wno-implicit-fallthrough
|
|
|
|
# https://stackoverflow.com/a/12099167
|
|
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
warnclang += -Wno-poison-system-directories
|
|
|
|
endif
|
|
|
|
# Some stuff is really new, comment out the warnclang?
|
2022-01-19 20:06:41 -05:00
|
|
|
warn := $(warnbasic) $(warnclang)
|
|
|
|
CC := clang # gcc
|
2022-12-27 02:31:08 -05:00
|
|
|
CF := $(optimize) $(warn)
|
|
|
|
OF :=
|
2022-02-10 23:30:11 -05:00
|
|
|
ifeq (release, $(firstword $(MAKECMDGOALS)))
|
|
|
|
CF += -funroll-loops -Ofast -D NDEBUG # -O3
|
|
|
|
OF += -Ofast
|
|
|
|
else
|
|
|
|
CF += -g
|
|
|
|
endif
|
2022-01-19 20:06:41 -05:00
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
projects := bin/text bin/kjv
|
|
|
|
#docs := $(patsubst test/test_%.c, doc/%.md, $(wildcard test/test_*.c))
|
2022-01-19 20:06:41 -05:00
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
default: $(projects)
|
|
|
|
# success
|
2022-01-19 20:06:41 -05:00
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
bin/text: build/text.o build/test_text.o
|
2022-12-27 15:28:04 -05:00
|
|
|
bin/kjv: build/text.o build/kjv.o build/test_kjv.o
|
2022-01-19 20:06:41 -05:00
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
bin/%:
|
|
|
|
# linking test $@
|
|
|
|
@mkdir -p bin
|
2022-01-19 20:06:41 -05:00
|
|
|
$(CC) $(OF) -o $@ $^
|
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
build/%.o: src/%.c
|
|
|
|
# compile src $@
|
|
|
|
@mkdir -p build
|
2022-01-19 20:06:41 -05:00
|
|
|
$(CC) $(CF) -c -o $@ $<
|
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
build/%.o: test/%.c
|
|
|
|
# compile test $@
|
|
|
|
@mkdir -p build
|
2022-01-19 20:06:41 -05:00
|
|
|
$(CC) $(CF) -c -o $@ $<
|
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
build/%.o: build/%.c
|
|
|
|
# compile generated $@
|
2022-01-19 20:06:41 -05:00
|
|
|
$(CC) $(CF) -c -o $@ $<
|
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
build/%.c: src/%.re_c.c
|
|
|
|
# https://re2c.org/ generate $@
|
|
|
|
@mkdir -p build
|
|
|
|
re2c -W --tags --conditions -o $@ $<
|
2022-01-19 20:06:41 -05:00
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
#doc/%.md: src/%.h
|
|
|
|
# # https://github.com/neil-edelman/cdoc documentation
|
|
|
|
# -cdoc -o $@ $<
|
2022-02-10 23:30:11 -05:00
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
.PHONY: clean release test
|
2022-01-19 20:06:41 -05:00
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
test: $(projects)
|
|
|
|
@for project in $(projects); do \
|
|
|
|
echo "\033[1;36m\033[1m*** Testing $$project ***\033[0m" ; \
|
|
|
|
$$project ; \
|
|
|
|
done
|
2022-01-19 20:06:41 -05:00
|
|
|
|
|
|
|
clean:
|
2022-12-27 02:31:08 -05:00
|
|
|
-rm -rf bin/ build/
|
2022-01-19 20:06:41 -05:00
|
|
|
|
2022-12-27 02:31:08 -05:00
|
|
|
#docs: $(docs)
|