commit 61bc2e57f2ea34e377d18719e7bce170fe8a91e2
parent 01503b01abb2d8c0a89d0207b51080a2303647dd
Author: finwo <finwo@pm.me>
Date: Wed, 7 Oct 2026 00:21:15 +0200
Build structure
Diffstat:
7 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/.editorconfig b/.editorconfig
@@ -0,0 +1,14 @@
+# 2d0e4a3f-ac19-430c-bf1b-46c68651ce21
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+charset = utf-8
+indent_size = 2
+indent_style = space
+trim_trailing_whitespace = true
+
+[Makefile*]
+indent_style = tab
+
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,3 @@
+/build/
+/lib/
+*.o
diff --git a/Makefile b/Makefile
@@ -0,0 +1,40 @@
+TARGET:=linux-glibc-$(shell uname -m)
+
+BIN:=sfinx
+
+FIND:=$(shell command -v gfind find)
+
+WATCH?=
+WATCH+=$(shell $(FIND) src -type f -name '*.c')
+WATCH+=$(shell $(FIND) src -type f -name '*.h')
+
+.PHONY: default
+default: build/${TARGET}/${BIN}
+
+build/${TARGET}/${BIN}: build/${TARGET} $(WATCH)
+ cd build/${TARGET} && dep install
+ $(MAKE) --directory build/${TARGET} TARGET=${TARGET}
+
+build/${TARGET}: $(WATCH)
+ mkdir -p build/${TARGET}
+ cp -rT src/ build/${TARGET}/src
+ cp -rT target/common/ build/${TARGET}
+ cp -rT target/${TARGET}/ build/${TARGET}
+
+.PHONY: targets
+targets:
+ @ls -1 target | grep -v '^common$$'
+
+.PHONY: clean
+clean:
+ rm -rf build
+
+# Never let the catch-all try to rebuild the makefiles themselves
+Makefile: ;
+
+# Forward any other goal verbatim into the assembled target tree
+.PHONY: FORCE
+FORCE:
+%: build/${TARGET} FORCE
+ cd build/${TARGET} && dep install
+ $(MAKE) --directory build/${TARGET} TARGET=${TARGET} $@
diff --git a/src/main.c b/src/main.c
@@ -0,0 +1,3 @@
+int main() {
+ return 42;
+}
diff --git a/target/common/.dep b/target/common/.dep
@@ -0,0 +1 @@
+mjosaarinen/tiny_sha3 https://git.finwo.net/misc/dep-repository/archives/heads/pkg/mjosaarinen/tiny_sha3.tar.gz
diff --git a/target/common/Makefile b/target/common/Makefile
@@ -0,0 +1,45 @@
+TARGET?=
+
+BIN=sfinx
+
+SRC:=
+SRC+=$(wildcard src/*.c)
+SRC+=$(wildcard src/*/*.c)
+SRC+=$(wildcard src/*/*/*.c)
+
+CFLAGS?=-Wall -Wextra -O2
+LDFLAGS?=
+
+# Drop unreferenced code: dependencies export whole libraries, of which we use a part
+CFLAGS +=-ffunction-sections -fdata-sections
+LDFLAGS+=-Wl,--gc-sections
+
+INCLUDES:=
+INCLUDES+=-I src
+
+include lib/.dep/config.mk
+
+# Target-specific overrides, optional.
+# Supplied by target/<target>/Makefile.target
+-include Makefile.target
+
+CFLAGS+=$(INCLUDES)
+
+OBJ:=$(SRC:.c=.o)
+
+.PHONY: default
+default: $(BIN)
+
+%.o: %.c $(LIBS)
+ $(CC) $(CFLAGS) $(@:.o=.c) -D__NAME=\"$(BIN)\" -D__TARGET=\"$(TARGET)\" -c -o $@
+
+$(BIN): $(OBJ)
+ $(CC) $(CFLAGS) $(OBJ) $(LDFLAGS) -o $@
+
+.PHONY: clean
+clean:
+ rm -f $(OBJ) $(BIN)
+
+.PHONY: install
+install: $(BIN)
+ install -Dm0755 $(BIN) $(DESTDIR)/usr/bin/$(BIN)
diff --git a/target/linux-glibc-x86_64/.gitkeep b/target/linux-glibc-x86_64/.gitkeep