aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-12-21 15:27:05 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-12-21 15:27:05 -0500
commit63e6d52f1e1ad9ba3e5dd453115abfc2f8418fc6 (patch)
treec5ea296fbc76369984ce2e04323b350bbe68d492
parent9e8574f44c22615de09c133eeb9f60cccfc5aed3 (diff)
Rework makefile to simplify things
-rw-r--r--Makefile101
l---------build/include/tomo1
-rw-r--r--link_versions.sh5
-rwxr-xr-xlocal-tomo6
4 files changed, 64 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index 32192554..342fec8e 100644
--- a/Makefile
+++ b/Makefile
@@ -107,49 +107,81 @@ else
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 $@
+headers := $(wildcard src/stdlib/*.h)
+build_headers := $(patsubst src/stdlib/%.h, build/$(TOMO_VERSION)/include/tomo@$(TOMO_VERSION)/%.h, $(headers))
-version:
- @echo $(TOMO_VERSION)
+# find all man pages
+manpages := $(wildcard man/*/*)
-check-c-compiler:
- @$(DEFAULT_C_COMPILER) -v 2>/dev/null >/dev/null \
- || { printf '\033[31;1m%s\033[m\n' "You have set your DEFAULT_C_COMPILER to $(DEFAULT_C_COMPILER) in your config.mk, but I can't run it!"; exit 1; }
+# generate corresponding build paths with .gz
+build_manpages := $(foreach f,$(manpages),build/$(TOMO_VERSION)/$(f).gz)
-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; }
+# Ensure directories exist
+dirs := build/$(TOMO_VERSION)/include/tomo@$(TOMO_VERSION) \
+ build/$(TOMO_VERSION)/lib \
+ build/$(TOMO_VERSION)/lib/tomo@$(TOMO_VERSION) \
+ build/$(TOMO_VERSION)/bin \
+ build/$(TOMO_VERSION)/man/man1 \
+ build/$(TOMO_VERSION)/man/man3 \
+ build/$(TOMO_VERSION)/share/licenses/tomo@$(TOMO_VERSION)
+
+$(dirs):
+ mkdir -p $@
+
+# Rule for copying headers
+build/$(TOMO_VERSION)/include/tomo@$(TOMO_VERSION)%.h: src/stdlib/%.h | build/$(TOMO_VERSION)/include/tomo@$(TOMO_VERSION)
+ cp $< $@
+
+# Rule for gzipping man pages
+build/$(TOMO_VERSION)/man/man1/%.gz: man/man1/% | build/$(TOMO_VERSION)/man/man1
+ gzip -c $< > $@
+build/$(TOMO_VERSION)/man/man3/%.gz: man/man3/% | build/$(TOMO_VERSION)/man/man3
+ gzip -c $< > $@
-build/bin/$(EXE_FILE): $(STDLIB_OBJS) $(COMPILER_OBJS)
- @mkdir -p build/bin
+build/$(TOMO_VERSION)/bin/tomo: build/$(TOMO_VERSION)/bin/tomo@$(TOMO_VERSION) | build/$(TOMO_VERSION)/bin
+ ln -sf tomo@$(TOMO_VERSION) $@
+
+build/$(TOMO_VERSION)/bin/$(EXE_FILE): $(STDLIB_OBJS) $(COMPILER_OBJS) | build/$(TOMO_VERSION)/bin
@$(ECHO) $(CC) $(CFLAGS_PLACEHOLDER) $(LDFLAGS) $^ $(LDLIBS) -o $@
@$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
-build/lib/$(LIB_FILE): $(STDLIB_OBJS)
- @mkdir -p build/lib
+build/$(TOMO_VERSION)/lib/$(LIB_FILE): $(STDLIB_OBJS) | build/$(TOMO_VERSION)/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)
+build/$(TOMO_VERSION)/lib/$(AR_FILE): $(STDLIB_OBJS) | build/$(TOMO_VERSION)/lib
+ ar -rcs $@ $^
+
+build/$(TOMO_VERSION)/lib/tomo@$(TOMO_VERSION)/modules.ini: modules/core.ini modules/examples.ini | build/$(TOMO_VERSION)/lib/tomo@$(TOMO_VERSION)
@cat $^ > $@
-build/lib/$(AR_FILE): $(STDLIB_OBJS)
- @mkdir -p build/lib
- ar -rcs $@ $^
+build/$(TOMO_VERSION)/share/licenses/tomo@$(TOMO_VERSION)/LICENSE.md: LICENSE.md | build/$(TOMO_VERSION)/share/licenses/tomo@$(TOMO_VERSION)
+ cp $< $@
+
+build: build/$(TOMO_VERSION)/bin/tomo build/$(TOMO_VERSION)/bin/tomo@$(TOMO_VERSION) build/$(TOMO_VERSION)/lib/$(LIB_FILE) \
+ build/$(TOMO_VERSION)/lib/$(AR_FILE) build/$(TOMO_VERSION)/lib/tomo@$(TOMO_VERSION)/modules.ini \
+ build/$(TOMO_VERSION)/share/licenses/tomo@$(TOMO_VERSION)/LICENSE.md $(build_headers) $(build_manpages)
+
+version:
+ @echo $(TOMO_VERSION)
+
+check-c-compiler:
+ @$(DEFAULT_C_COMPILER) -v 2>/dev/null >/dev/null \
+ || { printf '\033[31;1m%s\033[m\n' "You have set your DEFAULT_C_COMPILER to $(DEFAULT_C_COMPILER) in your config.mk, but I can't run it!"; exit 1; }
+
+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; }
tags:
ctags src/*.{c,h} src/stdlib/*.{c,h} src/compile/*.{c,h} src/parse/*.{c,h} src/formatter/*.{c,h}
@@ -181,7 +213,7 @@ 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 +225,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 +260,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 +273,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/$(TOMO_VERSION)/* $(PREFIX)/
install: install-files
@@ -260,11 +282,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
diff --git a/build/include/tomo b/build/include/tomo
deleted file mode 120000
index 82be04c8..00000000
--- a/build/include/tomo
+++ /dev/null
@@ -1 +0,0 @@
-../../src/stdlib \ No newline at end of file
diff --git a/link_versions.sh b/link_versions.sh
deleted file mode 100644
index 8dadbb52..00000000
--- a/link_versions.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-TOMO_PREFIX="$(awk -F= '/PREFIX/{print $2}' config.mk)"
-cd "$TOMO_PREFIX/bin"
-top_version="$(printf '%s\n' 'tomo@'* | sort -r | head -1)"
-ln -fs "$top_version" tomo
diff --git a/local-tomo b/local-tomo
index 76864837..74143604 100755
--- a/local-tomo
+++ b/local-tomo
@@ -1,11 +1,11 @@
#!/bin/sh
version=$(awk '/^## / {print $2; exit}' CHANGES.md)
here="$(realpath "$(dirname "$0")")"
-if [ ! -e "$here/build/bin/tomo@$version" ]; then
+if [ ! -e "$here/dist/$version/bin/tomo@$version" ]; then
echo "Tomo hasn't been compiled yet! Run \`make\` to compile it!"
exit 1;
fi
-PATH="$here/build/bin${PATH:+:$PATH}" \
-TOMO_PATH="$here/build" \
+PATH="$here/dist/$version/bin${PATH:+:$PATH}" \
+TOMO_PATH="$here/dist/$version" \
tomo@"$version" "$@"