xref: /freebsd/contrib/bmake/mk/prog.mk (revision 3cbdda60ff509264469d6894d4e838b0d2ccea5c)
1*3cbdda60SSimon J. Gerraty#	$Id: prog.mk,v 1.24 2012/12/13 23:04:14 sjg Exp $
2*3cbdda60SSimon J. Gerraty
3*3cbdda60SSimon J. Gerraty.if !target(__${.PARSEFILE}__)
4*3cbdda60SSimon J. Gerraty__${.PARSEFILE}__:
5*3cbdda60SSimon J. Gerraty
6*3cbdda60SSimon J. Gerraty.include <init.mk>
7*3cbdda60SSimon J. Gerraty
8*3cbdda60SSimon J. Gerraty# FreeBSD at least expects MAN8 etc.
9*3cbdda60SSimon J. Gerraty.if defined(MAN) && !empty(MAN)
10*3cbdda60SSimon J. Gerraty_sect:=${MAN:E}
11*3cbdda60SSimon J. GerratyMAN${_sect}=${MAN}
12*3cbdda60SSimon J. Gerraty.endif
13*3cbdda60SSimon J. Gerraty
14*3cbdda60SSimon J. Gerraty.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
15*3cbdda60SSimon J. Gerraty
16*3cbdda60SSimon J. GerratyCFLAGS+=	${COPTS}
17*3cbdda60SSimon J. Gerraty
18*3cbdda60SSimon J. Gerraty.if ${TARGET_OSNAME} == "NetBSD"
19*3cbdda60SSimon J. Gerraty.if ${MACHINE_ARCH} == "sparc64"
20*3cbdda60SSimon J. GerratyCFLAGS+=	-mcmodel=medlow
21*3cbdda60SSimon J. Gerraty.endif
22*3cbdda60SSimon J. Gerraty
23*3cbdda60SSimon J. Gerraty# ELF platforms depend on crtbegin.o and crtend.o
24*3cbdda60SSimon J. Gerraty.if ${OBJECT_FMT} == "ELF"
25*3cbdda60SSimon J. Gerraty.ifndef LIBCRTBEGIN
26*3cbdda60SSimon J. GerratyLIBCRTBEGIN=	${DESTDIR}/usr/lib/crtbegin.o
27*3cbdda60SSimon J. Gerraty.MADE: ${LIBCRTBEGIN}
28*3cbdda60SSimon J. Gerraty.endif
29*3cbdda60SSimon J. Gerraty.ifndef LIBCRTEND
30*3cbdda60SSimon J. GerratyLIBCRTEND=	${DESTDIR}/usr/lib/crtend.o
31*3cbdda60SSimon J. Gerraty.MADE: ${LIBCRTEND}
32*3cbdda60SSimon J. Gerraty.endif
33*3cbdda60SSimon J. Gerraty_SHLINKER=	${SHLINKDIR}/ld.elf_so
34*3cbdda60SSimon J. Gerraty.else
35*3cbdda60SSimon J. GerratyLIBCRTBEGIN?=
36*3cbdda60SSimon J. GerratyLIBCRTEND?=
37*3cbdda60SSimon J. Gerraty_SHLINKER=	${SHLINKDIR}/ld.so
38*3cbdda60SSimon J. Gerraty.endif
39*3cbdda60SSimon J. Gerraty
40*3cbdda60SSimon J. Gerraty.ifndef LIBCRT0
41*3cbdda60SSimon J. GerratyLIBCRT0=	${DESTDIR}/usr/lib/crt0.o
42*3cbdda60SSimon J. Gerraty.MADE: ${LIBCRT0}
43*3cbdda60SSimon J. Gerraty.endif
44*3cbdda60SSimon J. Gerraty.endif	# NetBSD
45*3cbdda60SSimon J. Gerraty
46*3cbdda60SSimon J. Gerraty# here is where you can define what LIB* are
47*3cbdda60SSimon J. Gerraty.-include <libnames.mk>
48*3cbdda60SSimon J. Gerraty.if ${MK_DPADD_MK} == "yes"
49*3cbdda60SSimon J. Gerraty# lots of cool magic, but might not suit everyone.
50*3cbdda60SSimon J. Gerraty.include <dpadd.mk>
51*3cbdda60SSimon J. Gerraty.endif
52*3cbdda60SSimon J. Gerraty
53*3cbdda60SSimon J. Gerraty.if defined(SHAREDSTRINGS)
54*3cbdda60SSimon J. GerratyCLEANFILES+=strings
55*3cbdda60SSimon J. Gerraty.c.o:
56*3cbdda60SSimon J. Gerraty	${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
57*3cbdda60SSimon J. Gerraty	@${CC} ${CFLAGS} -c x.c -o ${.TARGET}
58*3cbdda60SSimon J. Gerraty	@rm -f x.c
59*3cbdda60SSimon J. Gerraty
60*3cbdda60SSimon J. Gerraty.cc.o:
61*3cbdda60SSimon J. Gerraty	${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
62*3cbdda60SSimon J. Gerraty	@mv -f x.c x.cc
63*3cbdda60SSimon J. Gerraty	@${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
64*3cbdda60SSimon J. Gerraty	@rm -f x.cc
65*3cbdda60SSimon J. Gerraty
66*3cbdda60SSimon J. Gerraty.C.o:
67*3cbdda60SSimon J. Gerraty	${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
68*3cbdda60SSimon J. Gerraty	@mv -f x.c x.C
69*3cbdda60SSimon J. Gerraty	@${CXX} ${CXXFLAGS} -c x.C -o ${.TARGET}
70*3cbdda60SSimon J. Gerraty	@rm -f x.C
71*3cbdda60SSimon J. Gerraty.endif
72*3cbdda60SSimon J. Gerraty
73*3cbdda60SSimon J. Gerraty
74*3cbdda60SSimon J. Gerraty.if defined(PROG)
75*3cbdda60SSimon J. GerratySRCS?=	${PROG}.c
76*3cbdda60SSimon J. Gerraty.for s in ${SRCS:N*.h:N*.sh:M*/*}
77*3cbdda60SSimon J. Gerraty${.o .po .lo:L:@o@${s:T:R}$o@}: $s
78*3cbdda60SSimon J. Gerraty.endfor
79*3cbdda60SSimon J. Gerraty.if !empty(SRCS:N*.h:N*.sh)
80*3cbdda60SSimon J. GerratyOBJS+=	${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
81*3cbdda60SSimon J. GerratyLOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
82*3cbdda60SSimon J. Gerraty.endif
83*3cbdda60SSimon J. Gerraty
84*3cbdda60SSimon J. Gerraty.if defined(OBJS) && !empty(OBJS)
85*3cbdda60SSimon J. Gerraty.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
86*3cbdda60SSimon J. Gerraty
87*3cbdda60SSimon J. Gerraty# this is known to work for NetBSD 1.6 and FreeBSD 4.2
88*3cbdda60SSimon J. Gerraty.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
89*3cbdda60SSimon J. Gerraty_PROGLDOPTS=
90*3cbdda60SSimon J. Gerraty.if ${SHLINKDIR} != "/usr/libexec"	# XXX: change or remove if ld.so moves
91*3cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-dynamic-linker=${_SHLINKER}
92*3cbdda60SSimon J. Gerraty.endif
93*3cbdda60SSimon J. Gerraty.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
94*3cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
95*3cbdda60SSimon J. Gerraty		-L${DESTDIR}${SHLIBDIR}
96*3cbdda60SSimon J. Gerraty.endif
97*3cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-rpath,${SHLIBDIR}:/usr/lib
98*3cbdda60SSimon J. Gerraty
99*3cbdda60SSimon J. Gerraty.if defined(PROG_CXX)
100*3cbdda60SSimon J. Gerraty_CCLINK=	${CXX}
101*3cbdda60SSimon J. Gerraty_SUPCXX=	-lstdc++ -lm
102*3cbdda60SSimon J. Gerraty.endif
103*3cbdda60SSimon J. Gerraty.endif	# NetBSD
104*3cbdda60SSimon J. Gerraty
105*3cbdda60SSimon J. Gerraty_CCLINK?=	${CC}
106*3cbdda60SSimon J. Gerraty
107*3cbdda60SSimon J. Gerraty.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
108*3cbdda60SSimon J. Gerraty
109*3cbdda60SSimon J. Gerraty${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
110*3cbdda60SSimon J. Gerraty	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
111*3cbdda60SSimon J. Gerraty
112*3cbdda60SSimon J. Gerraty.else
113*3cbdda60SSimon J. Gerraty
114*3cbdda60SSimon J. Gerraty${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
115*3cbdda60SSimon J. Gerraty	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
116*3cbdda60SSimon J. Gerraty
117*3cbdda60SSimon J. Gerraty.endif	# defined(DESTDIR)
118*3cbdda60SSimon J. Gerraty.endif	# defined(OBJS) && !empty(OBJS)
119*3cbdda60SSimon J. Gerraty
120*3cbdda60SSimon J. Gerraty.if	!defined(MAN)
121*3cbdda60SSimon J. GerratyMAN=	${PROG}.1
122*3cbdda60SSimon J. Gerraty.endif	# !defined(MAN)
123*3cbdda60SSimon J. Gerraty.endif	# defined(PROG)
124*3cbdda60SSimon J. Gerraty
125*3cbdda60SSimon J. Gerraty.if !defined(_SKIP_BUILD)
126*3cbdda60SSimon J. Gerratyall: ${PROG}
127*3cbdda60SSimon J. Gerraty.endif
128*3cbdda60SSimon J. Gerratyall: _SUBDIRUSE
129*3cbdda60SSimon J. Gerraty
130*3cbdda60SSimon J. Gerraty.if !target(clean)
131*3cbdda60SSimon J. Gerratycleanprog:
132*3cbdda60SSimon J. Gerraty	rm -f a.out [Ee]rrs mklog core *.core \
133*3cbdda60SSimon J. Gerraty	    ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
134*3cbdda60SSimon J. Gerraty
135*3cbdda60SSimon J. Gerratyclean: _SUBDIRUSE cleanprog
136*3cbdda60SSimon J. Gerratycleandir: _SUBDIRUSE cleanprog
137*3cbdda60SSimon J. Gerraty.else
138*3cbdda60SSimon J. Gerratycleandir: _SUBDIRUSE clean
139*3cbdda60SSimon J. Gerraty.endif
140*3cbdda60SSimon J. Gerraty
141*3cbdda60SSimon J. Gerraty.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
142*3cbdda60SSimon J. Gerratyafterdepend: .depend
143*3cbdda60SSimon J. Gerraty	@(TMP=/tmp/_depend$$$$; \
144*3cbdda60SSimon J. Gerraty	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
145*3cbdda60SSimon J. Gerraty	      < .depend > $$TMP; \
146*3cbdda60SSimon J. Gerraty	    mv $$TMP .depend)
147*3cbdda60SSimon J. Gerraty.endif
148*3cbdda60SSimon J. Gerraty
149*3cbdda60SSimon J. Gerraty.if !target(install)
150*3cbdda60SSimon J. Gerraty.if !target(beforeinstall)
151*3cbdda60SSimon J. Gerratybeforeinstall:
152*3cbdda60SSimon J. Gerraty.endif
153*3cbdda60SSimon J. Gerraty.if !target(afterinstall)
154*3cbdda60SSimon J. Gerratyafterinstall:
155*3cbdda60SSimon J. Gerraty.endif
156*3cbdda60SSimon J. Gerraty
157*3cbdda60SSimon J. Gerraty.if !empty(BINOWN)
158*3cbdda60SSimon J. GerratyPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
159*3cbdda60SSimon J. Gerraty.endif
160*3cbdda60SSimon J. Gerraty
161*3cbdda60SSimon J. Gerraty.if !target(realinstall)
162*3cbdda60SSimon J. Gerratyrealinstall: proginstall
163*3cbdda60SSimon J. Gerraty.endif
164*3cbdda60SSimon J. Gerraty.if !target(proginstall)
165*3cbdda60SSimon J. Gerratyproginstall:
166*3cbdda60SSimon J. Gerraty.if defined(PROG)
167*3cbdda60SSimon J. Gerraty	[ -d ${DESTDIR}${BINDIR} ] || \
168*3cbdda60SSimon J. Gerraty	${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
169*3cbdda60SSimon J. Gerraty	${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
170*3cbdda60SSimon J. Gerraty	    ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
171*3cbdda60SSimon J. Gerraty.endif
172*3cbdda60SSimon J. Gerraty.if defined(HIDEGAME)
173*3cbdda60SSimon J. Gerraty	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
174*3cbdda60SSimon J. Gerraty.endif
175*3cbdda60SSimon J. Gerraty.endif
176*3cbdda60SSimon J. Gerraty
177*3cbdda60SSimon J. Gerraty.include <links.mk>
178*3cbdda60SSimon J. Gerraty
179*3cbdda60SSimon J. Gerratyinstall: maninstall install_links _SUBDIRUSE
180*3cbdda60SSimon J. Gerraty
181*3cbdda60SSimon J. Gerratyinstall_links:
182*3cbdda60SSimon J. Gerraty.if !empty(SYMLINKS)
183*3cbdda60SSimon J. Gerraty	@set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
184*3cbdda60SSimon J. Gerraty.endif
185*3cbdda60SSimon J. Gerraty.if !empty(LINKS)
186*3cbdda60SSimon J. Gerraty	@set ${LINKS}; ${_LINKS_SCRIPT}
187*3cbdda60SSimon J. Gerraty.endif
188*3cbdda60SSimon J. Gerraty
189*3cbdda60SSimon J. Gerratymaninstall: afterinstall
190*3cbdda60SSimon J. Gerratyafterinstall: realinstall
191*3cbdda60SSimon J. Gerratyrealinstall: beforeinstall
192*3cbdda60SSimon J. Gerraty.endif
193*3cbdda60SSimon J. Gerraty
194*3cbdda60SSimon J. Gerraty.if !target(lint)
195*3cbdda60SSimon J. Gerratylint: ${LOBJS}
196*3cbdda60SSimon J. Gerraty.if defined(LOBJS) && !empty(LOBJS)
197*3cbdda60SSimon J. Gerraty	@${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
198*3cbdda60SSimon J. Gerraty.endif
199*3cbdda60SSimon J. Gerraty.endif
200*3cbdda60SSimon J. Gerraty
201*3cbdda60SSimon J. Gerraty.NOPATH:	${PROG}
202*3cbdda60SSimon J. Gerraty.if defined(OBJS) && !empty(OBJS)
203*3cbdda60SSimon J. Gerraty.NOPATH:	${OBJS}
204*3cbdda60SSimon J. Gerraty.endif
205*3cbdda60SSimon J. Gerraty
206*3cbdda60SSimon J. Gerraty.if ${MK_MAN} != "no"
207*3cbdda60SSimon J. Gerraty.include <man.mk>
208*3cbdda60SSimon J. Gerraty.endif
209*3cbdda60SSimon J. Gerraty
210*3cbdda60SSimon J. Gerraty.if ${MK_NLS} != "no"
211*3cbdda60SSimon J. Gerraty.include <nls.mk>
212*3cbdda60SSimon J. Gerraty.endif
213*3cbdda60SSimon J. Gerraty
214*3cbdda60SSimon J. Gerraty.include <obj.mk>
215*3cbdda60SSimon J. Gerraty.include <dep.mk>
216*3cbdda60SSimon J. Gerraty.include <subdir.mk>
217*3cbdda60SSimon J. Gerraty.include <final.mk>
218*3cbdda60SSimon J. Gerraty
219*3cbdda60SSimon J. Gerraty.endif
220