diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 120 |
1 files changed, 58 insertions, 62 deletions
@@ -82,13 +82,12 @@ G=-ggdb O=-O3 # Note: older versions of Make have buggy behavior with hash marks inside strings, so this ugly code is necessary: TOMO_VERSION=$(shell awk 'BEGIN{hashes=sprintf("%c%c",35,35)} $$1==hashes {print $$2; exit}' CHANGES.md) -GIT_VERSION=$(shell git log -1 --pretty=format:"%as_%h") -CFLAGS=$(CCONFIG) $(INCLUDE_DIRS) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) $(LTO) \ - -DTOMO_INSTALL='"$(PREFIX)"' -DSUDO='"$(SUDO)"' -DDEFAULT_C_COMPILER='"$(DEFAULT_C_COMPILER)"' \ - -DTOMO_VERSION='"$(TOMO_VERSION)"' -DGIT_VERSION='"$(GIT_VERSION)"' +GIT_VERSION=$(shell git log -1 --pretty=format:"%as_%h" 2>/dev/null || echo "unknown") +CFLAGS+=$(CCONFIG) $(INCLUDE_DIRS) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) $(LTO) \ + -DSUDO='"$(SUDO)"' -DDEFAULT_C_COMPILER='"$(DEFAULT_C_COMPILER)"' \ + -DGIT_VERSION='"$(GIT_VERSION)"' -ffunction-sections -fdata-sections CFLAGS_PLACEHOLDER="$$(printf '\033[2m<flags...>\033[m\n')" LDLIBS=-lgc -lm -lunistring -lgmp -LIBTOMO_FLAGS=-shared ifeq ($(OS),OpenBSD) LDLIBS += -lexecinfo @@ -100,27 +99,64 @@ AR_FILE=libtomo@$(TOMO_VERSION).a ifeq ($(OS),Darwin) INCLUDE_DIRS += -I/opt/homebrew/include LDFLAGS += -L/opt/homebrew/lib - LIB_FILE=libtomo@$(TOMO_VERSION).dylib - LIBTOMO_FLAGS += -Wl,-install_name,@rpath/libtomo@$(TOMO_VERSION).dylib -else - LIB_FILE=libtomo@$(TOMO_VERSION).so - LIBTOMO_FLAGS += -Wl,-soname,libtomo@$(TOMO_VERSION).so endif EXE_FILE=tomo@$(TOMO_VERSION) -MODULES_FILE=build/lib/tomo@$(TOMO_VERSION)/modules.ini COMPILER_OBJS=$(patsubst %.c,%.o,$(wildcard src/*.c src/compile/*.c src/parse/*.c src/formatter/*.c)) STDLIB_OBJS=$(patsubst %.c,%.o,$(wildcard src/stdlib/*.c)) TESTS=$(patsubst test/%.tm,test/results/%.tm.testresult,$(wildcard test/[!_]*.tm)) API_YAML=$(wildcard api/*.yaml) API_MD=$(patsubst %.yaml,%.md,$(API_YAML)) -INCLUDE_SYMLINK=build/include/tomo@$(TOMO_VERSION) -all: config.mk check-c-compiler check-libs $(INCLUDE_SYMLINK) build/lib/$(LIB_FILE) build/lib/$(AR_FILE) $(MODULES_FILE) build/bin/$(EXE_FILE) +all: config.mk check-c-compiler check-libs build @$(ECHO) "All done!" -$(INCLUDE_SYMLINK): - ln -s ../../src/stdlib $@ +BUILD_DIR=build/tomo@$(TOMO_VERSION) +headers := $(wildcard src/stdlib/*.h) +build_headers := $(patsubst src/stdlib/%.h, $(BUILD_DIR)/include/tomo@$(TOMO_VERSION)/%.h, $(headers)) + +# generate corresponding build paths with .gz +build_manpages := $(patsubst %,$(BUILD_DIR)/%.gz,$(wildcard man/man*/*)) + +# Ensure directories exist +dirs := $(BUILD_DIR)/include/tomo@$(TOMO_VERSION) \ + $(BUILD_DIR)/lib \ + $(BUILD_DIR)/lib/tomo@$(TOMO_VERSION) \ + $(BUILD_DIR)/bin \ + $(BUILD_DIR)/man/man1 \ + $(BUILD_DIR)/man/man3 \ + $(BUILD_DIR)/share/licenses/tomo@$(TOMO_VERSION) + +$(dirs): + mkdir -p $@ + +# Rule for copying headers +$(BUILD_DIR)/include/tomo@$(TOMO_VERSION)%.h: src/stdlib/%.h | $(BUILD_DIR)/include/tomo@$(TOMO_VERSION) + cp $< $@ + +# Rule for gzipping man pages +$(BUILD_DIR)/man/%.gz: man/% | $(BUILD_DIR)/man/man1 $(BUILD_DIR)/man/man3 + gzip -c $< > $@ + +$(BUILD_DIR)/bin/tomo: $(BUILD_DIR)/bin/tomo@$(TOMO_VERSION) | $(BUILD_DIR)/bin + ln -sf tomo@$(TOMO_VERSION) $@ + +$(BUILD_DIR)/bin/$(EXE_FILE): $(STDLIB_OBJS) $(COMPILER_OBJS) | $(BUILD_DIR)/bin + @$(ECHO) $(CC) $(CFLAGS_PLACEHOLDER) $(LDFLAGS) $^ $(LDLIBS) -o $@ + @$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(BUILD_DIR)/lib/$(AR_FILE): $(STDLIB_OBJS) | $(BUILD_DIR)/lib + ar -rcs $@ $^ + +$(BUILD_DIR)/lib/tomo@$(TOMO_VERSION)/modules.ini: modules/core.ini modules/examples.ini | $(BUILD_DIR)/lib/tomo@$(TOMO_VERSION) + @cat $^ > $@ + +$(BUILD_DIR)/share/licenses/tomo@$(TOMO_VERSION)/LICENSE.md: LICENSE.md | $(BUILD_DIR)/share/licenses/tomo@$(TOMO_VERSION) + cp $< $@ + +build: $(BUILD_DIR)/bin/tomo $(BUILD_DIR)/bin/tomo@$(TOMO_VERSION) \ + $(BUILD_DIR)/lib/$(AR_FILE) $(BUILD_DIR)/lib/tomo@$(TOMO_VERSION)/modules.ini \ + $(BUILD_DIR)/share/licenses/tomo@$(TOMO_VERSION)/LICENSE.md $(build_headers) $(build_manpages) version: @echo $(TOMO_VERSION) @@ -133,24 +169,6 @@ check-libs: check-c-compiler @echo 'int main() { return 0; }' | $(DEFAULT_C_COMPILER) $(LDFLAGS) $(LDLIBS) -x c - -o /dev/null 2>/dev/null >/dev/null \ || { printf '\033[31;1m%s\033[m\n' "I expected to find the following libraries on your system, but I can't find them: $(LDLIBS)"; exit 1; } -build/bin/$(EXE_FILE): $(STDLIB_OBJS) $(COMPILER_OBJS) - @mkdir -p build/bin - @$(ECHO) $(CC) $(CFLAGS_PLACEHOLDER) $(LDFLAGS) $^ $(LDLIBS) -o $@ - @$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ - -build/lib/$(LIB_FILE): $(STDLIB_OBJS) - @mkdir -p build/lib - @$(ECHO) $(CC) $^ $(CFLAGS_PLACEHOLDER) $(OSFLAGS) $(LDFLAGS) $(LDLIBS) $(LIBTOMO_FLAGS) -o $@ - @$(CC) $^ $(CFLAGS) $(OSFLAGS) $(LDFLAGS) $(LDLIBS) $(LIBTOMO_FLAGS) -o $@ - -$(MODULES_FILE): modules/core.ini modules/examples.ini - @mkdir -p build/lib/tomo@$(TOMO_VERSION) - @cat $^ > $@ - -build/lib/$(AR_FILE): $(STDLIB_OBJS) - @mkdir -p build/lib - ar -rcs $@ $^ - tags: ctags src/*.{c,h} src/stdlib/*.{c,h} src/compile/*.{c,h} src/parse/*.{c,h} src/formatter/*.{c,h} @@ -167,21 +185,10 @@ src/stdlib/int64.o src/stdlib/int32.o src/stdlib/int16.o src/stdlib/int8.o: src/ # Float implementations depend on the shared header: src/stdlib/float32.o src/stdlib/float64.o: src/stdlib/floatX.c.h src/stdlib/floatX.h -# These files all depend on the current tomo version: -src/compile/files.o src/compile/headers.o src/compile/statements.o src/config.o src/environment.o \ - src/modules.o src/stdlib/stacktrace.o src/stdlib/stdlib.o src/tomo.o src/typecheck.o: CHANGES.md - -src/changes.md.h: CHANGES.md - @$(ECHO) "Embedding changes.md" - xxd -i $< > $@ - -# The main Tomo executable embeds the changelog: -src/tomo.o: src/changes.md.h - %: %.tm ./local-tomo -e $< -test/results/%.tm.testresult: test/%.tm build/bin/$(EXE_FILE) +test/results/%.tm.testresult: test/%.tm build @mkdir -p test/results @printf '\033[33;1;4m%s\033[m\n' $< @if ! COLOR=1 LC_ALL=C ./local-tomo -O 1 $< 2>&1 | tee $@; then \ @@ -193,7 +200,7 @@ test: $(TESTS) @printf '\033[32;7m ALL TESTS PASSED! \033[m\n' clean: - rm -rf build/{lib,bin}/* $(COMPILER_OBJS) $(STDLIB_OBJS) test/*.tm.testresult test/.build lib/*/.build examples/.build examples/*/.build + rm -rf build/* $(COMPILER_OBJS) $(STDLIB_OBJS) test/*.tm.testresult test/.build lib/*/.build examples/.build examples/*/.build %: %.md pandoc --lua-filter=docs/.pandoc/bold-code.lua -s $< -t man -o $@ @@ -228,7 +235,7 @@ check-utilities: check-c-compiler @which debugedit 2>/dev/null >/dev/null \ || printf '\033[33;1m%s\033[m\n' "I couldn't find 'debugedit' on your system! Try installing the package 'debugedit' with your package manager. (It's not required though)" -install-files: $(INCLUDE_SYMLINK) build/bin/$(EXE_FILE) build/lib/$(LIB_FILE) build/lib/$(AR_FILE) $(MODULES_FILE) check-utilities +install-files: build check-utilities @if ! echo "$$PATH" | tr ':' '\n' | grep -qx "$(PREFIX)/bin"; then \ echo $$PATH; \ printf "\033[31;1mError: '$(PREFIX)/bin' is not in your \$$PATH variable!\033[m\n" >&2; \ @@ -241,17 +248,7 @@ install-files: $(INCLUDE_SYMLINK) build/bin/$(EXE_FILE) build/lib/$(LIB_FILE) bu $(SUDO) -u $(OWNER) $(MAKE) install-files; \ exit 0; \ fi; \ - mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/man/man3" "$(PREFIX)/bin" \ - "$(PREFIX)/include/tomo@$(TOMO_VERSION)" "$(PREFIX)/lib" "$(PREFIX)/lib/tomo@$(TOMO_VERSION)" "$(PREFIX)/share/licenses/tomo@$(TOMO_VERSION)"; \ - cp src/stdlib/*.h "$(PREFIX)/include/tomo@$(TOMO_VERSION)/"; \ - cp build/lib/$(LIB_FILE) build/lib/$(AR_FILE) "$(PREFIX)/lib/"; \ - cp $(MODULES_FILE) "$(PREFIX)/lib/tomo@$(TOMO_VERSION)"; \ - cp LICENSE.md "$(PREFIX)/share/licenses/tomo@$(TOMO_VERSION)"; \ - rm -f "$(PREFIX)/bin/$(EXE_FILE)"; \ - cp build/bin/$(EXE_FILE) "$(PREFIX)/bin/"; \ - cp man/man1/* "$(PREFIX)/man/man1/"; \ - cp man/man3/* "$(PREFIX)/man/man3/"; \ - sh link_versions.sh + cp -R $(BUILD_DIR)/* $(PREFIX)/ install: install-files @@ -260,11 +257,10 @@ uninstall: $(SUDO) -u $(OWNER) $(MAKE) uninstall; \ exit 0; \ fi; \ - rm -rvf "$(PREFIX)/bin/tomo" "$(PREFIX)/bin/tomo"[0-9]* "$(PREFIX)/bin/tomo_v"* "$(PREFIX)/include/tomo_v"* \ - "$(PREFIX)/lib/libtomo_v*" "$(PREFIX)/lib/tomo@$(TOMO_VERSION)" "$(PREFIX)/share/licenses/tomo@$(TOMO_VERSION)"; \ - sh link_versions.sh + rm -rvf "$(PREFIX)/bin/tomo" "$(PREFIX)/bin/tomo"* "$(PREFIX)/include/tomo"* \ + "$(PREFIX)/lib/libtomo@"* "$(PREFIX)/lib/tomo@"* "$(PREFIX)/share/licenses/tomo@"*; \ endif .SUFFIXES: -.PHONY: all clean install install-files uninstall test tags core-libs examples deps check-utilities check-c-compiler check-libs version +.PHONY: all build clean install install-files uninstall test tags core-libs examples deps check-utilities check-c-compiler check-libs version |
