Blame


1 24587d39 2021-06-02 martijn LIB= opensmtpd
2 957c2372 2019-11-14 martijn
3 24587d39 2021-06-02 martijn LOCALBASE?= /usr
4 48b3e268 2021-06-01 martijn
5 24587d39 2021-06-02 martijn SRCS= opensmtpd.c iobuf.c ioev.c
6 24587d39 2021-06-02 martijn HDRS= opensmtpd.h
7 24587d39 2021-06-02 martijn MAN= osmtpd_run.3
8 8cd14444 2019-11-15 martijn LIBDIR?= ${LOCALBASE}/lib/
9 48b3e268 2021-06-01 martijn MANDIR?= ${LOCALBASE}/share/man/man3
10 24587d39 2021-06-02 martijn LDLIBS+= -levent
11 957c2372 2019-11-14 martijn
12 957c2372 2019-11-14 martijn mkfile_path := ${abspath ${lastword ${MAKEFILE_LIST}}}
13 957c2372 2019-11-14 martijn CURDIR := ${dir ${mkfile_path}}
14 957c2372 2019-11-14 martijn
15 957c2372 2019-11-14 martijn CFLAGS+= -I${CURDIR} -I${CURDIR}/openbsd-compat/
16 957c2372 2019-11-14 martijn CFLAGS+= -Wall
17 957c2372 2019-11-14 martijn CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
18 957c2372 2019-11-14 martijn CFLAGS+= -Wmissing-declarations
19 957c2372 2019-11-14 martijn CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
20 957c2372 2019-11-14 martijn CFLAGS+= -Wsign-compare
21 957c2372 2019-11-14 martijn
22 957c2372 2019-11-14 martijn CLEANFILES= ${VERSION_SCRIPT}
23 957c2372 2019-11-14 martijn
24 957c2372 2019-11-14 martijn VERSION_SCRIPT= Symbols.map
25 957c2372 2019-11-14 martijn SYMBOL_LIST= ${CURDIR}/Symbols.list
26 957c2372 2019-11-14 martijn
27 24587d39 2021-06-02 martijn includes:
28 24587d39 2021-06-02 martijn @cd ${CURDIR}; for i in ${HDRS}; do \
29 24587d39 2021-06-02 martijn j="cmp -s $$i ${DESTDIR}${LOCALBASE}/include/$$i || \
30 24587d39 2021-06-02 martijn ${INSTALL} -D -o ${BINOWN} -g ${BINGRP} -m 444 $$i\
31 24587d39 2021-06-02 martijn ${DESTDIR}${LOCALBASE}/include/$$i"; \
32 24587d39 2021-06-02 martijn echo $$j; \
33 24587d39 2021-06-02 martijn eval "$$j"; \
34 24587d39 2021-06-02 martijn done;
35 24587d39 2021-06-02 martijn
36 24587d39 2021-06-02 martijn ${VERSION_SCRIPT}: ${SYMBOL_LIST}
37 24587d39 2021-06-02 martijn { printf '{\n\tglobal:\n'; \
38 24587d39 2021-06-02 martijn sed '/^[._a-zA-Z]/s/$$/;/; s/^/ /' ${SYMBOL_LIST}; \
39 24587d39 2021-06-02 martijn printf '\n\tlocal:\n\t\t*;\n};\n'; } >$@.tmp && mv $@.tmp $@
40 24587d39 2021-06-02 martijn
41 957c2372 2019-11-14 martijn # Defines for OpenBSD-specific interfaces
42 957c2372 2019-11-14 martijn # Add a OS-specific defines here.
43 8224686b 2019-11-14 martijn NEED_EXPLICIT_BZERO?= 0
44 957c2372 2019-11-14 martijn NEED_RECALLOCARRAY?= 1
45 8224686b 2019-11-14 martijn NEED_REALLOCARRAY?= 0
46 957c2372 2019-11-14 martijn NEED_STRLCAT?= 1
47 957c2372 2019-11-14 martijn NEED_STRLCPY?= 1
48 957c2372 2019-11-14 martijn NEED_STRTONUM?= 1
49 957c2372 2019-11-14 martijn
50 48b3e268 2021-06-01 martijn MANFORMAT?= mangz
51 957c2372 2019-11-14 martijn
52 24587d39 2021-06-02 martijn INSTALL?= install
53 24587d39 2021-06-02 martijn LINK?= ln
54 24587d39 2021-06-02 martijn
55 24587d39 2021-06-02 martijn BINOWN?= root
56 24587d39 2021-06-02 martijn BINGRP?= root
57 24587d39 2021-06-02 martijn LIBPERM?= 755
58 24587d39 2021-06-02 martijn MANOWN?= root
59 24587d39 2021-06-02 martijn MANGRP?= root
60 24587d39 2021-06-02 martijn MANPERM?= 644
61 24587d39 2021-06-02 martijn
62 48b3e268 2021-06-01 martijn include ${CURDIR}/shlib_version
63 48b3e268 2021-06-01 martijn BASE_LIB=lib${LIB}.so
64 48b3e268 2021-06-01 martijn TARGET_LIB=lib${LIB}.so.${major}.${minor}.0
65 48b3e268 2021-06-01 martijn SONAME_LIB=lib${LIB}.so.${major}
66 48b3e268 2021-06-01 martijn
67 24587d39 2021-06-02 martijn CFLAGS+= -fPIC
68 48b3e268 2021-06-01 martijn LDFLAGS+= -shared -Wl,-soname=${SONAME_LIB}
69 48b3e268 2021-06-01 martijn
70 48b3e268 2021-06-01 martijn ifeq (${MANFORMAT}, mangz)
71 48b3e268 2021-06-01 martijn TARGET_MAN= ${MAN}.gz
72 48b3e268 2021-06-01 martijn CLEANFILES+= ${TARGET_MAN}
73 48b3e268 2021-06-01 martijn ${TARGET_MAN}: ${MAN}
74 48b3e268 2021-06-01 martijn mandoc -Tman ${MAN} | gzip > $@
75 48b3e268 2021-06-01 martijn else
76 48b3e268 2021-06-01 martijn TARGET_MAN= ${MAN}
77 48b3e268 2021-06-01 martijn endif
78 48b3e268 2021-06-01 martijn
79 957c2372 2019-11-14 martijn ${SRCS:.c=.d}:%.d:%.c
80 957c2372 2019-11-14 martijn ${CC} ${CFLAGS} -MM $< >$@
81 957c2372 2019-11-14 martijn
82 8224686b 2019-11-14 martijn ifeq (${NEED_EXPLICIT_BZERO}, 1)
83 8224686b 2019-11-14 martijn SRCS+= ${CURDIR}/openbsd-compat/explicit_bzero.c
84 8224686b 2019-11-14 martijn CFLAGS+= -DNEED_EXPLICIT_BZERO=1
85 8224686b 2019-11-14 martijn
86 8224686b 2019-11-14 martijn explicit_bzero.o: ${CURDIR}/openbsd-compat/explicit_bzero.c
87 8224686b 2019-11-14 martijn ${CC} ${CFLAGS} -c -o explicit_bzero.o ${CURDIR}/openbsd-compat/explicit_bzero.c
88 8224686b 2019-11-14 martijn endif
89 957c2372 2019-11-14 martijn ifeq (${NEED_RECALLOCARRAY}, 1)
90 957c2372 2019-11-14 martijn SRCS+= ${CURDIR}/openbsd-compat/recallocarray.c
91 957c2372 2019-11-14 martijn CFLAGS+= -DNEED_RECALLOCARRAY=1
92 957c2372 2019-11-14 martijn
93 957c2372 2019-11-14 martijn recallocarray.o: ${CURDIR}/openbsd-compat/recallocarray.c
94 957c2372 2019-11-14 martijn ${CC} ${CFLAGS} -c -o recallocarray.o ${CURDIR}/openbsd-compat/recallocarray.c
95 957c2372 2019-11-14 martijn endif
96 8224686b 2019-11-14 martijn ifeq (${NEED_REALLOCARRAY}, 1)
97 8224686b 2019-11-14 martijn SRCS+= ${CURDIR}/openbsd-compat/reallocarray.c
98 8224686b 2019-11-14 martijn CFLAGS+= -DNEED_REALLOCARRAY=1
99 8224686b 2019-11-14 martijn
100 8224686b 2019-11-14 martijn reallocarray.o: ${CURDIR}/openbsd-compat/reallocarray.c
101 8224686b 2019-11-14 martijn ${CC} ${CFLAGS} -c -o reallocarray.o ${CURDIR}/openbsd-compat/reallocarray.c
102 8224686b 2019-11-14 martijn endif
103 957c2372 2019-11-14 martijn ifeq (${NEED_STRLCAT}, 1)
104 957c2372 2019-11-14 martijn SRCS+= ${CURDIR}/openbsd-compat/strlcat.c
105 957c2372 2019-11-14 martijn CFLAGS+= -DNEED_STRLCAT=1
106 957c2372 2019-11-14 martijn
107 957c2372 2019-11-14 martijn strlcat.o: ${CURDIR}/openbsd-compat/strlcat.c
108 957c2372 2019-11-14 martijn ${CC} ${CFLAGS} -c -o strlcat.o ${CURDIR}/openbsd-compat/strlcat.c
109 957c2372 2019-11-14 martijn endif
110 957c2372 2019-11-14 martijn ifeq (${NEED_STRLCPY}, 1)
111 957c2372 2019-11-14 martijn SRCS+= ${CURDIR}/openbsd-compat/strlcpy.c
112 957c2372 2019-11-14 martijn CFLAGS+= -DNEED_STRLCPY=1
113 957c2372 2019-11-14 martijn
114 957c2372 2019-11-14 martijn strlcpy.o: ${CURDIR}/openbsd-compat/strlcpy.c
115 957c2372 2019-11-14 martijn ${CC} ${CFLAGS} -c -o strlcpy.o ${CURDIR}/openbsd-compat/strlcpy.c
116 957c2372 2019-11-14 martijn endif
117 957c2372 2019-11-14 martijn ifeq (${NEED_STRTONUM}, 1)
118 957c2372 2019-11-14 martijn SRCS+= ${CURDIR}/openbsd-compat/strtonum.c
119 957c2372 2019-11-14 martijn CFLAGS+= -DNEED_STRTONUM=1
120 957c2372 2019-11-14 martijn
121 957c2372 2019-11-14 martijn strtonum.o: ${CURDIR}/openbsd-compat/strtonum.c
122 957c2372 2019-11-14 martijn ${CC} ${CFLAGS} -c -o strtonum.o ${CURDIR}/openbsd-compat/strtonum.c
123 957c2372 2019-11-14 martijn endif
124 957c2372 2019-11-14 martijn
125 957c2372 2019-11-14 martijn OBJS= ${notdir ${SRCS:.c=.o}}
126 957c2372 2019-11-14 martijn
127 48b3e268 2021-06-01 martijn ifdef VERSION_SCRIPT
128 48b3e268 2021-06-01 martijn ${TARGET_LIB}: ${VERSION_SCRIPT}
129 48b3e268 2021-06-01 martijn LDFLAGS+= -Wl,--version-script=${VERSION_SCRIPT}
130 48b3e268 2021-06-01 martijn endif
131 48b3e268 2021-06-01 martijn
132 957c2372 2019-11-14 martijn ${TARGET_LIB}: ${OBJS}
133 48b3e268 2021-06-01 martijn ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDLIBS}
134 957c2372 2019-11-14 martijn
135 48b3e268 2021-06-01 martijn .DEFAULT_GOAL= all
136 48b3e268 2021-06-01 martijn .PHONY: all
137 48b3e268 2021-06-01 martijn all: ${TARGET_LIB} ${TARGET_MAN}
138 48b3e268 2021-06-01 martijn
139 957c2372 2019-11-14 martijn .PHONY: install
140 48b3e268 2021-06-01 martijn install: includes ${TARGET_LIB} ${TARGET_MAN}
141 48b3e268 2021-06-01 martijn ${INSTALL} -D -o ${BINOWN} -g ${BINGRP} -m ${LIBPERM} ${TARGET_LIB} ${DESTDIR}${LIBDIR}/${TARGET_LIB}
142 48b3e268 2021-06-01 martijn ${LINK} -s ${TARGET_LIB} ${DESTDIR}${LIBDIR}/${SONAME_LIB}
143 48b3e268 2021-06-01 martijn ${LINK} -s ${TARGET_LIB} ${DESTDIR}${LIBDIR}/${BASE_LIB}
144 48b3e268 2021-06-01 martijn ${INSTALL} -D -o ${MANOWN} -g ${MANGRP} -m ${MANPERM} ${TARGET_MAN} ${DESTDIR}${MANDIR}/${TARGET_MAN}
145 957c2372 2019-11-14 martijn
146 48b3e268 2021-06-01 martijn CLEANFILES+= *.o ${TARGET_LIB}
147 48b3e268 2021-06-01 martijn
148 957c2372 2019-11-14 martijn .PHONY: clean
149 957c2372 2019-11-14 martijn clean:
150 48b3e268 2021-06-01 martijn rm -f ${CLEANFILES}