From ea6f13397ec0063b91a8e6cb69b88b7d0b456887 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Fri, 13 Feb 2026 16:34:02 +0100 Subject: [PATCH] Generic lib.mk makefile for building libraries --- liballoc/Makefile | 34 ++++------------------------------ libmsl/Makefile | 34 ++++------------------------------ libprocess/Makefile | 35 +++++------------------------------ libstring/Makefile | 34 ++++------------------------------ libterminal/Makefile | 34 ++++------------------------------ make/lib.mk | 33 +++++++++++++++++++++++++++++++++ make/ufuncs.mk | 4 ++++ 7 files changed, 58 insertions(+), 150 deletions(-) create mode 100644 make/lib.mk diff --git a/liballoc/Makefile b/liballoc/Makefile index 570631f..db5f2c8 100644 --- a/liballoc/Makefile +++ b/liballoc/Makefile @@ -1,33 +1,7 @@ -cc := clang -o := -c := -cflags := -isystem . -isystem ../libmsl -buildtype ?= release +include ../make/ufuncs.mk -include src.mk -include ../generic/flags.mk -include ../$(platform)/flags.mk +$(eval $(call add_include,libmsl)) -all: build/liballoc.a +libname := liballoc -build/liballoc.a: $(o) - llvm-ar rcs $@ $^ - -%.o: %.c - $(cc) -c -o $@ $(cflags) $< - -%.o: %.S - $(cc) -c -o $@ $(cflags) $< - -clean: - rm -f $(o) build/liballoc.a - -format: - clang-format -i $$(git ls-files '*.c' '*.h') - -docs: - clang-doc --format=md --output docs -p . $$(git ls-files '*.h') - mkdir -p ../docs/libs/liballoc - cp ./docs/GlobalNamespace/*.md ../docs/libs/liballoc - -.PHONY: all clean format +include ../make/lib.mk diff --git a/libmsl/Makefile b/libmsl/Makefile index 88ba85b..d25bfa0 100644 --- a/libmsl/Makefile +++ b/libmsl/Makefile @@ -1,33 +1,7 @@ -cc := clang -o := -c := -cflags := -isystem . -isystem ../liballoc -buildtype ?= release +include ../make/ufuncs.mk -include src.mk -include ../generic/flags.mk -include ../$(platform)/flags.mk +$(eval $(call add_include,liballoc)) -all: build/libmsl.a +libname := libmsl -build/libmsl.a: $(o) - llvm-ar rcs $@ $^ - -%.o: %.c - $(cc) -c -o $@ $(cflags) $< - -%.o: %.S - $(cc) -c -o $@ $(cflags) $< - -clean: - rm -f $(o) build/libmsl.a - -format: - clang-format -i $$(git ls-files '*.c' '*.h') - -docs: - clang-doc --format=md --output docs -p . $$(git ls-files '*.h') - mkdir -p ../docs/libs/libmsl - cp ./docs/GlobalNamespace/*.md ../docs/libs/libmsl - -.PHONY: all clean format +include ../make/lib.mk diff --git a/libprocess/Makefile b/libprocess/Makefile index e571226..c9cfdc9 100644 --- a/libprocess/Makefile +++ b/libprocess/Makefile @@ -1,33 +1,8 @@ -cc := clang -o := -c := -cflags := -isystem . -isystem ../libmsl -isystem ../liballoc -buildtype ?= release +include ../make/ufuncs.mk -include src.mk -include ../generic/flags.mk -include ../$(platform)/flags.mk +$(eval $(call add_include,libmsl)) +$(eval $(call add_include,liballoc)) -all: build/libprocess.a +libname := libprocess -build/libprocess.a: $(o) - llvm-ar rcs $@ $^ - -%.o: %.c - $(cc) -c -o $@ $(cflags) $< - -%.o: %.S - $(cc) -c -o $@ $(cflags) $< - -clean: - rm -f $(o) build/libprocess.a - -format: - clang-format -i $$(git ls-files '*.c' '*.h') - -docs: - clang-doc --format=md --output docs -p . $$(git ls-files '*.h') - mkdir -p ../docs/libs/libprocess - cp ./docs/GlobalNamespace/*.md ../docs/libs/libprocess - -.PHONY: all clean format +include ../make/lib.mk diff --git a/libstring/Makefile b/libstring/Makefile index 047456b..67bdb47 100644 --- a/libstring/Makefile +++ b/libstring/Makefile @@ -1,33 +1,7 @@ -cc := clang -o := -c := -cflags := -isystem . -isystem ../libmsl -buildtype ?= release +include ../make/ufuncs.mk -include src.mk -include ../generic/flags.mk -include ../$(platform)/flags.mk +$(eval $(call add_include,libmsl)) -all: build/libstring.a +libname := libstring -build/libstring.a: $(o) - llvm-ar rcs $@ $^ - -%.o: %.c - $(cc) -c -o $@ $(cflags) $< - -%.o: %.S - $(cc) -c -o $@ $(cflags) $< - -clean: - rm -f $(o) build/libstring.a - -format: - clang-format -i $$(git ls-files '*.c' '*.h') - -docs: - clang-doc --format=md --output docs -p . $$(git ls-files '*.h') - mkdir -p ../docs/libs/libstring - cp ./docs/GlobalNamespace/*.md ../docs/libs/libstring - -.PHONY: all clean format +include ../make/lib.mk diff --git a/libterminal/Makefile b/libterminal/Makefile index 7429b87..687e2f5 100644 --- a/libterminal/Makefile +++ b/libterminal/Makefile @@ -1,33 +1,7 @@ -cc := clang -o := -c := -cflags := -isystem . -isystem ../libmsl -buildtype ?= release +include ../make/ufuncs.mk -include src.mk -include ../generic/flags.mk -include ../$(platform)/flags.mk +$(eval $(call add_include,libmsl)) -all: build/libterminal.a +libname := libterminal -build/libterminal.a: $(o) - llvm-ar rcs $@ $^ - -%.o: %.c - $(cc) -c -o $@ $(cflags) $< - -%.o: %.S - $(cc) -c -o $@ $(cflags) $< - -clean: - rm -f $(o) build/libterminal.a - -format: - clang-format -i $$(git ls-files '*.c' '*.h') - -docs: - clang-doc --format=md --output docs -p . $$(git ls-files '*.h') - mkdir -p ../docs/libs/libterminal - cp ./docs/GlobalNamespace/*.md ../docs/libs/libterminal - -.PHONY: all clean format +include ../make/lib.mk diff --git a/make/lib.mk b/make/lib.mk new file mode 100644 index 0000000..cf49bb8 --- /dev/null +++ b/make/lib.mk @@ -0,0 +1,33 @@ +cc := clang +o := +c := +cflags += -isystem . +buildtype ?= release + +include src.mk +include ../generic/flags.mk +include ../$(platform)/flags.mk + +all: build/$(libname).a + +build/$(libname).a: $(o) + llvm-ar rcs $@ $^ + +%.o: %.c + $(cc) -c -o $@ $(cflags) $< + +%.o: %.S + $(cc) -c -o $@ $(cflags) $< + +clean: + rm -f $(o) build/$(libname).a + +format: + clang-format -i $$(git ls-files '*.c' '*.h') + +docs: + clang-doc --format=md --output docs -p . $$(git ls-files '*.h') + mkdir -p ../docs/libs/$(libname) + cp ./docs/GlobalNamespace/*.md ../docs/libs/$(libname) + +.PHONY: all clean format diff --git a/make/ufuncs.mk b/make/ufuncs.mk index c9f779d..0030e0f 100644 --- a/make/ufuncs.mk +++ b/make/ufuncs.mk @@ -2,3 +2,7 @@ define add_lib ldflags += -L ../$(1)/build -l:$(1).a cflags += -isystem ../$(1) endef + +define add_include + cflags += -isystem ../$(1) +endef