1300313Ssjg#	$Id: prog.mk,v 1.26 2016/03/22 20:45:14 sjg Exp $
2246149Ssjg
3246149Ssjg.if !target(__${.PARSEFILE}__)
4246149Ssjg__${.PARSEFILE}__:
5246149Ssjg
6246149Ssjg.include <init.mk>
7246149Ssjg
8246149Ssjg# FreeBSD at least expects MAN8 etc.
9246149Ssjg.if defined(MAN) && !empty(MAN)
10246149Ssjg_sect:=${MAN:E}
11246149SsjgMAN${_sect}=${MAN}
12246149Ssjg.endif
13246149Ssjg
14246149Ssjg.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
15246149Ssjg
16246149SsjgCFLAGS+=	${COPTS}
17246149Ssjg
18246149Ssjg.if ${TARGET_OSNAME} == "NetBSD"
19246149Ssjg.if ${MACHINE_ARCH} == "sparc64"
20246149SsjgCFLAGS+=	-mcmodel=medlow
21246149Ssjg.endif
22246149Ssjg
23246149Ssjg# ELF platforms depend on crtbegin.o and crtend.o
24246149Ssjg.if ${OBJECT_FMT} == "ELF"
25246149Ssjg.ifndef LIBCRTBEGIN
26246149SsjgLIBCRTBEGIN=	${DESTDIR}/usr/lib/crtbegin.o
27246149Ssjg.MADE: ${LIBCRTBEGIN}
28246149Ssjg.endif
29246149Ssjg.ifndef LIBCRTEND
30246149SsjgLIBCRTEND=	${DESTDIR}/usr/lib/crtend.o
31246149Ssjg.MADE: ${LIBCRTEND}
32246149Ssjg.endif
33246149Ssjg_SHLINKER=	${SHLINKDIR}/ld.elf_so
34246149Ssjg.else
35246149SsjgLIBCRTBEGIN?=
36246149SsjgLIBCRTEND?=
37246149Ssjg_SHLINKER=	${SHLINKDIR}/ld.so
38246149Ssjg.endif
39246149Ssjg
40246149Ssjg.ifndef LIBCRT0
41246149SsjgLIBCRT0=	${DESTDIR}/usr/lib/crt0.o
42246149Ssjg.MADE: ${LIBCRT0}
43246149Ssjg.endif
44246149Ssjg.endif	# NetBSD
45246149Ssjg
46246149Ssjg# here is where you can define what LIB* are
47246149Ssjg.-include <libnames.mk>
48246149Ssjg.if ${MK_DPADD_MK} == "yes"
49246149Ssjg# lots of cool magic, but might not suit everyone.
50246149Ssjg.include <dpadd.mk>
51246149Ssjg.endif
52246149Ssjg
53253883Ssjg.if ${MK_GPROF} == "yes"
54253883SsjgCFLAGS+= ${CC_PG} ${PROFFLAGS}
55253883SsjgLDADD+= ${CC_PG}
56253883Ssjg.if ${MK_DPADD_MK} == "no"
57253883SsjgLDADD_LIBC_P?= -lc_p
58253883SsjgLDADD_LAST+= ${LDADD_LIBC_P}
59253883Ssjg.endif
60253883Ssjg.endif
61253883Ssjg
62246149Ssjg.if defined(SHAREDSTRINGS)
63246149SsjgCLEANFILES+=strings
64246149Ssjg.c.o:
65246149Ssjg	${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
66246149Ssjg	@${CC} ${CFLAGS} -c x.c -o ${.TARGET}
67246149Ssjg	@rm -f x.c
68246149Ssjg
69300313Ssjg${CXX_SUFFIXES:%=%.o}:
70246149Ssjg	${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
71246149Ssjg	@mv -f x.c x.cc
72246149Ssjg	@${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
73246149Ssjg	@rm -f x.cc
74246149Ssjg.endif
75246149Ssjg
76246149Ssjg
77246149Ssjg.if defined(PROG)
78246149SsjgSRCS?=	${PROG}.c
79246149Ssjg.for s in ${SRCS:N*.h:N*.sh:M*/*}
80246149Ssjg${.o .po .lo:L:@o@${s:T:R}$o@}: $s
81246149Ssjg.endfor
82246149Ssjg.if !empty(SRCS:N*.h:N*.sh)
83246149SsjgOBJS+=	${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
84246149SsjgLOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
85246149Ssjg.endif
86246149Ssjg
87246149Ssjg.if defined(OBJS) && !empty(OBJS)
88246149Ssjg.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
89246149Ssjg
90246149Ssjg# this is known to work for NetBSD 1.6 and FreeBSD 4.2
91246149Ssjg.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
92246149Ssjg_PROGLDOPTS=
93246149Ssjg.if ${SHLINKDIR} != "/usr/libexec"	# XXX: change or remove if ld.so moves
94246149Ssjg_PROGLDOPTS+=	-Wl,-dynamic-linker=${_SHLINKER}
95246149Ssjg.endif
96246149Ssjg.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
97246149Ssjg_PROGLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
98246149Ssjg		-L${DESTDIR}${SHLIBDIR}
99246149Ssjg.endif
100246149Ssjg_PROGLDOPTS+=	-Wl,-rpath,${SHLIBDIR}:/usr/lib 
101246149Ssjg
102246149Ssjg.if defined(PROG_CXX)
103246149Ssjg_CCLINK=	${CXX}
104246149Ssjg_SUPCXX=	-lstdc++ -lm
105246149Ssjg.endif
106246149Ssjg.endif	# NetBSD
107246149Ssjg
108246149Ssjg_CCLINK?=	${CC}
109246149Ssjg
110246149Ssjg.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
111246149Ssjg
112246149Ssjg${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
113246149Ssjg	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
114246149Ssjg
115246149Ssjg.else
116246149Ssjg
117246149Ssjg${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
118246149Ssjg	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
119246149Ssjg
120246149Ssjg.endif	# defined(DESTDIR)
121246149Ssjg.endif	# defined(OBJS) && !empty(OBJS)
122246149Ssjg
123246149Ssjg.if	!defined(MAN)
124246149SsjgMAN=	${PROG}.1
125246149Ssjg.endif	# !defined(MAN)
126246149Ssjg.endif	# defined(PROG)
127246149Ssjg
128246149Ssjg.if !defined(_SKIP_BUILD)
129246149Ssjgall: ${PROG}
130246149Ssjg.endif
131246149Ssjgall: _SUBDIRUSE
132246149Ssjg
133246149Ssjg.if !target(clean)
134246149Ssjgcleanprog:
135246149Ssjg	rm -f a.out [Ee]rrs mklog core *.core \
136246149Ssjg	    ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
137246149Ssjg
138246149Ssjgclean: _SUBDIRUSE cleanprog
139246149Ssjgcleandir: _SUBDIRUSE cleanprog
140246149Ssjg.else
141246149Ssjgcleandir: _SUBDIRUSE clean
142246149Ssjg.endif
143246149Ssjg
144246149Ssjg.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
145246149Ssjgafterdepend: .depend
146246149Ssjg	@(TMP=/tmp/_depend$$$$; \
147246149Ssjg	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
148246149Ssjg	      < .depend > $$TMP; \
149246149Ssjg	    mv $$TMP .depend)
150246149Ssjg.endif
151246149Ssjg
152246149Ssjg.if !target(install)
153246149Ssjg.if !target(beforeinstall)
154246149Ssjgbeforeinstall:
155246149Ssjg.endif
156246149Ssjg.if !target(afterinstall)
157246149Ssjgafterinstall:
158246149Ssjg.endif
159246149Ssjg
160246149Ssjg.if !empty(BINOWN)
161246149SsjgPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
162246149Ssjg.endif
163246149Ssjg
164246149Ssjg.if !target(realinstall)
165246149Ssjgrealinstall: proginstall
166246149Ssjg.endif
167246149Ssjg.if !target(proginstall)
168246149Ssjgproginstall:
169246149Ssjg.if defined(PROG)
170246149Ssjg	[ -d ${DESTDIR}${BINDIR} ] || \
171246149Ssjg	${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
172246149Ssjg	${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
173246149Ssjg	    ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
174246149Ssjg.endif
175246149Ssjg.if defined(HIDEGAME)
176246149Ssjg	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
177246149Ssjg.endif
178246149Ssjg.endif
179246149Ssjg
180246149Ssjg.include <links.mk>
181246149Ssjg
182246149Ssjginstall: maninstall install_links _SUBDIRUSE
183246149Ssjg
184246149Ssjginstall_links:
185246149Ssjg.if !empty(SYMLINKS)
186246149Ssjg	@set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
187246149Ssjg.endif
188246149Ssjg.if !empty(LINKS)
189246149Ssjg	@set ${LINKS}; ${_LINKS_SCRIPT}
190246149Ssjg.endif
191246149Ssjg
192246149Ssjgmaninstall: afterinstall
193246149Ssjgafterinstall: realinstall
194246149Ssjgrealinstall: beforeinstall
195246149Ssjg.endif
196246149Ssjg
197246149Ssjg.if !target(lint)
198246149Ssjglint: ${LOBJS}
199246149Ssjg.if defined(LOBJS) && !empty(LOBJS)
200246149Ssjg	@${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
201246149Ssjg.endif
202246149Ssjg.endif
203246149Ssjg
204246149Ssjg.NOPATH:	${PROG}
205246149Ssjg.if defined(OBJS) && !empty(OBJS)
206246149Ssjg.NOPATH:	${OBJS}
207246149Ssjg.endif
208246149Ssjg
209246149Ssjg.if ${MK_MAN} != "no"
210246149Ssjg.include <man.mk>
211246149Ssjg.endif
212246149Ssjg
213246149Ssjg.if ${MK_NLS} != "no"
214246149Ssjg.include <nls.mk>
215246149Ssjg.endif
216246149Ssjg
217246149Ssjg.include <obj.mk>
218246149Ssjg.include <dep.mk>
219246149Ssjg.include <subdir.mk>
220246149Ssjg.include <final.mk>
221246149Ssjg
222246149Ssjg.endif
223