commit 9c255c51733f553c653590a36aa089af89b18fd4
parent 0b36b80642e93ddbc0f6df08b5049ad4cb1d6cc0
Author: Louis Burda <quent.burda@gmail.com>
Date: Mon, 29 May 2023 13:42:24 +0200
Template build.jst for debug configuration
Diffstat:
5 files changed, 72 insertions(+), 49 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,5 +1,6 @@
compile_commands.json
build
+build.jst
.cache
vgcore*
.gdb_history
diff --git a/Makefile b/Makefile
@@ -10,9 +10,7 @@ else
CFLAGS += -O2
endif
-include common.mk
-
-all: $(LIBALLOC_SO) $(LIBALLOC_A) build/test
+all: build/liballoc.so build/liballoc.a build/test
clean:
rm -rf build
@@ -22,22 +20,22 @@ cleanall: clean
build:
mkdir build
-$(LIBALLOC_A): $(LIBALLOC_A_DEP) | build
- $(CC) -o build/tmp.o $(LIBALLOC_A_SRC) $(CFLAGS) -r
+build/liballoc.a: src/allocator.c | build
+ $(CC) -o build/tmp.o src/allocator.c $(CFLAGS) -r
objcopy --keep-global-symbols=liballoc.api build/tmp.o build/fixed.o
ar rcs $@ build/fixed.o
-$(LIBALLOC_SO): $(LIBALLOC_SO_DEP) | build
- $(CC) -o $@ $(LIBALLOC_SO_SRC) $(CFLAGS) \
+build/liballoc.so: src/allocator.c include/allocator.h | build
+ $(CC) -o $@ src/allocator.c $(CFLAGS) \
-shared -Wl,-version-script liballoc.lds
-build/test: src/test.c $(LIBALLOC_A) | build
+build/test: src/test.c build/liballoc.a | build
$(CC) -o $@ $^ -I include
install:
install -m755 include/allocator.h -t "$(DESTDIR)$(PREFIX)$(INCLDIR)"
- install -m755 $(LIBALLOC_A) -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
- install -m755 $(LIBALLOC_SO) -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
+ install -m755 build/liballoc.a -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
+ install -m755 build/liballoc.so -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
uninstall:
rm -f "$(DESTDIR)$(PREFIX)$(INCLDIR)/allocator.h"
diff --git a/build.jst b/build.jst
@@ -1,39 +0,0 @@
-cflags = -Wunused-function -Wunused-variable -Wconversion -Wformat
- -I include
-
-rule liba
- gcc -o $out.tmp.o $in $cflags -r
- objcopy --keep-global-symbols=liballoc.api $out.tmp.o $out.fixed.o
- ar rcs $out $out.fixed.o
- rm $out.tmp.o $out.fixed.o
-
-rule libso
- gcc -o $out $in $cflags -shared -Wl,-version-script liballoc.lds
-
-rule cc
- gcc -o $out $in $cflags
-
-rule mkdir
- mkdir $out
-
-target build
- mkdir
-
-target build/liballoc.a
- liba src/allocator.c | include/allocator.h build
-
-target build/liballoc.so
- libso src/allocator.c | include/allocator.h build
-
-target build/test
- cc src/test.c build/liballoc.a | build
-
-command clean
- rm -rf build
-
-command cleanall
- just clean
-
-command all
- just build/liballoc.a build/liballoc.so build/test
-
diff --git a/build.jst.tmpl b/build.jst.tmpl
@@ -0,0 +1,60 @@
+#default PREFIX /usr/local
+#default INCLDIR /include
+#default LIBDIR /lib
+#default CC gcc
+
+#ifdef DEBUG
+#define OPT_CFLAGS -Og -g
+#else
+#define OPT_CFLAGS -O2
+#endif
+
+cflags = -Wunused-function -Wunused-variable -Wconversion -Wformat
+ -I include #{OPT_CFLAGS} #{EXTRA_CFLAGS}
+
+rule liba
+ gcc -o $out.tmp.o $in $cflags -r
+ objcopy --keep-global-symbols=liballoc.api $out.tmp.o $out.fixed.o
+ ar rcs $out $out.fixed.o
+ rm $out.tmp.o $out.fixed.o
+
+rule libso
+ gcc -o $out $in $cflags -shared -Wl,-version-script liballoc.lds
+
+rule cc
+ gcc -o $out $in $cflags
+
+rule mkdir
+ mkdir $out
+
+target build
+ mkdir
+
+target build/liballoc.a
+ liba src/allocator.c | include/allocator.h build
+
+target build/liballoc.so
+ libso src/allocator.c | include/allocator.h build
+
+target build/test
+ cc src/test.c build/liballoc.a | build
+
+command clean
+ rm -rf build
+
+command cleanall
+ just clean
+
+command install
+ install -m755 build/liballoc.a -t "#{DESTDIR}#{PREFIX}#{LIBDIR}"
+ install -m755 build/liballoc.so -t "#{DESTDIR}#{PREFIX}#{LIBDIR}"
+ install -m755 include/allocator.h -t "#{DESTDIR}#{PREFIX}#{INCLDIR}"
+
+command uninstall
+ rm -f "#{DESTDIR}#{PREFIX}#{LIBDIR}/liballoc.a"
+ rm -f "#{DESTDIR}#{PREFIX}#{LIBDIR}/liballoc.so"
+ rm -f "#{DESTDIR}#{PREFIX}#{INCLDIR}/allocator.h"
+
+command all
+ just build/liballoc.a build/liballoc.so build/test
+
diff --git a/configure b/configure
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+tmpl "$@" build.jst.tmpl > build.jst