commit: f94e39cfffc9000ccec602ac83da0326dd8095be
parent f91442142970ef63080e4cdc856341a9298855d6
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 14 Dec 2024 05:54:22 +0100
Add pkg-config, static & shared targets
Diffstat:
3 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,4 +1,7 @@
# Copyright © 2024 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
# SPDX-License-Identifier: MIT
-/test-error
-\ No newline at end of file
+/test-error
+/error.o
+/liberror.a
+/liberror.so
diff --git a/Makefile b/Makefile
@@ -2,12 +2,39 @@
# SPDX-License-Identifier: MIT
PREFIX ?= /usr
+LIBDIR ?= ${PREFIX}/lib
-all:
+PKG_CONFIG_DIR = ${LIBDIR}/pkgconfig/
-test-error: test-error.c error.c error.h
- ${CC} ${CFLAGS} -o test-error test-error.c error.c ${LDFLAGS} ${LDSTATIC}
+all: liberror.so liberror.a
+
+error.o: error.c error.h
+ ${CC} ${CFLAGS} -c -o error.o error.c
+
+test-error: test-error.c error.o
+ ${CC} ${CFLAGS} -o test-error test-error.c error.o ${LDFLAGS} ${LDSTATIC}
+
+liberror.so: error.o
+ ${CC} ${CFLAGS} -shared -o liberror.so error.o ${LDFLAGS}
+
+liberror.a: error.o
+ ${AR} rc liberror.a error.o
+
+install-shared: install liberror.so
+ mkdir -p ${DESTDIR}${LIBDIR}/
+ cp -p liberror.so ${DESTDIR}${LIBDIR}/
+
+install-static: install liberror.a
+ mkdir -p ${DESTDIR}${LIBDIR}/
+ cp -p liberror.a ${DESTDIR}${LIBDIR}/
install:
mkdir -p ${DESTDIR}${PREFIX}/include
cp error.h ${DESTDIR}${PREFIX}/include/error.h
+ mkdir -p ${DESTDIR}${PKG_CONFIG_DIR}/
+ sed -e 's;@PREFIX@;${PREFIX};' -e 's;@LIBDIR@;${LIBDIR};' error-standalone.pc.in > ${DESTDIR}${PKG_CONFIG_DIR}/error-standalone.pc
+
+clean:
+ rm -f error.o liberror.so liberror.a
+
+.PHONY: install-shared install-static install clean
diff --git a/error-standalone.pc.in b/error-standalone.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=@LIBDIR@
+includedir=${prefix}/include
+
+Name: error-standalone
+Description: standalone <error.h> implementation intended for musl
+Version: 2.0
+Libs: -L${libdir} -lerror
+Cflags: -I${includedir}