xref: /freebsd/contrib/bmake/mk/prog.mk (revision e48f47ddc1225f9d2c8f40e9537ab6022ec30f7f)
1*e48f47ddSSimon J. Gerraty#	$Id: prog.mk,v 1.26 2016/03/22 20:45:14 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
69*e48f47ddSSimon 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)
783cbdda60SSimon J. GerratySRCS?=	${PROG}.c
793cbdda60SSimon J. Gerraty.for s in ${SRCS:N*.h:N*.sh:M*/*}
803cbdda60SSimon J. Gerraty${.o .po .lo:L:@o@${s:T:R}$o@}: $s
813cbdda60SSimon J. Gerraty.endfor
823cbdda60SSimon J. Gerraty.if !empty(SRCS:N*.h:N*.sh)
833cbdda60SSimon J. GerratyOBJS+=	${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
843cbdda60SSimon J. GerratyLOBJS+=	${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
853cbdda60SSimon J. Gerraty.endif
863cbdda60SSimon J. Gerraty
873cbdda60SSimon J. Gerraty.if defined(OBJS) && !empty(OBJS)
883cbdda60SSimon J. Gerraty.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
893cbdda60SSimon J. Gerraty
903cbdda60SSimon J. Gerraty# this is known to work for NetBSD 1.6 and FreeBSD 4.2
913cbdda60SSimon J. Gerraty.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
923cbdda60SSimon J. Gerraty_PROGLDOPTS=
933cbdda60SSimon J. Gerraty.if ${SHLINKDIR} != "/usr/libexec"	# XXX: change or remove if ld.so moves
943cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-dynamic-linker=${_SHLINKER}
953cbdda60SSimon J. Gerraty.endif
963cbdda60SSimon J. Gerraty.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
973cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
983cbdda60SSimon J. Gerraty		-L${DESTDIR}${SHLIBDIR}
993cbdda60SSimon J. Gerraty.endif
1003cbdda60SSimon J. Gerraty_PROGLDOPTS+=	-Wl,-rpath,${SHLIBDIR}:/usr/lib
1013cbdda60SSimon J. Gerraty
1023cbdda60SSimon J. Gerraty.if defined(PROG_CXX)
1033cbdda60SSimon J. Gerraty_CCLINK=	${CXX}
1043cbdda60SSimon J. Gerraty_SUPCXX=	-lstdc++ -lm
1053cbdda60SSimon J. Gerraty.endif
1063cbdda60SSimon J. Gerraty.endif	# NetBSD
1073cbdda60SSimon J. Gerraty
1083cbdda60SSimon J. Gerraty_CCLINK?=	${CC}
1093cbdda60SSimon J. Gerraty
1103cbdda60SSimon J. Gerraty.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
1113cbdda60SSimon J. Gerraty
1123cbdda60SSimon J. Gerraty${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
1133cbdda60SSimon 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}
1143cbdda60SSimon J. Gerraty
1153cbdda60SSimon J. Gerraty.else
1163cbdda60SSimon J. Gerraty
1173cbdda60SSimon J. Gerraty${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
1183cbdda60SSimon J. Gerraty	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
1193cbdda60SSimon J. Gerraty
1203cbdda60SSimon J. Gerraty.endif	# defined(DESTDIR)
1213cbdda60SSimon J. Gerraty.endif	# defined(OBJS) && !empty(OBJS)
1223cbdda60SSimon J. Gerraty
1233cbdda60SSimon J. Gerraty.if	!defined(MAN)
1243cbdda60SSimon J. GerratyMAN=	${PROG}.1
1253cbdda60SSimon J. Gerraty.endif	# !defined(MAN)
1263cbdda60SSimon J. Gerraty.endif	# defined(PROG)
1273cbdda60SSimon J. Gerraty
1283cbdda60SSimon J. Gerraty.if !defined(_SKIP_BUILD)
1293cbdda60SSimon J. Gerratyall: ${PROG}
1303cbdda60SSimon J. Gerraty.endif
1313cbdda60SSimon J. Gerratyall: _SUBDIRUSE
1323cbdda60SSimon J. Gerraty
1333cbdda60SSimon J. Gerraty.if !target(clean)
1343cbdda60SSimon J. Gerratycleanprog:
1353cbdda60SSimon J. Gerraty	rm -f a.out [Ee]rrs mklog core *.core \
1363cbdda60SSimon J. Gerraty	    ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
1373cbdda60SSimon J. Gerraty
1383cbdda60SSimon J. Gerratyclean: _SUBDIRUSE cleanprog
1393cbdda60SSimon J. Gerratycleandir: _SUBDIRUSE cleanprog
1403cbdda60SSimon J. Gerraty.else
1413cbdda60SSimon J. Gerratycleandir: _SUBDIRUSE clean
1423cbdda60SSimon J. Gerraty.endif
1433cbdda60SSimon J. Gerraty
1443cbdda60SSimon J. Gerraty.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
1453cbdda60SSimon J. Gerratyafterdepend: .depend
1463cbdda60SSimon J. Gerraty	@(TMP=/tmp/_depend$$$$; \
1473cbdda60SSimon J. Gerraty	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
1483cbdda60SSimon J. Gerraty	      < .depend > $$TMP; \
1493cbdda60SSimon J. Gerraty	    mv $$TMP .depend)
1503cbdda60SSimon J. Gerraty.endif
1513cbdda60SSimon J. Gerraty
1523cbdda60SSimon J. Gerraty.if !target(install)
1533cbdda60SSimon J. Gerraty.if !target(beforeinstall)
1543cbdda60SSimon J. Gerratybeforeinstall:
1553cbdda60SSimon J. Gerraty.endif
1563cbdda60SSimon J. Gerraty.if !target(afterinstall)
1573cbdda60SSimon J. Gerratyafterinstall:
1583cbdda60SSimon J. Gerraty.endif
1593cbdda60SSimon J. Gerraty
1603cbdda60SSimon J. Gerraty.if !empty(BINOWN)
1613cbdda60SSimon J. GerratyPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
1623cbdda60SSimon J. Gerraty.endif
1633cbdda60SSimon J. Gerraty
1643cbdda60SSimon J. Gerraty.if !target(realinstall)
1653cbdda60SSimon J. Gerratyrealinstall: proginstall
1663cbdda60SSimon J. Gerraty.endif
1673cbdda60SSimon J. Gerraty.if !target(proginstall)
1683cbdda60SSimon J. Gerratyproginstall:
1693cbdda60SSimon J. Gerraty.if defined(PROG)
1703cbdda60SSimon J. Gerraty	[ -d ${DESTDIR}${BINDIR} ] || \
1713cbdda60SSimon J. Gerraty	${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
1723cbdda60SSimon J. Gerraty	${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
1733cbdda60SSimon J. Gerraty	    ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
1743cbdda60SSimon J. Gerraty.endif
1753cbdda60SSimon J. Gerraty.if defined(HIDEGAME)
1763cbdda60SSimon J. Gerraty	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
1773cbdda60SSimon J. Gerraty.endif
1783cbdda60SSimon J. Gerraty.endif
1793cbdda60SSimon J. Gerraty
1803cbdda60SSimon J. Gerraty.include <links.mk>
1813cbdda60SSimon J. Gerraty
1823cbdda60SSimon J. Gerratyinstall: maninstall install_links _SUBDIRUSE
1833cbdda60SSimon J. Gerraty
1843cbdda60SSimon J. Gerratyinstall_links:
1853cbdda60SSimon J. Gerraty.if !empty(SYMLINKS)
1863cbdda60SSimon J. Gerraty	@set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
1873cbdda60SSimon J. Gerraty.endif
1883cbdda60SSimon J. Gerraty.if !empty(LINKS)
1893cbdda60SSimon J. Gerraty	@set ${LINKS}; ${_LINKS_SCRIPT}
1903cbdda60SSimon J. Gerraty.endif
1913cbdda60SSimon J. Gerraty
1923cbdda60SSimon J. Gerratymaninstall: afterinstall
1933cbdda60SSimon J. Gerratyafterinstall: realinstall
1943cbdda60SSimon J. Gerratyrealinstall: beforeinstall
1953cbdda60SSimon J. Gerraty.endif
1963cbdda60SSimon J. Gerraty
1973cbdda60SSimon J. Gerraty.if !target(lint)
1983cbdda60SSimon J. Gerratylint: ${LOBJS}
1993cbdda60SSimon J. Gerraty.if defined(LOBJS) && !empty(LOBJS)
2003cbdda60SSimon J. Gerraty	@${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
2013cbdda60SSimon J. Gerraty.endif
2023cbdda60SSimon J. Gerraty.endif
2033cbdda60SSimon J. Gerraty
2043cbdda60SSimon J. Gerraty.NOPATH:	${PROG}
2053cbdda60SSimon J. Gerraty.if defined(OBJS) && !empty(OBJS)
2063cbdda60SSimon J. Gerraty.NOPATH:	${OBJS}
2073cbdda60SSimon J. Gerraty.endif
2083cbdda60SSimon J. Gerraty
2093cbdda60SSimon J. Gerraty.if ${MK_MAN} != "no"
2103cbdda60SSimon J. Gerraty.include <man.mk>
2113cbdda60SSimon J. Gerraty.endif
2123cbdda60SSimon J. Gerraty
2133cbdda60SSimon J. Gerraty.if ${MK_NLS} != "no"
2143cbdda60SSimon J. Gerraty.include <nls.mk>
2153cbdda60SSimon J. Gerraty.endif
2163cbdda60SSimon J. Gerraty
2173cbdda60SSimon J. Gerraty.include <obj.mk>
2183cbdda60SSimon J. Gerraty.include <dep.mk>
2193cbdda60SSimon J. Gerraty.include <subdir.mk>
2203cbdda60SSimon J. Gerraty.include <final.mk>
2213cbdda60SSimon J. Gerraty
2223cbdda60SSimon J. Gerraty.endif
223