Restructure the Makefile (refactor)

This commit is contained in:
Benedikt Heine 2017-10-22 03:11:19 +02:00
parent 37d76ab0d1
commit e890052431
2 changed files with 29 additions and 30 deletions

View File

@ -3,11 +3,18 @@
include config.mk include config.mk
VERSION := "1.2.0-non-git"
ifneq ($(wildcard ./.git/.),)
VERSION := $(shell git describe --tags)
endif
CFLAGS += -I. CFLAGS += -I.
LDFLAGS += -L. LDFLAGS += -L.
SRC := $(sort $(shell find src/ -name '*.c')) SRC := $(sort $(shell find src/ -name '*.c'))
OBJ := ${SRC:.c=.o} OBJ := ${SRC:.c=.o}
TEST_SRC := $(sort $(shell find test/ -name '*.c'))
TEST_OBJ := $(TEST_SRC:.c=.o)
all: doc dunst service all: doc dunst service
@ -19,6 +26,25 @@ ${OBJ}: config.mk
dunst: ${OBJ} main.o dunst: ${OBJ} main.o
${CC} ${CFLAGS} -o $@ ${OBJ} main.o ${LDFLAGS} ${CC} ${CFLAGS} -o $@ ${OBJ} main.o ${LDFLAGS}
dunstify: dunstify.o
${CC} ${CFLAGS} -o $@ dunstify.o ${LDFLAGS}
test: test/test
cd test && ./test
test/test: ${OBJ} ${TEST_OBJ}
${CC} ${CFLAGS} -o $@ ${TEST_OBJ} ${OBJ} ${LDFLAGS}
doc: docs/dunst.1
docs/dunst.1: docs/dunst.pod
pod2man --name=dunst -c "Dunst Reference" --section=1 --release=${VERSION} $< > $@
service:
@sed "s|##PREFIX##|$(PREFIX)|" org.knopwob.dunst.service.in > org.knopwob.dunst.service
@sed "s|##PREFIX##|$(PREFIX)|" dunst.systemd.service.in > dunst.systemd.service
clean: clean-dunst clean-dunstify clean-doc clean-tests
clean-dunst: clean-dunst:
rm -f dunst ${OBJ} main.o rm -f dunst ${OBJ} main.o
rm -f org.knopwob.dunst.service rm -f org.knopwob.dunst.service
@ -31,15 +57,10 @@ clean-dunstify:
clean-doc: clean-doc:
rm -f docs/dunst.1 rm -f docs/dunst.1
clean: clean-dunst clean-dunstify clean-doc test-clean clean-tests:
rm -f test/test test/*.o
doc: docs/dunst.1 install: install-dunst install-doc install-service
docs/dunst.1: docs/dunst.pod
pod2man --name=dunst -c "Dunst Reference" --section=1 --release=${VERSION} $< > $@
service:
@sed "s|##PREFIX##|$(PREFIX)|" org.knopwob.dunst.service.in > org.knopwob.dunst.service
@sed "s|##PREFIX##|$(PREFIX)|" dunst.systemd.service.in > dunst.systemd.service
install-dunst: dunst doc install-dunst: dunst doc
mkdir -p ${DESTDIR}${PREFIX}/bin mkdir -p ${DESTDIR}${PREFIX}/bin
@ -56,8 +77,6 @@ install-service: service
install -m644 org.knopwob.dunst.service ${DESTDIR}${PREFIX}/share/dbus-1/services install -m644 org.knopwob.dunst.service ${DESTDIR}${PREFIX}/share/dbus-1/services
install -Dm644 dunst.systemd.service ${DESTDIR}${PREFIX}/lib/systemd/user/dunst.service install -Dm644 dunst.systemd.service ${DESTDIR}${PREFIX}/lib/systemd/user/dunst.service
install: install-dunst install-doc install-service
uninstall: uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/dunst rm -f ${DESTDIR}${PREFIX}/bin/dunst
rm -f ${DESTDIR}${MANPREFIX}/man1/dunst.1 rm -f ${DESTDIR}${MANPREFIX}/man1/dunst.1
@ -65,19 +84,4 @@ uninstall:
rm -f ${DESTDIR}${PREFIX}/lib/systemd/user/dunst.service rm -f ${DESTDIR}${PREFIX}/lib/systemd/user/dunst.service
rm -rf ${DESTDIR}${PREFIX}/share/dunst rm -rf ${DESTDIR}${PREFIX}/share/dunst
test: test/test
cd test && ./test
TEST_SRC := $(shell find test/ -name '*.c')
TEST_OBJ := $(TEST_SRC:.c=.o)
test/test: ${OBJ} ${TEST_OBJ}
${CC} ${CFLAGS} -o $@ ${TEST_OBJ} ${OBJ} ${LDFLAGS}
test-clean:
rm -f test/test test/*.o
dunstify: dunstify.o
${CC} ${CFLAGS} -o $@ dunstify.o ${LDFLAGS}
.PHONY: all clean dist install uninstall .PHONY: all clean dist install uninstall

View File

@ -2,11 +2,6 @@
PREFIX ?= /usr/local PREFIX ?= /usr/local
MANPREFIX = ${PREFIX}/share/man MANPREFIX = ${PREFIX}/share/man
VERSION := "1.2.0-non-git"
ifneq ($(wildcard ./.git/.),)
VERSION := $(shell git describe --tags)
endif
# Warning: This is deprecated behavior # Warning: This is deprecated behavior
# uncomment to disable parsing of dunstrc # uncomment to disable parsing of dunstrc
# or use "CFLAGS=-DSTATIC_CONFIG make" to build # or use "CFLAGS=-DSTATIC_CONFIG make" to build