xref: /minix/share/mk/bsd.prog.mk (revision 90b80121)
1#	$NetBSD: bsd.prog.mk,v 1.292 2015/06/07 15:04:28 matt Exp $
2#	@(#)bsd.prog.mk	8.2 (Berkeley) 4/2/94
3
4.ifndef HOSTPROG
5
6.include <bsd.init.mk>
7.include <bsd.shlib.mk>
8.include <bsd.gcc.mk>
9.include <minix.gcov.mk>
10
11#
12# Definitions and targets shared among all programs built by a single
13# Makefile.
14#
15
16##### Basic targets
17realinstall:	proginstall scriptsinstall
18
19.gdbinit:
20	rm -f .gdbinit
21.if defined(DESTDIR) && !empty(DESTDIR)
22	echo "set solib-absolute-prefix ${DESTDIR}" > .gdbinit
23.else
24	touch .gdbinit
25.endif
26.for __gdbinit in ${GDBINIT}
27	echo "source ${__gdbinit}" >> .gdbinit
28.endfor
29
30CLEANFILES+= a.out [Ee]rrs mklog core *.core .gdbinit
31
32.if defined(SHAREDSTRINGS)
33CLEANFILES+=strings
34.c.o:
35	${CC} -E ${CPPFLAGS} ${CFLAGS} ${.IMPSRC} | xstr -c -
36	@${CC} ${CPPFLAGS} ${CFLAGS} -c x.c -o ${.TARGET}
37.if defined(CTFCONVERT)
38	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
39.endif
40	@rm -f x.c
41
42.cc.o .cpp.o .cxx.o .C.o:
43	${CXX} -E ${CPPFLAGS} ${CXXFLAGS} ${.IMPSRC} | xstr -c -
44	@mv -f x.c x.cc
45	@${CXX} ${CPPFLAGS} ${CXXFLAGS} -c x.cc -o ${.TARGET}
46.if defined(CTFCONVERT)
47	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
48.endif
49	@rm -f x.cc
50.endif
51
52.if defined(MKPIE) && (${MKPIE} != "no")
53CFLAGS+=	${PIE_CFLAGS}
54AFLAGS+=	${PIE_AFLAGS}
55LDFLAGS+=	${PIE_LDFLAGS}
56.endif
57
58CFLAGS+=	${COPTS}
59.if defined(MKDEBUG) && (${MKDEBUG} != "no")
60CFLAGS+=	-g
61.endif
62OBJCFLAGS+=	${OBJCOPTS}
63MKDEP_SUFFIXES?=	.o .ln .d
64
65# CTF preserve debug symbols
66.if (${MKCTF:Uno} != "no") && (${CFLAGS:M-g} != "")
67CTFFLAGS+= -g
68CTFMFLAGS+= -g
69.if defined(HAVE_GCC) && ${HAVE_GCC} >= 48
70#CFLAGS+=-gdwarf-2
71.endif
72.endif
73
74# ELF platforms depend on crti.o, crtbegin.o, crtend.o, and crtn.o
75.ifndef LIBCRTBEGIN
76LIBCRTBEGIN=	${DESTDIR}/usr/lib/${MLIBDIR:D${MLIBDIR}/}crti.o ${_GCC_CRTBEGIN}
77.MADE: ${LIBCRTBEGIN}
78.endif
79.ifndef LIBCRTEND
80LIBCRTEND=	${_GCC_CRTEND} ${DESTDIR}/usr/lib/${MLIBDIR:D${MLIBDIR}/}crtn.o
81.MADE: ${LIBCRTEND}
82.endif
83_SHLINKER=	${SHLINKDIR}/ld.elf_so
84
85.ifndef LIBCRT0
86LIBCRT0=	${DESTDIR}/usr/lib/${MLIBDIR:D${MLIBDIR}/}crt0.o
87.MADE: ${LIBCRT0}
88.endif
89
90.ifndef LIBCRTI
91LIBCRTI=	${DESTDIR}/usr/lib/${MLIBDIR:D${MLIBDIR}/}crti.o
92.MADE: ${LIBCRTI}
93.endif
94
95##### Installed system library definitions
96#
97#	E.g.
98#		LIBC?=${DESTDIR}/usr/lib/libc.a
99#		LIBX11?=${DESTDIR}/usr/X11R7/lib/libX11.a
100#	etc..
101#	NB:	If you are a library here, add it in bsd.README
102
103.for _lib in \
104	archive \
105	asn1 \
106	atf_c \
107	atf_cxx \
108	bind9 \
109	bluetooth \
110	bsdmalloc \
111	bz2 \
112	c \
113	c_pic \
114	com_err \
115	compat \
116	crypt \
117	crypto \
118	crypto_idea \
119	crypto_mdc2 \
120	crypto_rc5 \
121	curses \
122	dbm \
123	des \
124	dns \
125	edit \
126	event \
127	expat \
128	fetch \
129	fl \
130	form \
131	g2c \
132	gcc \
133	gnumalloc \
134	gssapi \
135	hdb \
136	heimbase \
137	heimntlm \
138	hx509 \
139	intl \
140	ipsec \
141	isc \
142	isccc \
143	isccfg \
144	kadm5clnt \
145	kadm5srv \
146	kafs \
147	krb5 \
148	kvm \
149	l \
150	lber \
151	ldap \
152	ldap_r \
153	lua \
154	lwres \
155	m \
156	magic \
157	menu \
158	objc \
159	ossaudio \
160	pam \
161	pcap \
162	pci \
163	pmc \
164	posix \
165	pthread \
166	pthread_dbg \
167	puffs \
168	quota \
169	radius \
170	resolv \
171	rmt \
172	roken \
173	rpcsvc \
174	rt \
175	rump \
176	rumpfs_cd9660fs \
177	rumpfs_efs \
178	rumpfs_ext2fs \
179	rumpfs_ffs \
180	rumpfs_hfs \
181	rumpfs_lfs \
182	rumpfs_msdosfs \
183	rumpfs_nfs \
184	rumpfs_ntfs \
185	rumpfs_syspuffs \
186	rumpfs_tmpfs \
187	rumpfs_udf \
188	rumpfs_ufs \
189	rumpuser \
190	saslc \
191	skey \
192	sl \
193	sqlite3 \
194	ss \
195	ssh \
196	ssl \
197	ssp \
198	stdcxx \
199	supcxx \
200	terminfo \
201	tre \
202	usbhid \
203	util \
204	wind \
205	wrap \
206	y \
207	z
208
209.ifndef LIB${_lib:tu}
210LIB${_lib:tu}=	${DESTDIR}/usr/lib/lib${_lib:S/xx/++/:S/atf_c/atf-c/}.a
211.MADE:		${LIB${_lib:tu}}	# Note: ${DESTDIR} will be expanded
212.endif
213.endfor
214
215# Minix libraries
216.for _lib in \
217	audiodriver \
218	bdev \
219	blockdriver \
220	chardriver \
221	clkconf \
222	ddekit \
223	ddekit_usb_client \
224	ddekit_usb_server \
225	devman \
226	elf \
227	exec \
228	fsdriver \
229	gpio \
230	hgfs \
231	i2cdriver \
232	inputdriver \
233	lwip \
234	minc \
235	minixfs \
236	mthread \
237	netdriver \
238	sffs \
239	sockdriver \
240	sockevent \
241	sys \
242	timers \
243	usb \
244	vboxfs \
245	virtio \
246	vtreefs
247.ifndef LIB${_lib:tu}
248LIB${_lib:tu}=	${DESTDIR}/usr/lib/lib${_lib:S/xx/++/:S/atf_c/atf-c/}.a
249.MADE:		${LIB${_lib:tu}}	# Note: ${DESTDIR} will be expanded
250.endif
251.endfor
252
253# PAM applications, if linked statically, need more libraries
254.if (${MKPIC} == "no")
255.if (${MKCRYPTO} != "no")
256PAM_STATIC_LDADD+= -lssh
257PAM_STATIC_DPADD+= ${LIBSSH}
258.endif
259.if (${MKKERBEROS} != "no")
260PAM_STATIC_LDADD+= -lkafs -lkrb5 -lhx509 -lwind -lasn1 \
261	-lroken -lcom_err -lheimbase -lcrypto
262PAM_STATIC_DPADD+= ${LIBKAFS} ${LIBKRB5} ${LIBHX509} ${LIBWIND} ${LIBASN1} \
263	${LIBROKEN} ${LIBCOM_ERR} ${LIBHEIMBASE} ${LIBCRYPTO}
264.endif
265.if (${MKSKEY} != "no")
266PAM_STATIC_LDADD+= -lskey
267PAM_STATIC_DPADD+= ${LIBSKEY}
268.endif
269PAM_STATIC_LDADD+= -lradius -lcrypt -lrpcsvc -lutil
270PAM_STATIC_DPADD+= ${LIBRADIUS} ${LIBCRYPT} ${LIBRPCSVC} ${LIBUTIL}
271.else
272PAM_STATIC_LDADD=
273PAM_STATIC_DPADD=
274.endif
275
276.if defined(__MINIX) && ${MACHINE_ARCH} == "earm"
277# LSC: On ARM, when compiling statically, with gcc, lgcc_eh is required
278LDFLAGS+= ${${ACTIVE_CC} == "gcc":? -lgcc_eh:}
279.endif # defined(__MINIX) && ${MACHINE_ARCH} == "earm"
280
281#	NB:	If you are a library here, add it in bsd.README
282.for _lib in \
283	FS \
284	GL \
285	GLU \
286	ICE \
287	SM \
288	X11 \
289	XTrap \
290	Xau \
291	Xaw \
292	Xdmcp \
293	Xext \
294	Xfont \
295	Xft \
296	Xi \
297	Xinerama \
298	Xmu \
299	Xmuu \
300	Xpm \
301	Xrandr \
302	Xrender \
303	Xss \
304	Xt \
305	Xtst \
306	Xv \
307	Xxf86dga \
308	Xxf86misc \
309	Xxf86vm \
310	dps \
311	fntstubs \
312	fontcache \
313	fontconfig \
314	fontenc \
315	freetype \
316	lbxutil \
317	xkbfile
318.ifndef LIB${_lib:tu}
319LIB${_lib:tu}=	${DESTDIR}${X11USRLIBDIR}/lib${_lib}.a
320.MADE:		${LIB${_lib:tu}}	# Note: ${DESTDIR} will be expanded
321.endif
322.endfor
323
324# Ugly one-offs
325LIBX11_XCB=	${DESTDIR}${X11USRLIBDIR}/libX11-xcb.a
326LIBXCB=	${DESTDIR}${X11USRLIBDIR}/libxcb.a
327
328.if defined(RESCUEDIR)
329CPPFLAGS+=	-DRESCUEDIR=\"${RESCUEDIR}\"
330.endif
331
332_PROGLDOPTS=
333.if ${SHLINKDIR} != "/usr/libexec"	# XXX: change or remove if ld.so moves
334_PROGLDOPTS+=	-Wl,-dynamic-linker=${_SHLINKER}
335.endif
336.if ${SHLIBDIR} != "/usr/lib"
337_PROGLDOPTS+=	-Wl,-rpath,${SHLIBDIR} \
338		-L=${SHLIBDIR}
339.elif ${SHLIBINSTALLDIR} != "/usr/lib"
340_PROGLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
341		-L=${SHLIBINSTALLDIR}
342.endif
343
344__proginstall: .USE
345	${_MKTARGET_INSTALL}
346	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
347		${STRIPFLAG} ${.ALLSRC} ${.TARGET}
348
349__progrumpinstall: .USE
350	${_MKTARGET_INSTALL}
351	${INSTALL_FILE} -o ${RUMPBINOWN} -g ${RUMPBINGRP} -m ${RUMPBINMODE} \
352		${STRIPFLAG} ${.ALLSRC} ${.TARGET}
353
354__progdebuginstall: .USE
355	${_MKTARGET_INSTALL}
356	${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
357		${.ALLSRC} ${.TARGET}
358
359
360
361#
362# Backwards compatibility with Makefiles that assume that bsd.prog.mk
363# can only build a single binary.
364#
365
366_APPEND_MANS=yes
367_APPEND_SRCS=yes
368
369_CCLINKFLAGS=
370
371.if defined(PROG_CXX)
372PROG=		${PROG_CXX}
373_CCLINK=	${CXX} ${_CCLINKFLAGS}
374
375.if defined(__MINIX)
376# BJG - stack unwinding (for C++ exceptions) doesn't work on static executables when built with llvm.
377LDSTATIC=	-dynamic
378.endif # defined(__MINIX)
379.endif
380
381.if defined(RUMPPRG)
382PROG=			${RUMPPRG}
383. ifndef CRUNCHEDPROG
384.  if (${MKRUMP} != "no")
385PROGS=			${RUMPPRG} rump.${RUMPPRG}
386.  else
387PROGS=			${RUMPPRG}
388.  endif
389.  if defined(SRCS)
390.   if (${MKRUMP} != "no")
391SRCS.rump.${PROG}:=	${SRCS} ${PROG}_rumpops.c ${RUMPSRCS}
392.   endif
393SRCS+=			${PROG}_hostops.c
394.  else
395SRCS=			${PROG}.c ${PROG}_hostops.c
396.   if (${MKRUMP} != "no")
397SRCS.rump.${PROG}=	${PROG}.c ${PROG}_rumpops.c ${RUMPSRCS}
398.   endif
399.  endif
400.   if (${MKRUMP} != "no")
401DPSRCS+=		${PROG}_rumpops.c ${RUMPSRCS}
402LDADD.rump.${PROG}+=	-lrumpclient
403DPADD.rump.${PROG}+=	${LIBRUMPCLIENT}
404MAN.rump.${PROG}=	# defined but feeling empty
405_RUMPINSTALL.rump.${PROG}=# defined
406.   endif
407. else # CRUNCHEDPROG
408PROGS=			${PROG}
409CPPFLAGS+=		-DCRUNCHOPS
410. endif
411.endif
412
413.if defined(PROG)
414_CCLINK?=	${CC} ${_CCLINKFLAGS}
415.  if defined(MAN)
416MAN.${PROG}=	${MAN}
417_APPEND_MANS=	no
418.  endif
419.  if !defined(OBJS)
420OBJS=		${OBJS.${PROG}}
421.  endif
422.  if defined(PROGNAME)
423PROGNAME.${PROG}=	${PROGNAME}
424.  endif
425.  if defined(SRCS)
426SRCS.${PROG}=	${SRCS}
427_APPEND_SRCS=	no
428.  endif
429.endif
430
431# Turn the single-program PROG and PROG_CXX variables into their multi-word
432# counterparts, PROGS and PROGS_CXX.
433.if !defined(RUMPPRG)
434.  if defined(PROG_CXX) && !defined(PROGS_CXX)
435PROGS_CXX=	${PROG_CXX}
436.  elif defined(PROG) && !defined(PROGS)
437PROGS=		${PROG}
438.  endif
439.endif
440
441##### Libraries that this may depend upon.
442.if defined(PROGDPLIBS) 						# {
443.for _lib _dir in ${PROGDPLIBS}
444.if !defined(BINDO.${_lib})
445PROGDO.${_lib}!=	cd "${_dir}" && ${PRINTOBJDIR}
446.MAKEOVERRIDES+=PROGDO.${_lib}
447.endif
448LDADD+=		-L${PROGDO.${_lib}} -l${_lib}
449.if exists(${PROGDO.${_lib}}/lib${_lib}_pic.a)
450DPADD+=		${PROGDO.${_lib}}/lib${_lib}_pic.a
451.elif exists(${PROGDO.${_lib}}/lib${_lib}.so)
452DPADD+=		${PROGDO.${_lib}}/lib${_lib}.so
453.else
454DPADD+=		${PROGDO.${_lib}}/lib${_lib}.a
455.endif
456.endfor
457.endif									# }
458#
459# Per-program definitions and targets.
460#
461
462_CCLINK.CDEFAULT= ${CC} ${_CCLINKFLAGS}
463# Definitions specific to C programs.
464.for _P in ${PROGS}
465SRCS.${_P}?=	${_P}.c
466_CCLINK.${_P}=	${CC} ${_CCLINKFLAGS}
467_CFLAGS.${_P}=	${CFLAGS} ${CPUFLAGS}
468_CPPFLAGS.${_P}=	${CPPFLAGS}
469_COPTS.${_P}=	${COPTS}
470.endfor
471
472_CCLINK.CXXDEFAULT= ${CXX} ${_CCLINKFLAGS}
473# Definitions specific to C++ programs.
474.for _P in ${PROGS_CXX}
475SRCS.${_P}?=	${_P}.cc
476_CCLINK.${_P}=	${CXX} ${_CCLINKFLAGS}
477.endfor
478
479# Language-independent definitions.
480.if defined(__MINIX)
481.if ${USE_BITCODE:Uno} == "yes"
482CFLAGS+= -flto
483.endif # ${USE_BITCODE:Uno} == "yes"
484
485.if ${USE_BITCODE:Uyes} == "no"
486#LSC Gold linker seems to require the library directory to be set up if
487#    a sysroot parameter has been given.
488LDFLAGS+= -L ${DESTDIR}/usr/lib
489.endif # ${USE_BITCODE:U} == "no"
490.endif # defined(__MINIX)
491
492.for _P in ${PROGS} ${PROGS_CXX}					# {
493
494BINDIR.${_P}?=		${BINDIR}
495PROGNAME.${_P}?=	${_P}
496
497.if ${MKDEBUG} != "no" && !commands(${_P})
498_PROGDEBUG.${_P}:=	${PROGNAME.${_P}}.debug
499.endif
500
501.if defined(PAXCTL_FLAGS)
502PAXCTL_FLAGS.${_P}?= ${PAXCTL_FLAGS}
503.endif
504
505##### PROG specific flags.
506
507_DPADD.${_P}=		${DPADD}    ${DPADD.${_P}}
508_LDADD.${_P}=		${LDADD}    ${LDADD.${_P}}
509_LDFLAGS.${_P}=		${LDFLAGS}  ${LDFLAGS.${_P}}
510_LDSTATIC.${_P}=	${LDSTATIC} ${LDSTATIC.${_P}}
511
512##### Build and install rules
513.if !empty(_APPEND_SRCS:M[Yy][Ee][Ss])
514SRCS+=		${SRCS.${_P}}	# For bsd.dep.mk
515.endif
516
517_YPSRCS.${_P}=	${SRCS.${_P}:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS.${_P}:M*.y:.y=.h}}
518
519DPSRCS+=		${_YPSRCS.${_P}}
520CLEANFILES+=		${_YPSRCS.${_P}}
521
522.if !empty(SRCS.${_P}:N*.h:N*.sh:N*.fth)
523OBJS.${_P}+=	${SRCS.${_P}:N*.h:N*.sh:N*.fth:R:S/$/.o/g}
524LOBJS.${_P}+=	${LSRCS:.c=.ln} ${SRCS.${_P}:M*.c:.c=.ln}
525.endif
526
527.if defined(OBJS.${_P}) && !empty(OBJS.${_P})			# {
528.NOPATH: ${OBJS.${_P}} ${_P} ${_YPSRCS.${_P}}
529
530.if (defined(USE_COMBINE) && ${USE_COMBINE} != "no" && !commands(${_P}) \
531   && (${_CCLINK.${_P}} == ${_CCLINK.CDEFAULT} \
532       || ${_CCLINK.${_P}} == ${_CCLINK.CXXDEFAULT}) \
533   && !defined(NOCOMBINE.${_P}) && !defined(NOCOMBINE))
534.for f in ${SRCS.${_P}:N*.h:N*.sh:N*.fth:C/\.[yl]$/.c/g}
535#_XFLAGS.$f := ${CPPFLAGS.$f:D1} ${CPUFLAGS.$f:D2} \
536#     ${COPTS.$f:D3} ${OBJCOPTS.$f:D4} ${CXXFLAGS.$f:D5}
537.if (${CPPFLAGS.$f:D1} == "1" || ${CPUFLAGS.$f:D2} == "2" \
538     || ${COPTS.$f:D3} == "3" || ${OBJCOPTS.$f:D4} == "4" \
539     || ${CXXFLAGS.$f:D5} == "5") \
540    || ("${f:M*.[cyl]}" == "" || commands(${f:R:S/$/.o/}))
541XOBJS.${_P}+=	${f:R:S/$/.o/}
542.else
543XSRCS.${_P}+=	${f}
544NODPSRCS+=	${f}
545.endif
546.endfor
547
548${_P}: .gdbinit ${LIBCRT0} ${LIBCRTI} ${XOBJS.${_P}} ${SRCS.${_P}} \
549    ${DPSRCS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${_DPADD.${_P}}
550	${_MKTARGET_LINK}
551.if defined(DESTDIR)
552	${_CCLINK.${_P}} -Wl,-nostdlib \
553	    ${_LDFLAGS.${_P}} ${_LDSTATIC.${_P}} -o ${.TARGET} ${_PROGLDOPTS} \
554	    -B${_GCC_CRTDIR}/ -B${DESTDIR}/usr/lib/ \
555	    -MD --combine ${_CPPFLAGS.${_P}} ${_CFLAGS.${_P}} ${_COPTS.${_P}} \
556	    ${XSRCS.${_P}:@.SRC.@${.ALLSRC:M*.c:M*${.SRC.}}@:O:u} ${XOBJS.${_P}} \
557	    ${_LDADD.${_P}} -L${_GCC_LIBGCCDIR} -L${DESTDIR}/usr/lib
558.else
559	${_CCLINK.${_P}} ${_LDFLAGS.${_P}} ${_LDSTATIC.${_P}} -o ${.TARGET} ${_PROGLDOPTS} \
560	    -MD --combine ${_CPPFLAGS.${_P}} ${_COPTS.${_P}}
561	    ${XSRCS.${_P}:@.SRC.@${.ALLSRC:M*.c:M*${.SRC.}}@:O:u} ${XOBJS.${_P}} \
562	    ${_LDADD.${_P}}
563.endif	# defined(DESTDIR)
564.if defined(CTFMERGE)
565	${CTFMERGE} ${CTFMFLAGS} -o ${.TARGET} ${OBJS.${_P}}
566.endif
567.if defined(PAXCTL_FLAGS.${_P})
568	${PAXCTL} ${PAXCTL_FLAGS.${_P}} ${.TARGET}
569.endif
570.if ${MKSTRIPIDENT} != "no"
571	${OBJCOPY} -R .ident ${.TARGET}
572.endif
573
574CLEANFILES+=	${_P}.d
575.if exists(${_P}.d)
576.include "${_P}.d"		# include -MD depend for program.
577.endif
578.else	# USE_COMBINE
579
580${OBJS.${_P}} ${LOBJS.${_P}}: ${DPSRCS}
581
582.if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
583CLEANFILES+= ${_P}.opt.bcl ${_P}.bcl ${_P}.bcl.o
584
585OPTFLAGS.${_P}?= ${OPTFLAGS}
586BITCODE_LD_FLAGS_1ST.${_P}+= ${BITCODE_LD_FLAGS_1ST}
587BITCODE_LD_FLAGS_2ND.${_P}+= ${BITCODE_LD_FLAGS_2ND}
588
589${_P}.bcl: .gdbinit ${LIBCRT0} ${LIBCRTI} ${OBJS.${_P}} ${LIBC} ${LIBCRTBEGIN} \
590    ${LIBCRTEND} ${_DPADD.${_P}}
591	${_MKTARGET_LINK}
592	${_CCLINK.${_P}} \
593		-o ${.TARGET} \
594		-nostartfiles \
595		-L${DESTDIR}/usr/lib/bc \
596		${OBJS.${_P}} ${LLVM_LINK_ARGS} ${_LDADD.${_P}:N-shared} \
597		${_LDSTATIC.${_P}} ${_PROGLDOPTS} \
598		-Wl,-r \
599		${BITCODE_LD_FLAGS_1ST.${_P}} \
600		-Wl,-plugin-opt=emit-llvm
601
602${_P}.opt.bcl: ${_P}.bcl ${LLVM_PASS}
603	${_MKTARGET_LINK}
604	${OPT} ${OPTFLAGS.${_P}} -o ${.TARGET} ${_P}.bcl
605
606${_P}.bcl.o: ${_P}.opt.bcl
607	${_MKTARGET_LINK}
608	${LLC} -O1 -march=x86 -mcpu=i586 -filetype=obj -o ${.TARGET} ${.ALLSRC}
609
610${_P}: ${_P}.bcl.o
611.if !commands(${_P})
612	${_MKTARGET_LINK}
613	${_CCLINK.${_P}} \
614		${_LDFLAGS.${_P}} \
615		-L${DESTDIR}/usr/lib \
616		${_LDSTATIC.${_P}} -o ${.TARGET} \
617		${.TARGET}.bcl.o ${_PROGLDOPTS} ${_LDADD.${_P}} \
618		${BITCODE_LD_FLAGS_2ND.${_P}} \
619		-Wl,--allow-multiple-definition
620.endif	# !commands(${_P})
621
622.else
623${_P}: .gdbinit ${LIBCRT0} ${LIBCRTI} ${OBJS.${_P}} ${LIBC} ${LIBCRTBEGIN} \
624    ${LIBCRTEND} ${_DPADD.${_P}}
625.if !commands(${_P})
626	${_MKTARGET_LINK}
627	${_CCLINK.${_P}} \
628	    ${_LDFLAGS.${_P}} ${_LDSTATIC.${_P}} -o ${.TARGET} \
629	    ${OBJS.${_P}} ${_PROGLDOPTS} ${_LDADD.${_P}}
630.if defined(CTFMERGE)
631	${CTFMERGE} ${CTFMFLAGS} -o ${.TARGET} ${OBJS.${_P}}
632.endif
633.if defined(PAXCTL_FLAGS.${_P})
634	${PAXCTL} ${PAXCTL_FLAGS.${_P}} ${.TARGET}
635.endif
636.if ${MKSTRIPIDENT} != "no"
637	${OBJCOPY} -R .ident ${.TARGET}
638.endif
639.endif	# !commands(${_P})
640.endif  # defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
641.endif	# USE_COMBINE
642
643${_P}.ro: ${OBJS.${_P}} ${_DPADD.${_P}}
644	${_MKTARGET_LINK}
645	${CC} ${LDFLAGS:N-Wl,-pie} -nostdlib -r -Wl,-dc -o ${.TARGET} ${OBJS.${_P}}
646
647.if defined(_PROGDEBUG.${_P})
648${_PROGDEBUG.${_P}}: ${_P}
649	${_MKTARGET_CREATE}
650	(  ${OBJCOPY} --only-keep-debug ${_P} ${_PROGDEBUG.${_P}} \
651	&& ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
652		--add-gnu-debuglink=${_PROGDEBUG.${_P}} ${_P} \
653	) || (rm -f ${_PROGDEBUG.${_P}}; false)
654.endif
655
656.endif	# defined(OBJS.${_P}) && !empty(OBJS.${_P})			# }
657
658.if !defined(MAN.${_P})
659MAN.${_P}=	${_P}.1
660.endif	# !defined(MAN.${_P})
661.if !empty(_APPEND_MANS:M[Yy][Ee][Ss])
662MAN+=		${MAN.${_P}}
663.endif
664
665realall: ${_P} ${_PROGDEBUG.${_P}}
666
667CLEANFILES+= ${_P} ${_PROGDEBUG.${_P}}
668
669.if defined(OBJS.${_P}) && !empty(OBJS.${_P})
670CLEANFILES+= ${OBJS.${_P}} ${LOBJS.${_P}}
671.endif
672
673_PROG_INSTALL+=	proginstall-${_P}
674
675.if !target(proginstall-${_P})						# {
676proginstall-${_P}::	${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}} \
677		${_PROGDEBUG.${_P}:D${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}}
678.PRECIOUS:	${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}} \
679		${_PROGDEBUG.${_P}:D${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}}
680
681.if ${MKUPDATE} == "no"
682.if defined(_RUMPINSTALL.${_P})
683${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}! ${_P} __progrumpinstall
684.else
685${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}! ${_P} __proginstall
686.endif
687.if !defined(BUILD) && !make(all) && !make(${_P})
688${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}! .MADE
689.endif
690.if defined(_PROGDEBUG.${_P})
691${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}! ${_PROGDEBUG.${_P}} __progdebuginstall
692.if !defined(BUILD) && !make(all) && !make(${_P})
693${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}! .MADE
694.endif
695.endif	#  define(_PROGDEBUG.${_P})
696.else	# MKUPDATE != no
697.if defined(_RUMPINSTALL.${_P})
698${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}: ${_P} __progrumpinstall
699.else
700${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}: ${_P} __proginstall
701.endif
702.if !defined(BUILD) && !make(all) && !make(${_P})
703${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}: .MADE
704.endif
705.if defined(_PROGDEBUG.${_P})
706${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}: ${_PROGDEBUG.${_P}} __progdebuginstall
707.if !defined(BUILD) && !make(all) && !make(${_P})
708${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}: .MADE
709.endif
710.endif	#  defined(_PROGDEBUG.${_P})
711.endif	# MKUPDATE != no
712
713.endif	# !target(proginstall-${_P})					# }
714
715lint: lint-${_P}
716lint-${_P}: ${LOBJS.${_P}}
717.if defined(LOBJS.${_P}) && !empty(LOBJS.${_P})
718	${LINT} ${LINTFLAGS} ${_LDFLAGS.${_P}:C/-L[  ]*/-L/Wg:M-L*} ${LOBJS.${_P}} ${_LDADD.${_P}}
719.endif
720
721.endfor # _P in ${PROGS} ${PROGS_CXX}					# }
722
723.if defined(OBJS) && !empty(OBJS) && \
724    (empty(PROGS) && empty(PROGS_CXX))
725CLEANFILES+= ${OBJS} ${LOBJS}
726.endif
727
728.if !target(proginstall)
729proginstall:: ${_PROG_INSTALL}
730.endif
731.PHONY:		proginstall
732
733
734
735realall: ${SCRIPTS}
736.if defined(SCRIPTS) && !target(scriptsinstall)				# {
737SCRIPTSDIR?=${BINDIR}
738SCRIPTSOWN?=${BINOWN}
739SCRIPTSGRP?=${BINGRP}
740SCRIPTSMODE?=${BINMODE}
741
742scriptsinstall:: ${SCRIPTS:@S@${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}@}
743.PRECIOUS: ${SCRIPTS:@S@${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}@}
744
745__scriptinstall: .USE
746	${_MKTARGET_INSTALL}
747	${INSTALL_FILE} \
748	    -o ${SCRIPTSOWN_${.ALLSRC:T}:U${SCRIPTSOWN}} \
749	    -g ${SCRIPTSGRP_${.ALLSRC:T}:U${SCRIPTSGRP}} \
750	    -m ${SCRIPTSMODE_${.ALLSRC:T}:U${SCRIPTSMODE}} \
751	    ${.ALLSRC} ${.TARGET}
752
753.for S in ${SCRIPTS:O:u}
754.if ${MKUPDATE} == "no"
755${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}! ${S} __scriptinstall
756.if !defined(BUILD) && !make(all) && !make(${S})
757${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}! .MADE
758.endif
759.else
760${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}: ${S} __scriptinstall
761.if !defined(BUILD) && !make(all) && !make(${S})
762${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}: .MADE
763.endif
764.endif
765.endfor
766.endif									# }
767
768.if !target(scriptsinstall)
769scriptsinstall::
770.endif
771.PHONY:		scriptsinstall
772
773##### Pull in related .mk logic
774LINKSOWN?= ${BINOWN}
775LINKSGRP?= ${BINGRP}
776LINKSMODE?= ${BINMODE}
777.include <bsd.man.mk>
778.include <bsd.nls.mk>
779.include <bsd.files.mk>
780.include <bsd.inc.mk>
781.include <bsd.links.mk>
782.include <bsd.sys.mk>
783.include <bsd.dep.mk>
784.include <bsd.clang-analyze.mk>
785.include <bsd.clean.mk>
786
787${TARGETS}:	# ensure existence
788
789.endif	# HOSTPROG
790