aboutsummaryrefslogtreecommitdiff
path: root/bsd.prog.mk
blob: 80d32319ef8be84a463c520201ed9df8fd7d6bb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright 2015 Nathan Holstein

BINDIR?=/usr/bin
MANDIR?=/usr/share/man

default: ${PROG}

OPENBSD:=reallocarray.c strtonum.c execvpe.c setresuid.c \
	auth_userokay.c setusercontext.c explicit_bzero.c
OPENBSD:=$(addprefix libopenbsd/,${OPENBSD:.c=.o})
libopenbsd.a: ${OPENBSD}
	${AR} -r $@ $?

CFLAGS:=${CFLAGS} -I${CURDIR}/libopenbsd ${COPTS} -MD -MP

OBJS:=${SRCS:.y=.c}
OBJS:=${OBJS:.c=.o}

${PROG}: ${OBJS} libopenbsd.a
	${CC} ${CFLAGS} ${LDFLAGS} $^ -o $@

.%.chmod: %
	cp $< $@
	chmod ${BINMODE} $@
	chown ${BINOWN}:${BINGRP} $@

${BINDIR}:
	mkdir -pm 0755 $@

${BINDIR}/${PROG}: .${PROG}.chmod ${BINDIR}
	mv $< $@

VERSION:=\#define VERSION "$(shell git describe --dirty --tags --long --always)"
OLDVERSION:=$(shell [ -f version.h ] && cat version.h)
version.h: ; @echo '$(VERSION)' > $@
ifneq ($(VERSION),$(OLDVERSION))
.PHONY: version.h
endif

MAN:=$(join $(addprefix ${MANDIR}/man,$(patsubst .%,%/,$(suffix ${MAN}))),${MAN})
$(foreach M,${MAN},$(eval $M: $(notdir $M); cp $$< $$@))

install: ${BINDIR}/${PROG} ${MAN}

clean:
	rm -f version.h
	rm -f libopenbsd.a
	rm -f ${OPENBSD}
	rm -f ${OPENBSD:.o=.d}
	rm -f ${OBJS}
	rm -f ${OBJS:.o=.d}
	rm -f ${PROG}

-include ${objs:.o=.d} ${OPENBSD:.o=.d}

.PHONY: default clean install man
.INTERMEDIATE: .${PROG}.chmod