prog.mk revision 246149
1246149Ssjg#	$Id: prog.mk,v 1.24 2012/12/13 23:04: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
53246149Ssjg.if defined(SHAREDSTRINGS)
54246149SsjgCLEANFILES+=strings
55246149Ssjg.c.o:
56246149Ssjg	${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
57246149Ssjg	@${CC} ${CFLAGS} -c x.c -o ${.TARGET}
58246149Ssjg	@rm -f x.c
59246149Ssjg
60246149Ssjg.cc.o:
61246149Ssjg	${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
62246149Ssjg	@mv -f x.c x.cc
63246149Ssjg	@${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
64246149Ssjg	@rm -f x.cc
65246149Ssjg
66246149Ssjg.C.o:
67246149Ssjg	${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
68246149Ssjg	@mv -f x.c x.C
69246149Ssjg	@${CXX} ${CXXFLAGS} -c x.C -o ${.TARGET}
70246149Ssjg	@rm -f x.C
71246149Ssjg.endif
72246149Ssjg
73246149Ssjg
74246149Ssjg.if defined(PROG)
75246149SsjgSRCS?=	${PROG}.c
76246149Ssjg.for s in ${SRCS:N*.h:N*.sh:M*/*}
77246149Ssjg${.o .po .lo:L:@o@${s:T:R}$o@}: $s
78246149Ssjg.endfor
79246149Ssjg.if !empty(SRCS:N*.h:N*.sh)
80246149SsjgOBJS+=	${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
81246149SsjgLOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
82246149Ssjg.endif
83246149Ssjg
84246149Ssjg.if defined(OBJS) && !empty(OBJS)
85246149Ssjg.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
86246149Ssjg
87246149Ssjg# this is known to work for NetBSD 1.6 and FreeBSD 4.2
88246149Ssjg.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
89246149Ssjg_PROGLDOPTS=
90246149Ssjg.if ${SHLINKDIR} != "/usr/libexec"	# XXX: change or remove if ld.so moves
91246149Ssjg_PROGLDOPTS+=	-Wl,-dynamic-linker=${_SHLINKER}
92246149Ssjg.endif
93246149Ssjg.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
94246149Ssjg_PROGLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
95246149Ssjg		-L${DESTDIR}${SHLIBDIR}
96246149Ssjg.endif
97246149Ssjg_PROGLDOPTS+=	-Wl,-rpath,${SHLIBDIR}:/usr/lib 
98246149Ssjg
99246149Ssjg.if defined(PROG_CXX)
100246149Ssjg_CCLINK=	${CXX}
101246149Ssjg_SUPCXX=	-lstdc++ -lm
102246149Ssjg.endif
103246149Ssjg.endif	# NetBSD
104246149Ssjg
105246149Ssjg_CCLINK?=	${CC}
106246149Ssjg
107246149Ssjg.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
108246149Ssjg
109246149Ssjg${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
110246149Ssjg	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
111246149Ssjg
112246149Ssjg.else
113246149Ssjg
114246149Ssjg${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
115246149Ssjg	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
116246149Ssjg
117246149Ssjg.endif	# defined(DESTDIR)
118246149Ssjg.endif	# defined(OBJS) && !empty(OBJS)
119246149Ssjg
120246149Ssjg.if	!defined(MAN)
121246149SsjgMAN=	${PROG}.1
122246149Ssjg.endif	# !defined(MAN)
123246149Ssjg.endif	# defined(PROG)
124246149Ssjg
125246149Ssjg.if !defined(_SKIP_BUILD)
126246149Ssjgall: ${PROG}
127246149Ssjg.endif
128246149Ssjgall: _SUBDIRUSE
129246149Ssjg
130246149Ssjg.if !target(clean)
131246149Ssjgcleanprog:
132246149Ssjg	rm -f a.out [Ee]rrs mklog core *.core \
133246149Ssjg	    ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
134246149Ssjg
135246149Ssjgclean: _SUBDIRUSE cleanprog
136246149Ssjgcleandir: _SUBDIRUSE cleanprog
137246149Ssjg.else
138246149Ssjgcleandir: _SUBDIRUSE clean
139246149Ssjg.endif
140246149Ssjg
141246149Ssjg.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
142246149Ssjgafterdepend: .depend
143246149Ssjg	@(TMP=/tmp/_depend$$$$; \
144246149Ssjg	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
145246149Ssjg	      < .depend > $$TMP; \
146246149Ssjg	    mv $$TMP .depend)
147246149Ssjg.endif
148246149Ssjg
149246149Ssjg.if !target(install)
150246149Ssjg.if !target(beforeinstall)
151246149Ssjgbeforeinstall:
152246149Ssjg.endif
153246149Ssjg.if !target(afterinstall)
154246149Ssjgafterinstall:
155246149Ssjg.endif
156246149Ssjg
157246149Ssjg.if !empty(BINOWN)
158246149SsjgPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
159246149Ssjg.endif
160246149Ssjg
161246149Ssjg.if !target(realinstall)
162246149Ssjgrealinstall: proginstall
163246149Ssjg.endif
164246149Ssjg.if !target(proginstall)
165246149Ssjgproginstall:
166246149Ssjg.if defined(PROG)
167246149Ssjg	[ -d ${DESTDIR}${BINDIR} ] || \
168246149Ssjg	${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
169246149Ssjg	${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
170246149Ssjg	    ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
171246149Ssjg.endif
172246149Ssjg.if defined(HIDEGAME)
173246149Ssjg	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
174246149Ssjg.endif
175246149Ssjg.endif
176246149Ssjg
177246149Ssjg.include <links.mk>
178246149Ssjg
179246149Ssjginstall: maninstall install_links _SUBDIRUSE
180246149Ssjg
181246149Ssjginstall_links:
182246149Ssjg.if !empty(SYMLINKS)
183246149Ssjg	@set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
184246149Ssjg.endif
185246149Ssjg.if !empty(LINKS)
186246149Ssjg	@set ${LINKS}; ${_LINKS_SCRIPT}
187246149Ssjg.endif
188246149Ssjg
189246149Ssjgmaninstall: afterinstall
190246149Ssjgafterinstall: realinstall
191246149Ssjgrealinstall: beforeinstall
192246149Ssjg.endif
193246149Ssjg
194246149Ssjg.if !target(lint)
195246149Ssjglint: ${LOBJS}
196246149Ssjg.if defined(LOBJS) && !empty(LOBJS)
197246149Ssjg	@${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
198246149Ssjg.endif
199246149Ssjg.endif
200246149Ssjg
201246149Ssjg.NOPATH:	${PROG}
202246149Ssjg.if defined(OBJS) && !empty(OBJS)
203246149Ssjg.NOPATH:	${OBJS}
204246149Ssjg.endif
205246149Ssjg
206246149Ssjg.if ${MK_MAN} != "no"
207246149Ssjg.include <man.mk>
208246149Ssjg.endif
209246149Ssjg
210246149Ssjg.if ${MK_NLS} != "no"
211246149Ssjg.include <nls.mk>
212246149Ssjg.endif
213246149Ssjg
214246149Ssjg.include <obj.mk>
215246149Ssjg.include <dep.mk>
216246149Ssjg.include <subdir.mk>
217246149Ssjg.include <final.mk>
218246149Ssjg
219246149Ssjg.endif
220