diff options
author | 2023-05-11 17:25:52 +0200 | |
---|---|---|
committer | 2023-05-11 17:25:52 +0200 | |
commit | f58400c634eea6f865db8486e7e174f67bb555ce (patch) | |
tree | 16dd706e8a33bd01832aea7c94eafb6637ced82c | |
parent | c3a38bdbd9e08ba631f34faf408cfac8171dd725 (diff) | |
download | string2-f58400c634eea6f865db8486e7e174f67bb555ce.tar.gz string2-f58400c634eea6f865db8486e7e174f67bb555ce.zip |
Change the way how to build this library
-rw-r--r-- | Makefile | 49 | ||||
-rwxr-xr-x | build-pc.sh | 56 | ||||
-rw-r--r-- | config.mk | 18 |
3 files changed, 118 insertions, 5 deletions
@@ -1,10 +1,49 @@ # See LICENSE file for copyright and license details. -PREFIX=/usr/local -INSTALL_DIR=${PREFIX}/include +include config.mk -install: - cp string2.h ${INSTALL_DIR}/string2.h +all: dist tests + +dist: static shared + ./build-pc.sh -p ${PREFIX} -n ${NAME} -ln ${LIBNAME} -d "${LIBDSCR}" -v ${LIBVER} ${PC_FILE} + +static: + @make OPT='-O2 -pipe -Werror' ${LIBNAME:=.a} + rm -f ${OBJ} + +shared: + @make OPT='-O2 -pipe -Werror -fPIC' ${LIBNAME:=.so} + rm -f ${OBJ} + +debug: + @make OPT=-g all + +${LIBNAME:=.so}: ${OBJ} + ${CC} ${LDFLAGS} -shared ${OBJ} -o $@ + +${LIBNAME:=.a}: ${OBJ} + ar rcs $@ ${OBJ} + +.c.o: + ${CC} ${CFLAGS} -c $< -o $@ + +clean: + rm -f ${OBJ} ${LIBNAME}.* *.core ${PC_FILE} + cd test && make clean + +tests: dist + @make -C test + +install: dist + mkdir -p ${PREFIX}/include + mkdir -p ${PREFIX}/lib + cp src/string2.h ${PREFIX}/include/string2.h + cp ${LIBNAME:=.so} ${PREFIX}/lib/${LIBNAME:=.so} + cp ${LIBNAME:=.a} ${PREFIX}/lib/${LIBNAME:=.a} + cp ${PC_FILE} ${PKG_CONFIG_PATH}/${PC_FILE} uninstall: - rm -f ${INSTALL_DIR}/string2.h + rm -f ${PREFIX}/include/string2.h + rm -f ${PREFIX}/lib/${LIBNAME:=.so} + rm -f ${PREFIX}/lib/${LIBNAME:=.a} + rm -f ${PKG_CONFIG_PATH}/${PC_FILE} diff --git a/build-pc.sh b/build-pc.sh new file mode 100755 index 0000000..eb7dca8 --- /dev/null +++ b/build-pc.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# See LICENSE file for copyright and license details. + +VERSION=0.0.1 + +while [ $# -gt 0 ] +do + case $1 in + -p|--prefix) + shift + PREFIX=$1 + ;; + -n|--name) + shift + NAME=$1 + ;; + -ln|--lib-name) + shift + LIBNAME=$1 + ;; + -d|--description) + shift + DESCR=$1 + ;; + -v|--version) + shift + VERSION=$1 + ;; + *) + TARGET=$1 + ;; + esac + shift +done + +if [ -z $PREFIX ]; then + echo 'prefix must be set' + exit 1 +elif [ -z $NAME ]; then + echo 'name must be set' + exit 1 +fi + +cat <<EOF > $TARGET +prefix=$PREFIX +exec_prefix=\${prefix} +includedir=\${prefix}/include +libdir=\${exec_prefix}/lib + +Name: $NAME +Description: $LIBNAME - $DESCR +Version: $VERSION +Cflags: -I\${includedir} +Libs: -L\${libdir} -l$NAME +EOF diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..2ecd96c --- /dev/null +++ b/config.mk @@ -0,0 +1,18 @@ +# See LICENSE file for copyright and license details. + +PREFIX = /usr/local + +CC = cc +SRC != find src -name "*.c" +OBJ = ${SRC:.c=.o} + +NAME = str2 +LIBNAME = lib${NAME} +LIBDSCR = String library (extension of the C standard string library) +LIBVER = 0.0.1 + +PC_FILE = ${NAME}.pc + +CFLAGS = -Wall --std=c99 -pedantic ${OPT} -DLIBVER=\"${LIBVER}\" + +PKG_CONFIG_PATH != pkg-config --variable pc_path pkg-config | sed -E "s|.*(/usr/local[^:]*)[:].*|\1|g" |