• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# rules to build a program
2# based on FreeBSD's bsd.prog.mk
3
4# Copyright 2008 Roy Marples <roy@marples.name>
5
6include ${MK}/cc.mk
7
8OBJS+=		${SRCS:.c=.o}
9
10# If building for /, ensure we use the libc in / if different from
11# the default one in /usr/lib
12LINK_RPATH?=		-Wl,-rpath
13_RPATH_SH=		if test "${PREFIX}" = "" -o "${PREIX}" = "/"; then \
14				echo "${LINK_RPATH}=${PREFIX}/${LIBNAME}"; \
15			else \
16				echo ""; \
17			fi
18_RPATH!=		${_RPATH_SH}
19LDFLAGS+=		${_RPATH}$(shell ${_RPATH_SH})
20
21# If building for /, ensure we use the linker in /libexec if different from
22# the default one in /usr/libexec
23_DYNLINK_SH=		if test "${PREFIX}" = "" -o "${PREFIX}" = "/" && test -e /libexec/ld.elf_so; then \
24				echo "-Wl,-dynamic-linker=/libexec/ld.elf_so"; \
25			else \
26				echo ""; \
27			fi
28_DYNLINK!=		${_DYNLINK_SH}
29LDFLAGS+=		${_DYNLINK}$(shell ${_DYNLINK_SH})
30
31all: ${PROG} ${SCRIPTS} _man
32
33.c.o:
34	${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
35
36${PROG}: ${OBJS}
37	${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD}
38
39# We could save about 600 bytes by building it like this
40# instead of the more traditional method above
41small: ${SRCS}
42	echo "" > _${PROG}.c
43	for src in ${SRCS}; do echo "#include \"$$src\"" >> _${PROG}.c; done
44	${CC} ${CFLAGS} ${CPPFLAGS} -c _${PROG}.c -o _${PROG}.o
45	${CC} ${LDFLAGS} -o ${PROG} _${PROG}.o ${LDADD}
46
47_proginstall: ${PROG}
48	${INSTALL} -d ${DESTDIR}${BINDIR}
49	${INSTALL} -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR}
50	${INSTALL} -d ${DESTDIR}${DBDIR}
51
52include ${MK}/depend.mk
53include ${MK}/files.mk
54include ${MK}/scripts.mk
55include ${MK}/man.mk
56include ${MK}/dist.mk
57
58install: _proginstall _scriptsinstall _filesinstall _maninstall
59	for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@; cd ..; done
60
61clean:
62	rm -f ${OBJS} ${PROG} _${PROG}.c _${PROG}.o ${PROG}.core ${CLEANFILES}
63
64LINTFLAGS?=	-hx
65LINTFLAGS+=	-X 159,247,352
66
67lint: ${SRCS:.c=.c}
68	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} $^ ${.ALLSRC}
69