1# dhcpcd Makefile
2
3PROG=		dhcpcd
4SRCS=		common.c control.c dhcpcd.c duid.c eloop.c
5SRCS+=		if.c if-options.c
6SRCS+=		dhcp-common.c
7PKG_CONFIG ?= pkg-config
8
9CFLAGS?=	-O2
10MKDIRS=
11
12TOP?=		.
13include ${TOP}/iconfig.mk
14
15CSTD?=		c99
16CFLAGS+=	-std=${CSTD}
17
18SRCS+=		${DHCPCD_SRCS}
19
20SRCS+=		auth.c
21CPPFLAGS+=	-I./crypt
22CRYPT_SRCS=	crypt/hmac_md5.c ${MD5_SRC} ${SHA256_SRC}
23
24OBJS+=		${SRCS:.c=.o} ${COMPAT_SRCS:.c=.o} ${CRYPT_SRCS:.c=.o}
25
26SCRIPT=		${LIBEXECDIR}/dhcpcd-run-hooks
27HOOKDIR=	${LIBEXECDIR}/dhcpcd-hooks
28
29MAN5=		dhcpcd.conf.5
30MAN8=		dhcpcd.8 dhcpcd-run-hooks.8
31CLEANFILES=	dhcpcd.conf.5 dhcpcd.8 dhcpcd-run-hooks.8
32
33SCRIPTS=	dhcpcd-run-hooks
34
35FILES=		dhcpcd.conf
36
37ifeq ($(DBUS_SUPPORT),yes)
38FILES+= 	dbus/dhcpcd-dbus.conf
39
40_DBUSCFLAGS_SH= $(PKG_CONFIG) --cflags dbus-1
41_DBUSCFLAGS!= ${_DBUSCFLAGS_SH}
42DBUSCFLAGS= ${_DBUSCFLAGS}$(shell ${_DBUSCFLAGS_SH})
43
44_DBUSLIBS_SH= $(PKG_CONFIG) --libs dbus-1
45_DBUSLIBS!= ${_DBUSLIBS_SH}
46DBUSLIBS= ${_DBUSLIBS}$(shell ${_DBUSLIBS_SH})
47DBUSDIR= ${SYSCONFDIR}/dbus-1/system.d
48
49CFLAGS+= ${DBUSCFLAGS}
50LDADD+= ${DBUSLIBS}
51endif
52
53# Linux needs librt
54_LIBRT_SH=	[ "$$(uname -s)" = "Linux" ] && echo "-lrt" || echo ""
55_LIBRT!= 	${_LIBRT_SH}
56LIBRT?=		${_LIBRT} $(shell ${_LIBRT_SH})
57LDADD+=		${LIBRT}
58
59SCRIPTSDIR=	${LIBEXECDIR}
60CLEANFILES+=	dhcpcd-run-hooks
61
62FILESDIR=	${SYSCONFDIR}
63
64SUBDIRS=	${MKDIRS}
65
66ifeq ($(HOOK_SUPPORT),yes)
67SUBDIRS+= 	dhcpcd-hooks
68endif
69
70SED_RUNDIR=		-e 's:@RUNDIR@:${RUNDIR}:g'
71SED_DBDIR=		-e 's:@DBDIR@:${DBDIR}:g'
72SED_LIBDIR=		-e 's:@LIBDIR@:${LIBDIR}:g'
73SED_HOOKDIR=		-e 's:@HOOKDIR@:${HOOKDIR}:g'
74SED_SERVICEEXISTS=	-e 's:@SERVICEEXISTS@:${SERVICEEXISTS}:g'
75SED_SERVICECMD=		-e 's:@SERVICECMD@:${SERVICECMD}:g'
76SED_SERVICESTATUS=	-e 's:@SERVICESTATUS@:${SERVICESTATUS}:g'
77SED_SCRIPT=		-e 's:@SCRIPT@:${SCRIPT}:g'
78SED_SYS=		-e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
79
80DEPEND!=	test -e .depend && echo ".depend" || echo ""
81VERSION!=	sed -n 's/\#define VERSION[[:space:]]*"\(.*\)".*/\1/p' defs.h
82
83FOSSILID?=	current
84
85DISTPREFIX?=	${PROG}-${VERSION}
86DISTFILEGZ?=	${DISTPREFIX}.tar.gz
87DISTFILE?=	${DISTPREFIX}.tar.bz2
88
89HOST_SH?=	/bin/sh
90
91CLEANFILES+=	*.tar.bz2
92
93.PHONY:		import import-bsd dev test
94
95.SUFFIXES:	.in
96
97.in:
98	${SED} ${SED_RUNDIR} ${SED_DBDIR} ${SED_LIBDIR} ${SED_HOOKDIR} \
99		${SED_SYS} ${SED_SCRIPT} \
100		${SED_SERVICEEXISTS} ${SED_SERVICECMD} ${SED_SERVICESTATUS} \
101		$< > $@
102
103all: config.h ${PROG} ${SCRIPTS} ${MAN5} ${MAN8} ${FILES}
104	for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@; cd ..; done
105
106dev:
107	cd dev && ${MAKE}
108
109.c.o:
110	${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
111
112CLEANFILES+=	dhcpcd-embedded.h dhcpcd-embedded.c
113
114dhcpcd-embedded.h: genembedh dhcpcd-definitions.conf dhcpcd-embedded.h.in
115	${HOST_SH} ${.ALLSRC} $^ > $@
116
117dhcpcd-embedded.c: genembedc dhcpcd-definitions.conf
118	${HOST_SH} ${.ALLSRC} $^ > $@
119
120if-options.c: dhcpcd-embedded.h
121
122.depend: ${SRCS} ${COMPAT_SRCS} ${CRYPT_SRCS}
123	${CC} ${CPPFLAGS} -MM ${SRCS} ${COMPAT_SRCS} ${CRYPT_SRCS} > .depend
124
125depend: .depend
126
127${PROG}: ${DEPEND} ${OBJS}
128	${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD}
129
130test:
131	cd $@; ${MAKE} $@; ./$@
132
133_embeddedinstall: dhcpcd-definitions.conf
134	${INSTALL} -d ${DESTDIR}${SCRIPTSDIR}
135	${INSTALL} -m ${CONFMODE} dhcpcd-definitions.conf ${DESTDIR}${SCRIPTSDIR}
136
137_proginstall: ${PROG}
138	${INSTALL} -d ${DESTDIR}${SBINDIR}
139	${INSTALL} -m ${BINMODE} ${PROG} ${DESTDIR}${SBINDIR}
140	${INSTALL} -d ${DESTDIR}${DBDIR}
141
142_scriptsinstall: ${SCRIPTS}
143	${INSTALL} -d ${DESTDIR}${SCRIPTSDIR}
144	${INSTALL} -m ${BINMODE} ${SCRIPTS} ${DESTDIR}${SCRIPTSDIR}
145
146proginstall: _proginstall ${SCRIPTSINSTALL} ${EMBEDDEDINSTALL}
147	for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@; cd ..; done
148
149_maninstall: ${MAN5} ${MAN8}
150	${INSTALL} -d ${DESTDIR}${MANDIR}/man5
151	${INSTALL} -m ${MANMODE} ${MAN5} ${DESTDIR}${MANDIR}/man5
152	${INSTALL} -d ${DESTDIR}${MANDIR}/man8
153	${INSTALL} -m ${MANMODE} ${MAN8} ${DESTDIR}${MANDIR}/man8
154
155_dbusinstall: dbus/dhcpcd-dbus.conf
156	${INSTALL} -d ${DESTDIR}${DBUSDIR}
157	${INSTALL} -m ${CONFMODE} dbus/dhcpcd-dbus.conf \
158		${DESTDIR}${DBUSDIR}/dhcpcd.conf
159
160_confinstall: ${DBUSINSTALL}
161	${INSTALL} -d ${DESTDIR}${SYSCONFDIR}
162	test -e ${DESTDIR}${SYSCONFDIR}/dhcpcd.conf || \
163		${INSTALL} -m ${CONFMODE} dhcpcd.conf ${DESTDIR}${SYSCONFDIR}
164
165install: proginstall _confinstall
166
167clean:
168	rm -f ${OBJS} ${PROG} ${PROG}.core ${CLEANFILES}
169	for x in ${SUBDIRS} test; do cd $$x; ${MAKE} $@; cd ..; done
170
171distclean: clean
172	rm -f .depend config.h config.mk config.log
173
174dist:
175	fossil tarball --name ${DISTPREFIX} ${FOSSILID} ${DISTFILEGZ}
176	gunzip -c ${DISTFILEGZ} |  bzip2 >${DISTFILE}
177	rm ${DISTFILEGZ}
178
179snapshot:
180	rm -rf /tmp/${DISTPREFIX}
181	${INSTALL} -d /tmp/${DISTPREFIX}
182	cp -RPp * /tmp/${DISTPREFIX}
183	cd /tmp/${DISTPREFIX} && ${MAKE} distclean
184	cd /tmp && tar -cvjpf ${DISTFILE} ${DISTPREFIX}
185	mv /tmp/${DISTFILE} .
186	ls -l ${DISTFILE}
187
188import: ${SRCS}
189	rm -rf /tmp/${DISTPREFIX}
190	${INSTALL} -d /tmp/${DISTPREFIX}
191	cp ${SRCS} dhcpcd.conf dhcpcd-definitions.conf *.in /tmp/${DISTPREFIX}
192	cp $$(${CC} ${CPPFLAGS} -DDEPGEN -MM ${SRCS} | \
193		sed -e 's/^.*\.c //g' -e 's/.*\.c$$//g' -e 's/\\//g' | \
194		tr ' ' '\n' | \
195		sed -e '/^compat\//d' | \
196		sed -e '/^crypt\//d' | \
197		sort -u) /tmp/${DISTPREFIX}; \
198	if test -n "${CRYPT_SRCS}"; then \
199		${INSTALL} -d /tmp/${DISTPREFIX}/crypt; \
200		cp ${CRYPT_SRCS} /tmp/${DISTPREFIX}/crypt; \
201		cp $$(${CC} ${CPPFLAGS} -DDEPGEN -MM ${CRYPT_SRCS} | \
202			sed -e 's/^.*c //g' -e 's/.*\.c$$//g' -e 's/\\//g' | \
203			tr ' ' '\n' | sed -e '/\/\.\.\//d'  | \
204			sort -u) /tmp/${DISTPREFIX}/crypt; \
205	fi;
206	if test -n "${COMPAT_SRCS}"; then \
207		${INSTALL} -d /tmp/${DISTPREFIX}/compat; \
208		cp ${COMPAT_SRCS} /tmp/${DISTPREFIX}/compat; \
209		cp $$(${CC} ${CPPFLAGS} -DDEPGEN -MM ${COMPAT_SRCS} | \
210			sed -e 's/^.*c //g' -e 's/.*\.c$$//g' -e 's/\\//g' | \
211			tr ' ' '\n' | \
212			sort -u) /tmp/${DISTPREFIX}/compat; \
213	fi;
214	cd dhcpcd-hooks; ${MAKE} DISTPREFIX=${DISTPREFIX} $@
215
216include Makefile.inc
217