Skip to content
Snippets Groups Projects
Makefile 4.48 KiB
Newer Older
CFLAGS += -march=native -masm=intel -g -Og -fsanitize=address,signed-integer-overflow,undefined -pedantic -Wall -Wextra -Werror -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -Wnull-dereference -Wdouble-promotion -Wshadow -Wformat=2 -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wstrict-overflow=5 -Wwrite-strings -Wswitch-default -Wswitch-enum -Wconversion -Wunreachable-code -Winit-self -fno-strict-aliasing -Wno-unknown-warning-option
CXXFLAGS += ${CFLAGS} -std=c++11 -std=c++17 -Wuseless-cast -Weffc++ -I/usr/local/include
Benny Baumann's avatar
Benny Baumann committed
DEPFLAGS = -MT $@ -MMD -MP -MF $(patsubst ${OBJDIR}/%.o,${DEPDIR}/%.d,$@)

POLANGS ?= de en

OS = $(shell uname -s)
ifeq "${OS}" "Linux"
CFLAGS += -flto
CXXFLAGS += -flto
else ifeq "${OS}" "FreeBSD"
CFLAGS += -Wno-error=sign-conversion
CXXFLAGS += -Wno-error=sign-conversion
Benny Baumann's avatar
Benny Baumann committed
CC ?= gcc
CXX ?= g++

MKDIR ?= mkdir -p

INSTALL ?= install
prefix ?= /usr

XGETTEXT ?= xgettext
XGETTEXT_FLAGS ?= -k_ -c -s -i --no-wrap --force-po --from-code=UTF-8 --check=ellipsis-unicode --sentence-end=single-space \
    --foreign-user --package-name=rmrf --package-version=0.1
MSGINIT ?= msginit
MSGMERGE ?= msgmerge
MSGFMT ?= msgfmt

Benny Baumann's avatar
Benny Baumann committed
SRCDIR ?= src
APPDIR ?= ${SRCDIR}/app

BINDIR ?= bin
DEPDIR ?= dep
OBJDIR ?= obj

POTDIR ?= po/tpl
PODIR ?= po/lang
MODIR ?= po/bin

Benny Baumann's avatar
Benny Baumann committed
SOURCES := $(wildcard ${SRCDIR}/*.cpp) $(wildcard ${SRCDIR}/*.c) $(wildcard ${SRCDIR}/**/*.cpp) $(wildcard ${SRCDIR}/**/*.c)

SRCOBJS := $(patsubst ${SRCDIR}/%.c,${OBJDIR}/%.o,$(patsubst ${SRCDIR}/%.cpp,${OBJDIR}/%.o,${SOURCES}))

APPOBJS := $(filter $(patsubst ${SRCDIR}/%,${OBJDIR}/%,${APPDIR})/%,${SRCOBJS})
OBJECTS := $(filter-out $(patsubst ${SRCDIR}/%,${OBJDIR}/%,${APPDIR})/%,${SRCOBJS})

TARGETS := $(patsubst $(patsubst ${SRCDIR}/%,${OBJDIR}/%,${APPDIR})/%.o,${BINDIR}/%,${APPOBJS})

POTOBJS := $(patsubst ${SRCDIR}/%.c,${POTDIR}/%.pot,$(patsubst ${SRCDIR}/%.cpp,${POTDIR}/%.pot,${SOURCES}))
POOBJS := $(foreach POLANG,${POLANGS},$(patsubst ${POTDIR}/%.pot,${PODIR}/${POLANG}/%.po,${POTOBJS}))
MOOBJS := $(patsubst ${PODIR}/%.po,${MODIR}/%.mo,${POOBJS})

Benny Baumann's avatar
Benny Baumann committed
CFLAGS += -I${SRCDIR}

MAKEFLAGS += --no-builtin-rules
.SUFFIXES:

.PRECIOUS: ${DEPDIR}/%.d ${OBJDIR}/%.o ${POTOBJS} ${POOBJS}

.PHONY: all clean install lintian style translation
all: ${TARGETS} translation
${BINDIR}/%: $(patsubst ${SRCDIR}/%,${OBJDIR}/%,${APPDIR})/%.o ${OBJECTS} Makefile ${APPDIR}/%.ldflags
	${MKDIR} ${@D} && ${CXX} ${CXXFLAGS} ${LFLAGS} -o $@ $< ${OBJECTS} $(shell [ -r $(patsubst ${OBJDIR}/%.o,${SRCDIR}/%.ldflags,$<) ] && cat $(patsubst ${OBJDIR}/%.o,${SRCDIR}/%.ldflags,$<) ) && touch $@
${OBJDIR}/%.o: ${SRCDIR}/%.cpp ${DEPDIR}/%.d Makefile
Benny Baumann's avatar
Benny Baumann committed
	${MKDIR} ${@D} && ${MKDIR} $(patsubst ${OBJDIR}/%,${DEPDIR}/%,${@D}) && ${CXX} ${CXXFLAGS} ${DEPFLAGS} ${LFLAGS} -o $@ -c $< && touch $@

${OBJDIR}/%.o: ${SRCDIR}/%.c ${DEPDIR}/%.d Makefile
Benny Baumann's avatar
Benny Baumann committed
	${MKDIR} ${@D} && ${MKDIR} $(patsubst ${OBJDIR}/%,${DEPDIR}/%,${@D}) && ${CC} ${CFLAGS} ${DEPFLAGS} ${LFLAGS} -o $@ -c $< && touch $@

${POTDIR}/%.pot: ${SRCDIR}/%.c
	${MKDIR} ${@D} && ${XGETTEXT} ${XGETTEXT_FLAGS} $( [ -r $@ ] && echo -- -j ) -o $@ $<

${POTDIR}/%.pot: ${SRCDIR}/%.cpp
	${MKDIR} ${@D} && ${XGETTEXT} ${XGETTEXT_FLAGS} $( [ -r $@ ] && echo -- -j ) -o $@ $<

$(foreach POFILE,${POLANGS},${PODIR}/${POFILE}/%.po): ${POTDIR}/%.pot
	for POLANG in ${POLANGS}; do \
		${MKDIR} ${PODIR}/$${POLANG}/${*D} && \
		( [ ! -r ${PODIR}/$${POLANG}/$*.po ] && ${MSGINIT} --no-translator --input=${POTDIR}/$*.pot --locale=${POLANG} --output=${PODIR}/$${POLANG}/$*.po ) && \
		( ${MSGMERGE} --update ${PODIR}/$${POLANG}/$*.po ${POTDIR}/$*.pot ) \
	done

${MODIR}/%.mo: ${PODIR}/%.po
	${MKDIR} ${@D} && ${MSGFMT} --output-file=$@ $<

Benny Baumann's avatar
Benny Baumann committed

${DEPDIR}/%.d: ;

include $(wildcard $(patsubst ${OBJDIR}/%.o,${DEPDIR}/%.d,${SRCOBJS}))

translation: ${MOOBJS}

Benny Baumann's avatar
Benny Baumann committed
clean:
	rm -rf ${BINDIR}
	rm -rf ${OBJDIR}
	rm -rf ${DEPDIR}
	rm -rf ${MODIR}
Benny Baumann's avatar
Benny Baumann committed

style:
	-astyle --mode=c --options=none --recursive -q -Q -s4 -f -j -k1 -W3 -p -U -H ${SRCDIR}/*.c
	-astyle --mode=c --options=none --recursive -q -Q -s4 -f -j -k1 -W3 -p -U -H ${SRCDIR}/*.h
	-astyle --mode=c --options=none --recursive -q -Q -s4 -f -j -k1 -W3 -p -U -H ${SRCDIR}/*.cpp
	-astyle --mode=c --options=none --recursive -q -Q -s4 -f -j -k1 -W3 -p -U -H ${SRCDIR}/*.hpp
	lintian --pedantic --profile debian --verbose --display-experimental --show-overrides
	@if lintian --pedantic --profile debian --verbose --display-experimental --show-overrides 2>&1 | grep -q '^W:'; then false; fi
Benny Baumann's avatar
Benny Baumann committed
install:
	${INSTALL} -D -o root -g root -m 700 -t ${DESTDIR}${prefix}/bin ${TARGETS}