commit 5b667362498ed4cdc6ad5a9036834c6ab1bed4e9
parent 7bb4bd65d7a11bbf4ad4e085aa2a32d5028585dd
Author: Louis Burda <quent.burda@gmail.com>
Date: Sun, 30 Apr 2023 14:41:27 +0200
Expose internal dependencies through common.mk
Diffstat:
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
@@ -4,7 +4,9 @@ INCLDIR ?= /include
CFLAGS = -I include
-all: build/liballoc.so build/liballoc.a build/test
+include common.mk
+
+all: $(LIBALLOC_SO) $(LIBALLOC_A) build/test
clean:
rm -rf build
@@ -12,22 +14,22 @@ clean:
build:
mkdir build
-build/liballoc.a: src/allocator.c include/allocator.h | build
- $(CC) -o build/tmp.o src/allocator.c $(CFLAGS) -r
+$(LIBALLOC_A): $(LIBALLOC_A_DEP) | build
+ $(CC) -o build/tmp.o $(LIBALLOC_A_SRC) $(CFLAGS) -r
objcopy --keep-global-symbols=liballoc.api build/tmp.o build/fixed.o
ar rcs $@ build/fixed.o
-build/liballoc.so: src/allocator.c include/allocator.h | build
- $(CC) -o $@ src/allocator.c $(CFLAGS) \
+$(LIBALLOC_SO): $(LIBALLOC_SO_DEP) | build
+ $(CC) -o $@ $(LIBALLOC_SO_SRC) $(CFLAGS) \
-shared -Wl,-version-script liballoc.lds
-build/test: src/test.c build/liballoc.a | build
+build/test: src/test.c $(LIBALLOC_A) | build
$(CC) -o $@ $^ -I include
install:
install -m755 include/allocator.h -t "$(DESTDIR)$(PREFIX)$(INCLDIR)"
- install -m755 build/liballoc.a -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
- install -m755 build/liballoc.so -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
+ install -m755 $(LIBALLOC_A) -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
+ install -m755 $(LIBALLOC_SO) -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
uninstall:
rm -f "$(DESTDIR)$(PREFIX)$(INCLDIR)/allocator.h"
diff --git a/common.mk b/common.mk
@@ -0,0 +1,7 @@
+LIBALLOC_A = build/liballoc.a
+LIBALLOC_A_SRC = src/allocator.c
+LIBALLOC_A_DEP = $(LIBALLOC_A_SRC) include/allocator.h
+
+LIBALLOC_SO = build/liballoc.so
+LIBALLOC_SO_SRC = src/allocator.c
+LIBALLOC_SO_DEP = $(LIBALLOC_SO_SRC) include/allocator.h