xref: /freebsd/contrib/bmake/mk/prog.mk (revision 50d2e745fa6eaec4ff8fc4112b6b86ba2e27ffe3)
1*50d2e745SSimon J. Gerraty#	$Id: prog.mk,v 1.35 2018/01/26 20:04:07 sjg Exp $
23cbdda60SSimon J. Gerraty
33cbdda60SSimon J. Gerraty.if !target(__${.PARSEFILE}__)
43cbdda60SSimon J. Gerraty__${.PARSEFILE}__:
53cbdda60SSimon J. Gerraty
63cbdda60SSimon J. Gerraty.include <init.mk>
73cbdda60SSimon J. Gerraty
83cbdda60SSimon J. Gerraty# FreeBSD at least expects MAN8 etc.
93cbdda60SSimon J. Gerraty.if defined(MAN) && !empty(MAN)
103cbdda60SSimon J. Gerraty_sect:=${MAN:E}
113cbdda60SSimon J. GerratyMAN${_sect}=${MAN}
123cbdda60SSimon J. Gerraty.endif
133cbdda60SSimon J. Gerraty
143cbdda60SSimon J. Gerraty.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
153cbdda60SSimon J. Gerraty
163cbdda60SSimon J. GerratyCFLAGS+=	${COPTS}
173cbdda60SSimon J. Gerraty
183cbdda60SSimon J. Gerraty.if ${TARGET_OSNAME} == "NetBSD"
193cbdda60SSimon J. Gerraty.if ${MACHINE_ARCH} == "sparc64"
203cbdda60SSimon J. GerratyCFLAGS+=	-mcmodel=medlow
213cbdda60SSimon J. Gerraty.endif
223cbdda60SSimon J. Gerraty
233cbdda60SSimon J. Gerraty# ELF platforms depend on crtbegin.o and crtend.o
243cbdda60SSimon J. Gerraty.if ${OBJECT_FMT} == "ELF"
253cbdda60SSimon J. Gerraty.ifndef LIBCRTBEGIN
263cbdda60SSimon J. GerratyLIBCRTBEGIN=	${DESTDIR}/usr/lib/crtbegin.o
273cbdda60SSimon J. Gerraty.MADE: ${LIBCRTBEGIN}
283cbdda60SSimon J. Gerraty.endif
293cbdda60SSimon J. Gerraty.ifndef LIBCRTEND
303cbdda60SSimon J. GerratyLIBCRTEND=	${DESTDIR}/usr/lib/crtend.o
313cbdda60SSimon J. Gerraty.MADE: ${LIBCRTEND}
323cbdda60SSimon J. Gerraty.endif
333cbdda60SSimon J. Gerraty_SHLINKER=	${SHLINKDIR}/ld.elf_so
343cbdda60SSimon J. Gerraty.else
353cbdda60SSimon J. GerratyLIBCRTBEGIN?=
363cbdda60SSimon J. GerratyLIBCRTEND?=
373cbdda60SSimon J. Gerraty_SHLINKER=	${SHLINKDIR}/ld.so
383cbdda60SSimon J. Gerraty.endif
393cbdda60SSimon J. Gerraty
403cbdda60SSimon J. Gerraty.ifndef LIBCRT0
413cbdda60SSimon J. GerratyLIBCRT0=	${DESTDIR}/usr/lib/crt0.o
423cbdda60SSimon J. Gerraty.MADE: ${LIBCRT0}
433cbdda60SSimon J. Gerraty.endif
443cbdda60SSimon J. Gerraty.endif	# NetBSD
453cbdda60SSimon J. Gerraty
463cbdda60SSimon J. Gerraty# here is where you can define what LIB* are
473cbdda60SSimon J. Gerraty.-include <libnames.mk>
483cbdda60SSimon J. Gerraty.if ${MK_DPADD_MK} == "yes"
493cbdda60SSimon J. Gerraty# lots of cool magic, but might not suit everyone.
503cbdda60SSimon J. Gerraty.include <dpadd.mk>
513cbdda60SSimon J. Gerraty.endif
523cbdda60SSimon J. Gerraty
5351ee2c1cSSimon J. Gerraty.if ${MK_GPROF} == "yes"
5451ee2c1cSSimon J. GerratyCFLAGS+= ${CC_PG} ${PROFFLAGS}
5551ee2c1cSSimon J. GerratyLDADD+= ${CC_PG}
5651ee2c1cSSimon J. Gerraty.if ${MK_DPADD_MK} == "no"
5751ee2c1cSSimon J. GerratyLDADD_LIBC_P?= -lc_p
5851ee2c1cSSimon J. GerratyLDADD_LAST+= ${LDADD_LIBC_P}
5951ee2c1cSSimon J. Gerraty.endif
6051ee2c1cSSimon J. Gerraty.endif
6151ee2c1cSSimon J. Gerraty
623cbdda60SSimon J. Gerraty.if defined(SHAREDSTRINGS)
633cbdda60SSimon J. GerratyCLEANFILES+=strings
643cbdda60SSimon J. Gerraty.c.o:
653cbdda60SSimon J. Gerraty	${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
663cbdda60SSimon J. Gerraty	@${CC} ${CFLAGS} -c x.c -o ${.TARGET}
673cbdda60SSimon J. Gerraty	@rm -f x.c
683cbdda60SSimon J. Gerraty
69e48f47ddSSimon J. Gerraty${CXX_SUFFIXES:%=%.o}:
703cbdda60SSimon J. Gerraty	${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
713cbdda60SSimon J. Gerraty	@mv -f x.c x.cc
723cbdda60SSimon J. Gerraty	@${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
733cbdda60SSimon J. Gerraty	@rm -f x.cc
743cbdda60SSimon J. Gerraty.endif
753cbdda60SSimon J. Gerraty
763cbdda60SSimon J. Gerraty
773cbdda60SSimon J. Gerraty.if defined(PROG)
78cac6fd11SSimon J. GerratyBINDIR ?= ${prefix}/bin
79cac6fd11SSimon J. Gerraty
803cbdda60SSimon J. GerratySRCS?=	${PROG}.c
813cbdda60SSimon J. Gerraty.for s in ${SRCS:N*.h:N*.sh:M*/*}
823cbdda60SSimon J. Gerraty${.o .po .lo:L:@o@${s:T:R}$o@}: $s
833cbdda60SSimon J. Gerraty.endfor
843cbdda60SSimon J. Gerraty.if !empty(SRCS:N*.h:N*.sh)
853cbdda60SSimon J. GerratyOBJS+=	${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
863cbdda60SSimon J. GerratyLOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
873cbdda60SSimon J. Gerraty.endif
883cbdda60SSimon J. Gerraty
893cbdda60SSimon J. Gerraty.if defined(OBJS) && !empty(OBJS)
903cbdda60SSimon J. Gerraty.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
913cbdda60SSimon J. Gerraty
923cbdda60SSimon J. Gerraty# this is known to work for NetBSD 1.6 and FreeBSD 4.2
933cbdda60SSimon J. Gerraty.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
943cbdda60SSimon J. Gerraty_PROGLDOPTS=
953cbdda60SSimon J. Gerraty.if ${SHLINKDIR} != "/usr/libexec"	# XXX: change or remove if ld.so moves
963cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-dynamic-linker=${_SHLINKER}
973cbdda60SSimon J. Gerraty.endif
983cbdda60SSimon J. Gerraty.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
993cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
1003cbdda60SSimon J. Gerraty		-L${DESTDIR}${SHLIBDIR}
1013cbdda60SSimon J. Gerraty.endif
1023cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-rpath,${SHLIBDIR}:/usr/lib
1033cbdda60SSimon J. Gerraty
1043cbdda60SSimon J. Gerraty.if defined(PROG_CXX)
1053cbdda60SSimon J. Gerraty_CCLINK=	${CXX}
1063cbdda60SSimon J. Gerraty_SUPCXX=	-lstdc++ -lm
1073cbdda60SSimon J. Gerraty.endif
1083cbdda60SSimon J. Gerraty.endif	# NetBSD
1093cbdda60SSimon J. Gerraty
1103cbdda60SSimon J. Gerraty_CCLINK?=	${CC}
1113cbdda60SSimon J. Gerraty
112*50d2e745SSimon J. Gerraty.if ${MK_PROG_LDORDER_MK} != "no"
113*50d2e745SSimon J. Gerraty${PROG}: ldorder
114*50d2e745SSimon J. Gerraty
115*50d2e745SSimon J. Gerraty.include <ldorder.mk>
116*50d2e745SSimon J. Gerraty.endif
117*50d2e745SSimon J. Gerraty
1183cbdda60SSimon J. Gerraty.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
1193cbdda60SSimon J. Gerraty
1203cbdda60SSimon J. Gerraty${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
121*50d2e745SSimon J. Gerraty	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD_LDORDER} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
1223cbdda60SSimon J. Gerraty
1233cbdda60SSimon J. Gerraty.else
1243cbdda60SSimon J. Gerraty
1253cbdda60SSimon J. Gerraty${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
126*50d2e745SSimon J. Gerraty	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD_LDORDER} ${LDADD}
1273cbdda60SSimon J. Gerraty
1283cbdda60SSimon J. Gerraty.endif	# defined(DESTDIR)
1293cbdda60SSimon J. Gerraty.endif	# defined(OBJS) && !empty(OBJS)
1303cbdda60SSimon J. Gerraty
1313cbdda60SSimon J. Gerraty.if	!defined(MAN)
1323cbdda60SSimon J. GerratyMAN=	${PROG}.1
1333cbdda60SSimon J. Gerraty.endif	# !defined(MAN)
1343cbdda60SSimon J. Gerraty.endif	# defined(PROG)
1353cbdda60SSimon J. Gerraty
1363cbdda60SSimon J. Gerraty.if !defined(_SKIP_BUILD)
137cac6fd11SSimon J. Gerratyrealbuild: ${PROG}
1383cbdda60SSimon J. Gerraty.endif
139cac6fd11SSimon J. Gerraty
1403cbdda60SSimon J. Gerratyall: _SUBDIRUSE
1413cbdda60SSimon J. Gerraty
1423cbdda60SSimon J. Gerraty.if !target(clean)
1433cbdda60SSimon J. Gerratycleanprog:
1443cbdda60SSimon J. Gerraty	rm -f a.out [Ee]rrs mklog core *.core \
1453cbdda60SSimon J. Gerraty	    ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
1463cbdda60SSimon J. Gerraty
1473cbdda60SSimon J. Gerratyclean: _SUBDIRUSE cleanprog
1483cbdda60SSimon J. Gerratycleandir: _SUBDIRUSE cleanprog
1493cbdda60SSimon J. Gerraty.else
1503cbdda60SSimon J. Gerratycleandir: _SUBDIRUSE clean
1513cbdda60SSimon J. Gerraty.endif
1523cbdda60SSimon J. Gerraty
1533cbdda60SSimon J. Gerraty.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
1543cbdda60SSimon J. Gerratyafterdepend: .depend
1553cbdda60SSimon J. Gerraty	@(TMP=/tmp/_depend$$$$; \
1563cbdda60SSimon J. Gerraty	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
1573cbdda60SSimon J. Gerraty	      < .depend > $$TMP; \
1583cbdda60SSimon J. Gerraty	    mv $$TMP .depend)
1593cbdda60SSimon J. Gerraty.endif
1603cbdda60SSimon J. Gerraty
1613cbdda60SSimon J. Gerraty.if !target(install)
1623cbdda60SSimon J. Gerraty.if !target(beforeinstall)
1633cbdda60SSimon J. Gerratybeforeinstall:
1643cbdda60SSimon J. Gerraty.endif
1653cbdda60SSimon J. Gerraty.if !target(afterinstall)
1663cbdda60SSimon J. Gerratyafterinstall:
1673cbdda60SSimon J. Gerraty.endif
1683cbdda60SSimon J. Gerraty
1693cbdda60SSimon J. Gerraty.if !empty(BINOWN)
1703cbdda60SSimon J. GerratyPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
1713cbdda60SSimon J. Gerraty.endif
1723cbdda60SSimon J. Gerraty
1733cbdda60SSimon J. Gerraty.if !target(realinstall)
1743cbdda60SSimon J. Gerratyrealinstall: proginstall
1753cbdda60SSimon J. Gerraty.endif
1763cbdda60SSimon J. Gerraty.if !target(proginstall)
1773cbdda60SSimon J. Gerratyproginstall:
1783cbdda60SSimon J. Gerraty.if defined(PROG)
1793cbdda60SSimon J. Gerraty	[ -d ${DESTDIR}${BINDIR} ] || \
1803cbdda60SSimon J. Gerraty	${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
1813cbdda60SSimon J. Gerraty	${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
1823cbdda60SSimon J. Gerraty	    ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
1833cbdda60SSimon J. Gerraty.endif
1843cbdda60SSimon J. Gerraty.if defined(HIDEGAME)
1853cbdda60SSimon J. Gerraty	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
1863cbdda60SSimon J. Gerraty.endif
1873cbdda60SSimon J. Gerraty.endif
1883cbdda60SSimon J. Gerraty
1893cbdda60SSimon J. Gerraty.include <links.mk>
1903cbdda60SSimon J. Gerraty
1913cbdda60SSimon J. Gerratyinstall: maninstall install_links _SUBDIRUSE
1923cbdda60SSimon J. Gerraty
1933cbdda60SSimon J. Gerratyinstall_links:
1943cbdda60SSimon J. Gerraty.if !empty(SYMLINKS)
1953cbdda60SSimon J. Gerraty	@set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
1963cbdda60SSimon J. Gerraty.endif
1973cbdda60SSimon J. Gerraty.if !empty(LINKS)
1983cbdda60SSimon J. Gerraty	@set ${LINKS}; ${_LINKS_SCRIPT}
1993cbdda60SSimon J. Gerraty.endif
2003cbdda60SSimon J. Gerraty
2013cbdda60SSimon J. Gerratymaninstall: afterinstall
2023cbdda60SSimon J. Gerratyafterinstall: realinstall
2031ce939a7SSimon J. Gerratyinstall_links: realinstall
20495e3ed2cSSimon J. Gerratyproginstall: beforeinstall
2053cbdda60SSimon J. Gerratyrealinstall: beforeinstall
2063cbdda60SSimon J. Gerraty.endif
2073cbdda60SSimon J. Gerraty
2083cbdda60SSimon J. Gerraty.if !target(lint)
2093cbdda60SSimon J. Gerratylint: ${LOBJS}
2103cbdda60SSimon J. Gerraty.if defined(LOBJS) && !empty(LOBJS)
2113cbdda60SSimon J. Gerraty	@${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
2123cbdda60SSimon J. Gerraty.endif
2133cbdda60SSimon J. Gerraty.endif
2143cbdda60SSimon J. Gerraty
2153cbdda60SSimon J. Gerraty.NOPATH:	${PROG}
2163cbdda60SSimon J. Gerraty.if defined(OBJS) && !empty(OBJS)
2173cbdda60SSimon J. Gerraty.NOPATH:	${OBJS}
2183cbdda60SSimon J. Gerraty.endif
2193cbdda60SSimon J. Gerraty
220cac6fd11SSimon J. Gerraty.if defined(FILES) || defined(FILESGROUPS)
221cac6fd11SSimon J. Gerraty.include <files.mk>
222cac6fd11SSimon J. Gerraty.endif
223cac6fd11SSimon J. Gerraty
2243cbdda60SSimon J. Gerraty.if ${MK_MAN} != "no"
2253cbdda60SSimon J. Gerraty.include <man.mk>
2263cbdda60SSimon J. Gerraty.endif
2273cbdda60SSimon J. Gerraty
2283cbdda60SSimon J. Gerraty.if ${MK_NLS} != "no"
2293cbdda60SSimon J. Gerraty.include <nls.mk>
2303cbdda60SSimon J. Gerraty.endif
2313cbdda60SSimon J. Gerraty
2323cbdda60SSimon J. Gerraty.include <obj.mk>
2333cbdda60SSimon J. Gerraty.include <dep.mk>
2343cbdda60SSimon J. Gerraty.include <subdir.mk>
235cac6fd11SSimon J. Gerraty
236cac6fd11SSimon J. Gerraty.if !empty(PROG) && ${MK_STAGING_PROG} == "yes"
237cac6fd11SSimon J. GerratySTAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR}
238cac6fd11SSimon J. GerratySTAGE_DIR.prog ?= ${STAGE_BINDIR}
239cac6fd11SSimon J. Gerraty.if ${PROG_NAME:U${PROG}} != ${PROG}
240cac6fd11SSimon J. GerratySTAGE_AS_SETS += prog
241cac6fd11SSimon J. GerratySTAGE_AS_${PROG} = ${PROG_NAME}
242cac6fd11SSimon J. Gerratystage_as.prog: ${PROG}
243cac6fd11SSimon J. Gerraty.else
244cac6fd11SSimon J. GerratySTAGE_SETS += prog
245cac6fd11SSimon J. Gerratystage_files.prog: ${PROG}
246cac6fd11SSimon J. Gerraty.endif
247cac6fd11SSimon J. Gerraty.endif
248cac6fd11SSimon J. Gerraty
2493cbdda60SSimon J. Gerraty.include <final.mk>
2503cbdda60SSimon J. Gerraty
2513cbdda60SSimon J. Gerraty.endif
252