feat(Makefile): USRDIR decomposed into USRLIB, USRBIN, USRINC, CFLAGS for SHARED=

This commit is contained in:
2024-09-18 10:21:38 +03:00
parent 5c8a211f46
commit 871c850cbe

View File

@ -2,6 +2,7 @@
SHARED ?= false
DEBUG ?= false
USRDIR ?= /usr
.PHONY: build i install uni uninstall\
tools library tests clean
@ -24,7 +25,9 @@ TESTS =\
ifeq (${origin CC}, default)
CC = g++
endif
CFLAGS = -std=c++23 -Wall -Wextra -Werror -Wno-unused-result -fPIC
ifneq (${DEBUG}, false)
CFLAGS += -fsanitize=address,undefined -g -O0
-g = -g
@ -32,13 +35,19 @@ else
CFLAGS += -O3
endif
ifneq (${SHARED}, false)
CFLAGS += -Xlinker -rpath=${BINDIR}
endif
SRCDIR = src
INCDIR = include
OBJDIR = obj
BINDIR = bin
LIBDIR = lib
TESTDIR = test
USRDIR = /usr
USRLIB = ${USRDIR}/lib
USRBIN = ${USRDIR}/bin
USRINC = ${USRDIR}/include
DIRS =\
${BINDIR}\
${BINDIR}/hash\
@ -49,14 +58,16 @@ DIRS =\
build: library tools
i: install
install: build ${patsubst %, ${USRDIR}/${BINDIR}/btc-%${-g}, ${TOOLS}}\
${USRDIR}/${LIBDIR}/lib${LIB}${-g}.a ${USRDIR}/${LIBDIR}/lib${LIB}${-g}.so
install: build\
${USRLIB}/lib${LIB}${-g}.a\
${USRLIB}/lib${LIB}${-g}.so\
${patsubst %, ${USRBIN}/%${-g}, ${TOOLS}}
uni: uninstall
uninstall:
rm -f ${USRDIR}/${LIBDIR}/lib${LIB}${-g}.a
rm -f ${USRDIR}/${LIBDIR}/lib${LIB}${-g}.so
rm -f ${patsubst %, ${USRDIR}/${BINDIR}/btc-%${-g}, ${TOOLS}}
rm -f ${USRLIB}/lib${LIB}${-g}.a
rm -f ${USRLIB}/lib${LIB}${-g}.so
rm -f ${patsubst %, ${USRBIN}/%${-g}, ${TOOLS}}
clean:
rm -rf ${OBJDIR}/* ${LIBDIR}/* ${BINDIR}/*
@ -74,10 +85,10 @@ ${BINDIR}/lib${LIB}${-g}.so: ${patsubst %, ${OBJDIR}/%${-g}.o, ${OBJS}}
${LIBDIR}/lib${LIB}${-g}.a: ${patsubst %, ${OBJDIR}/%${-g}.o, ${OBJS}}
ar rcs $@ $^
${USRDIR}/${LIBDIR}/lib${LIB}${-g}.so: ${BINDIR}/lib${LIB}${-g}.so
${USRLIB}/lib${LIB}${-g}.so: ${BINDIR}/lib${LIB}${-g}.so
cp $< $@
${USRDIR}/${LIBDIR}/lib${LIB}${-g}.a: ${LIBDIR}/lib${LIB}${-g}.a
${USRLIB}/lib${LIB}${-g}.a: ${LIBDIR}/lib${LIB}${-g}.a
cp $< $@
endif
@ -87,12 +98,12 @@ tools: library ${DIRS} ${patsubst %, ${BINDIR}/%${-g}, ${TOOLS}}
${BINDIR}/%${-g}: ${SRCDIR}/%.cpp ${patsubst %, ${OBJDIR}/%${-g}.o, ${OBJS}}
ifneq (${SHARED}, false)
${CC} -o $@ $< -I${INCDIR} -L${BINDIR} ${-l} -l${LIB}${-g} ${CFLAGS}
${CC} -o $@ $< -I${INCDIR} -L${BINDIR} ${-l} -l:lib${LIB}${-g}.so ${CFLAGS}
else
${CC} -o $@ $< -I${INCDIR} -L${LIBDIR} ${-l} -l${LIB}${-g} ${CFLAGS}
${CC} -o $@ $< -I${INCDIR} -L${LIBDIR} ${-l} -l:lib${LIB}${-g}.a ${CFLAGS}
endif
${USRDIR}/${BINDIR}/btc-%${-g}: ${BINDIR}/%${-g}
${USRBIN}/%${-g}: ${BINDIR}/%${-g}
cp $< $@
endif
@ -102,7 +113,11 @@ tests: library ${DIRS} ${patsubst %, ${BINDIR}/%${-g}, ${TESTS}}
${patsubst %, ./${BINDIR}/%${-g};, ${TESTS}}
${BINDIR}/%${-g}: ${TESTDIR}/%.cpp ${patsubst %, ${OBJDIR}/%${-g}.o, ${OBJS}}
${CC} -o $@ $< -I${INCDIR} -L${LIBDIR} ${-l} -l${LIB}${-g} -lgtest ${CFLAGS}
ifneq (${SHARED}, false)
${CC} -o $@ $< -I${INCDIR} -L${BINDIR} ${-l} -l:lib${LIB}${-g}.so -lgtest ${CFLAGS}
else
${CC} -o $@ $< -I${INCDIR} -L${LIBDIR} ${-l} -l:lib${LIB}${-g}.a -lgtest ${CFLAGS}
endif
endif