aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-02-07 12:34:44 +0100
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-02-07 12:34:44 +0100
commit479b2ee8e0cc52c3e76c7c09d0dfa5d902e50ec5 (patch)
tree5ff7555d0d031a6885f257708a0e2d3d84455162
parent7d5553e60f29b0d2c5d1981e836fe57708071eeb (diff)
downloadstring2-479b2ee8e0cc52c3e76c7c09d0dfa5d902e50ec5.tar.gz
string2-479b2ee8e0cc52c3e76c7c09d0dfa5d902e50ec5.zip
Rewrite build system
-rw-r--r--Makefile44
-rw-r--r--config.mk8
-rwxr-xr-xmakemk29
-rw-r--r--target.mk8
4 files changed, 75 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 7674ac9..826621d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,35 +1,51 @@
# See LICENSE file for copyright and license details.
+include config.mk
+
CC = cc
-SRC != find src -name '*.c'
+
+# Used for debugging and not as usual
OBJ = ${SRC:.c=.o}
LIBNAME = libstr
LIBVER = 0.0.0-a1
-CFLAGS = -Wall -ansi --std=c89 -pedantic ${OPT} -DLIBVER=\"${LIBVER}\"
+OPTIM = -O2 -pipe
+STD = -ansi --std=c89 -pedantic
+WARNS = -Werror -Wall
+
LDFLAGS =
+CFLAGS = ${WARNS} ${STD} -DLIBVER=\"${LIBVER}\" ${OPTIM}
-dist:
- @make OPT='-O2 -pipe -Werror' all
+# CFLAGS for debugging
+CDFLAGS = ${WARNS} ${STD} -DLIBVER=\"${LIBVER}\" -g
-debug:
- @make OPT=-g all
+all: ${LIBNAME:=.a} ${LIBNAME:=.so}
+ @echo ${STD}.
-all: ${LIBNAME:=.so} ${LIBNAME:=.a}
+debug: ${OBJ}
-${LIBNAME:=.so}: ${OBJ}
- ${CC} ${LDFLAGS} -fPIC -shared ${OBJ} -o $@
+.c.o:
+ ${CC} ${CDFLAGS} -c $< -o $@
-${LIBNAME:=.a}: ${OBJ}
- ar rcs $@ ${OBJ}
+# Make shared and archive directories
+${ARDIR} ${SHDIR}:
+ mkdir -p $@
-.c.o:
- ${CC} ${CFLAGS} -fPIC -c $< -o $@
+# Make archive file
+${LIBNAME:=.a}: ${ARDIR} ${AROBJ}
+ ar rcs $@ ${AROBJ}
+
+# Make shared file
+${LIBNAME:=.so}: ${SHDIR} ${SHOBJ}
+ ${CC} ${LDFLAGS} -shared ${SHOBJ} -o $@
clean:
- rm -f ${OBJ} ${LIBNAME}.* *.core
+ rm -rf bin ${LIBNAME}.* *.core ${OBJ}
cd test && make clean
tests: all
cd test && make clean tests
+
+# Generated by makemk script
+include target.mk
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..58fd233
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,8 @@
+# See LICENSE file for copyright and license details.
+
+SRCDIR = src
+ARDIR = bin/archive
+SHDIR = bin/shared
+SRC != find ${SRCDIR} -name '*.c'
+AROBJ = ${SRC:${SRCDIR}/%.c=${ARDIR}/%.o}
+SHOBJ = ${SRC:${SRCDIR}/%.c=${SHDIR}/%.o}
diff --git a/makemk b/makemk
new file mode 100755
index 0000000..0669f81
--- /dev/null
+++ b/makemk
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+MKFILE=target.mk
+SRCDIR=src/
+ARDIR=bin/archive/
+SHDIR=bin/shared/
+
+cat > $MKFILE << EOF
+# See LICENSE file for copyright and license details.
+
+EOF
+
+for srcf in `find $SRCDIR -name '*.c'`
+do
+ TARGETAR=`echo $srcf | sed -E "s|$SRCDIR(.*).c|$ARDIR\1.o|"`
+ TARGETSH=`echo $srcf | sed -E "s|$SRCDIR(.*).c|$SHDIR\1.o|"`
+ LINEAR='${CC} ${CFLAGS} -c '$srcf' -o $@'
+ LINESH='${CC} ${CFLAGS} -fPIC -c '$srcf' -o $@'
+
+cat >> $MKFILE << EOF
+$TARGETAR: $srcf
+ $LINEAR
+
+$TARGETSH: $srcf
+ $LINESH
+
+EOF
+
+done
diff --git a/target.mk b/target.mk
new file mode 100644
index 0000000..2d3e61e
--- /dev/null
+++ b/target.mk
@@ -0,0 +1,8 @@
+# See LICENSE file for copyright and license details.
+
+bin/archive/string2.o: src/string2.c
+ ${CC} ${CFLAGS} -c src/string2.c -o $@
+
+bin/shared/string2.o: src/string2.c
+ ${CC} ${CFLAGS} -fPIC -c src/string2.c -o $@
+