1*c59c3bf3SSimon J. Gerraty# $Id: prog.mk,v 1.44 2024/02/19 00:06:19 sjg Exp $ 23cbdda60SSimon J. Gerraty 3*c59c3bf3SSimon J. Gerraty# should be set properly in sys.mk 4*c59c3bf3SSimon J. Gerraty_this ?= ${.PARSEFILE:S,bsd.,,} 5*c59c3bf3SSimon J. Gerraty 6*c59c3bf3SSimon J. Gerraty.if !target(__${_this}__) 7*c59c3bf3SSimon J. Gerraty__${_this}__: .NOTMAIN 83cbdda60SSimon J. Gerraty 93cbdda60SSimon J. Gerraty.include <init.mk> 103cbdda60SSimon J. Gerraty 113cbdda60SSimon J. Gerraty# FreeBSD at least expects MAN8 etc. 123cbdda60SSimon J. Gerraty.if defined(MAN) && !empty(MAN) 133cbdda60SSimon J. Gerraty_sect:=${MAN:E} 143cbdda60SSimon J. GerratyMAN${_sect}=${MAN} 153cbdda60SSimon J. Gerraty.endif 163cbdda60SSimon J. Gerraty 17*c59c3bf3SSimon J. Gerraty.SUFFIXES: .out .o .c ${CXX_SUFFIXES} .y .l ${CCM_SUFFIXES} ${PCM} 183cbdda60SSimon J. Gerraty 193cbdda60SSimon J. GerratyCFLAGS+= ${COPTS} 203cbdda60SSimon J. Gerraty 213cbdda60SSimon J. Gerraty.if ${TARGET_OSNAME} == "NetBSD" 223cbdda60SSimon J. Gerraty.if ${MACHINE_ARCH} == "sparc64" 233cbdda60SSimon J. GerratyCFLAGS+= -mcmodel=medlow 243cbdda60SSimon J. Gerraty.endif 253cbdda60SSimon J. Gerraty 263cbdda60SSimon J. Gerraty# ELF platforms depend on crtbegin.o and crtend.o 273cbdda60SSimon J. Gerraty.if ${OBJECT_FMT} == "ELF" 283cbdda60SSimon J. Gerraty.ifndef LIBCRTBEGIN 293cbdda60SSimon J. GerratyLIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o 303cbdda60SSimon J. Gerraty.MADE: ${LIBCRTBEGIN} 313cbdda60SSimon J. Gerraty.endif 323cbdda60SSimon J. Gerraty.ifndef LIBCRTEND 333cbdda60SSimon J. GerratyLIBCRTEND= ${DESTDIR}/usr/lib/crtend.o 343cbdda60SSimon J. Gerraty.MADE: ${LIBCRTEND} 353cbdda60SSimon J. Gerraty.endif 363cbdda60SSimon J. Gerraty_SHLINKER= ${SHLINKDIR}/ld.elf_so 373cbdda60SSimon J. Gerraty.else 383cbdda60SSimon J. GerratyLIBCRTBEGIN?= 393cbdda60SSimon J. GerratyLIBCRTEND?= 403cbdda60SSimon J. Gerraty_SHLINKER= ${SHLINKDIR}/ld.so 413cbdda60SSimon J. Gerraty.endif 423cbdda60SSimon J. Gerraty 433cbdda60SSimon J. Gerraty.ifndef LIBCRT0 443cbdda60SSimon J. GerratyLIBCRT0= ${DESTDIR}/usr/lib/crt0.o 453cbdda60SSimon J. Gerraty.MADE: ${LIBCRT0} 463cbdda60SSimon J. Gerraty.endif 473cbdda60SSimon J. Gerraty.endif # NetBSD 483cbdda60SSimon J. Gerraty 493cbdda60SSimon J. Gerraty# here is where you can define what LIB* are 503cbdda60SSimon J. Gerraty.-include <libnames.mk> 513cbdda60SSimon J. Gerraty.if ${MK_DPADD_MK} == "yes" 523cbdda60SSimon J. Gerraty# lots of cool magic, but might not suit everyone. 533cbdda60SSimon J. Gerraty.include <dpadd.mk> 543cbdda60SSimon J. Gerraty.endif 553cbdda60SSimon J. Gerraty 5651ee2c1cSSimon J. Gerraty.if ${MK_GPROF} == "yes" 5751ee2c1cSSimon J. GerratyCFLAGS+= ${CC_PG} ${PROFFLAGS} 5851ee2c1cSSimon J. GerratyLDADD+= ${CC_PG} 5951ee2c1cSSimon J. Gerraty.if ${MK_DPADD_MK} == "no" 6051ee2c1cSSimon J. GerratyLDADD_LIBC_P?= -lc_p 6151ee2c1cSSimon J. GerratyLDADD_LAST+= ${LDADD_LIBC_P} 6251ee2c1cSSimon J. Gerraty.endif 6351ee2c1cSSimon J. Gerraty.endif 6451ee2c1cSSimon J. Gerraty 653cbdda60SSimon J. Gerraty.if defined(SHAREDSTRINGS) 663cbdda60SSimon J. GerratyCLEANFILES+=strings 673cbdda60SSimon J. Gerraty.c.o: 68*c59c3bf3SSimon J. Gerraty @${COMPILE.c:N-c} -E ${.IMPSRC} | xstr -c - 69*c59c3bf3SSimon J. Gerraty @${COMPILE.c} x.c -o ${.TARGET} 703cbdda60SSimon J. Gerraty @rm -f x.c 713cbdda60SSimon J. Gerraty 72*c59c3bf3SSimon J. Gerraty# precompiled C++ Modules 73*c59c3bf3SSimon J. Gerraty${CCM_SUFFIXES:%=%${PCM}}: 74*c59c3bf3SSimon J. Gerraty @${COMIPILE.cc:N-c} -E ${.IMPSRC} | xstr -c - 753cbdda60SSimon J. Gerraty @mv -f x.c x.cc 76*c59c3bf3SSimon J. Gerraty @${COMPILE.pcm} x.cc -o ${.TARGET} 77*c59c3bf3SSimon J. Gerraty @rm -f x.cc 78*c59c3bf3SSimon J. Gerraty 79*c59c3bf3SSimon J. Gerraty${CXX_SUFFIXES:N.c*m:%=%.o}: 80*c59c3bf3SSimon J. Gerraty @${COMIPILE.cc:N-c} -E ${.IMPSRC} | xstr -c - 81*c59c3bf3SSimon J. Gerraty @mv -f x.c x.cc 82*c59c3bf3SSimon J. Gerraty @${COMPILE.cc} x.cc -o ${.TARGET} 833cbdda60SSimon J. Gerraty @rm -f x.cc 843cbdda60SSimon J. Gerraty.endif 853cbdda60SSimon J. Gerraty 86954401e6SSimon J. Gerraty.if defined(PROG_CXX) 87954401e6SSimon J. GerratyPROG= ${PROG_CXX} 88954401e6SSimon J. Gerraty_SUPCXX?= -lstdc++ -lm 89954401e6SSimon J. Gerraty.endif 90954401e6SSimon J. Gerraty 913cbdda60SSimon J. Gerraty.if defined(PROG) 92cac6fd11SSimon J. GerratyBINDIR ?= ${prefix}/bin 93cac6fd11SSimon J. Gerraty 94*c59c3bf3SSimon J. Gerraty.if empty(SRCS) 95*c59c3bf3SSimon J. Gerraty# init.mk handling of QUALIFIED_VAR_LIST means 96*c59c3bf3SSimon J. Gerraty# SRCS will be defined - even if empty. 97*c59c3bf3SSimon J. GerratySRCS = ${PROG}.c 98*c59c3bf3SSimon J. Gerraty.endif 99*c59c3bf3SSimon J. Gerraty 1003cbdda60SSimon J. GerratySRCS ?= ${PROG}.c 101*c59c3bf3SSimon J. GerratyOBJS_SRCS = ${SRCS:${OBJS_SRCS_FILTER}} 102*c59c3bf3SSimon J. Gerraty.for s in ${OBJS_SRCS:M*/*} 1033cbdda60SSimon J. Gerraty${.o .po .lo:L:@o@${s:T:R}$o@}: $s 1043cbdda60SSimon J. Gerraty.endfor 105*c59c3bf3SSimon J. Gerraty.if !empty(OBJS_SRCS) 106*c59c3bf3SSimon J. GerratyOBJS+= ${OBJS_SRCS:T:R:S/$/.o/g} 1073cbdda60SSimon J. GerratyLOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} 1083cbdda60SSimon J. Gerraty.endif 1093cbdda60SSimon J. Gerraty 1103cbdda60SSimon J. Gerraty.if defined(OBJS) && !empty(OBJS) 1113cbdda60SSimon J. Gerraty.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} 1123cbdda60SSimon J. Gerraty 1133cbdda60SSimon J. Gerraty# this is known to work for NetBSD 1.6 and FreeBSD 4.2 1148c973ee2SSimon J. Gerraty.if ${TARGET_OSNAME:NFreeBSD:NNetBSD} == "" 1153cbdda60SSimon J. Gerraty_PROGLDOPTS= 1163cbdda60SSimon J. Gerraty.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves 1173cbdda60SSimon J. Gerraty_PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER} 1183cbdda60SSimon J. Gerraty.endif 1193cbdda60SSimon J. Gerraty.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR} 1203cbdda60SSimon J. Gerraty_PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \ 1213cbdda60SSimon J. Gerraty -L${DESTDIR}${SHLIBDIR} 1223cbdda60SSimon J. Gerraty.endif 1233cbdda60SSimon J. Gerraty_PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib 1243cbdda60SSimon J. Gerraty.endif # NetBSD 1253cbdda60SSimon J. Gerraty 12650d2e745SSimon J. Gerraty.if ${MK_PROG_LDORDER_MK} != "no" 12750d2e745SSimon J. Gerraty${PROG}: ldorder 12850d2e745SSimon J. Gerraty 12950d2e745SSimon J. Gerraty.include <ldorder.mk> 13050d2e745SSimon J. Gerraty.endif 131*c59c3bf3SSimon J. Gerraty# avoid -dL errors 132*c59c3bf3SSimon J. GerratyLDADD_LDORDER ?= 133*c59c3bf3SSimon J. GerratyLDSTATIC ?= 13450d2e745SSimon J. Gerraty 1353cbdda60SSimon J. Gerraty.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null" 1363cbdda60SSimon J. Gerraty 1373cbdda60SSimon J. Gerraty${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 13850d2e745SSimon 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} 1393cbdda60SSimon J. Gerraty 1403cbdda60SSimon J. Gerraty.else 1413cbdda60SSimon J. Gerraty 1423cbdda60SSimon J. Gerraty${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 14350d2e745SSimon J. Gerraty ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD_LDORDER} ${LDADD} 1443cbdda60SSimon J. Gerraty 1453cbdda60SSimon J. Gerraty.endif # defined(DESTDIR) 1463cbdda60SSimon J. Gerraty.endif # defined(OBJS) && !empty(OBJS) 1473cbdda60SSimon J. Gerraty 1483cbdda60SSimon J. Gerraty.if !defined(MAN) 1493cbdda60SSimon J. GerratyMAN= ${PROG}.1 1503cbdda60SSimon J. Gerraty.endif # !defined(MAN) 1513cbdda60SSimon J. Gerraty.endif # defined(PROG) 1523cbdda60SSimon J. Gerraty 1533cbdda60SSimon J. Gerraty.if !defined(_SKIP_BUILD) 154cac6fd11SSimon J. Gerratyrealbuild: ${PROG} 1553cbdda60SSimon J. Gerraty.endif 156cac6fd11SSimon J. Gerraty 1573cbdda60SSimon J. Gerratyall: _SUBDIRUSE 1583cbdda60SSimon J. Gerraty 1593cbdda60SSimon J. Gerraty.if !target(clean) 1603cbdda60SSimon J. Gerratycleanprog: 1613cbdda60SSimon J. Gerraty rm -f a.out [Ee]rrs mklog core *.core \ 1623cbdda60SSimon J. Gerraty ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES} 1633cbdda60SSimon J. Gerraty 1643cbdda60SSimon J. Gerratyclean: _SUBDIRUSE cleanprog 1653cbdda60SSimon J. Gerratycleandir: _SUBDIRUSE cleanprog 1663cbdda60SSimon J. Gerraty.else 1673cbdda60SSimon J. Gerratycleandir: _SUBDIRUSE clean 1683cbdda60SSimon J. Gerraty.endif 1693cbdda60SSimon J. Gerraty 1703cbdda60SSimon J. Gerraty.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep) 1713cbdda60SSimon J. Gerratyafterdepend: .depend 1723cbdda60SSimon J. Gerraty @(TMP=/tmp/_depend$$$$; \ 1733cbdda60SSimon J. Gerraty sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \ 1743cbdda60SSimon J. Gerraty < .depend > $$TMP; \ 1753cbdda60SSimon J. Gerraty mv $$TMP .depend) 1763cbdda60SSimon J. Gerraty.endif 1773cbdda60SSimon J. Gerraty 1783cbdda60SSimon J. Gerraty.if !target(install) 1793cbdda60SSimon J. Gerraty.if !target(beforeinstall) 1803cbdda60SSimon J. Gerratybeforeinstall: 1813cbdda60SSimon J. Gerraty.endif 1823cbdda60SSimon J. Gerraty.if !target(afterinstall) 1833cbdda60SSimon J. Gerratyafterinstall: 1843cbdda60SSimon J. Gerraty.endif 1853cbdda60SSimon J. Gerraty 1863cbdda60SSimon J. Gerraty.if !empty(BINOWN) 1873cbdda60SSimon J. GerratyPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP} 1883cbdda60SSimon J. Gerraty.endif 1893cbdda60SSimon J. Gerraty 1903cbdda60SSimon J. Gerraty.if !target(realinstall) 1913cbdda60SSimon J. Gerratyrealinstall: proginstall 1923cbdda60SSimon J. Gerraty.endif 1933cbdda60SSimon J. Gerraty.if !target(proginstall) 1943cbdda60SSimon J. Gerratyproginstall: 1953cbdda60SSimon J. Gerraty.if defined(PROG) 1963cbdda60SSimon J. Gerraty [ -d ${DESTDIR}${BINDIR} ] || \ 1973cbdda60SSimon J. Gerraty ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR} 1983cbdda60SSimon J. Gerraty ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \ 1993cbdda60SSimon J. Gerraty ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME} 2003cbdda60SSimon J. Gerraty.endif 2013cbdda60SSimon J. Gerraty.if defined(HIDEGAME) 2023cbdda60SSimon J. Gerraty (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}) 2033cbdda60SSimon J. Gerraty.endif 2043cbdda60SSimon J. Gerraty.endif 2053cbdda60SSimon J. Gerraty 2063cbdda60SSimon J. Gerraty.include <links.mk> 2073cbdda60SSimon J. Gerraty 2083cbdda60SSimon J. Gerratyinstall: maninstall install_links _SUBDIRUSE 2093cbdda60SSimon J. Gerraty 2103cbdda60SSimon J. Gerratyinstall_links: 2113cbdda60SSimon J. Gerraty.if !empty(SYMLINKS) 2123cbdda60SSimon J. Gerraty @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT} 2133cbdda60SSimon J. Gerraty.endif 2143cbdda60SSimon J. Gerraty.if !empty(LINKS) 2153cbdda60SSimon J. Gerraty @set ${LINKS}; ${_LINKS_SCRIPT} 2163cbdda60SSimon J. Gerraty.endif 2173cbdda60SSimon J. Gerraty 2183cbdda60SSimon J. Gerratymaninstall: afterinstall 2193cbdda60SSimon J. Gerratyafterinstall: realinstall 2201ce939a7SSimon J. Gerratyinstall_links: realinstall 22195e3ed2cSSimon J. Gerratyproginstall: beforeinstall 2223cbdda60SSimon J. Gerratyrealinstall: beforeinstall 2233cbdda60SSimon J. Gerraty.endif 2243cbdda60SSimon J. Gerraty 2253cbdda60SSimon J. Gerraty.if !target(lint) 2263cbdda60SSimon J. Gerratylint: ${LOBJS} 2273cbdda60SSimon J. Gerraty.if defined(LOBJS) && !empty(LOBJS) 2283cbdda60SSimon J. Gerraty @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD} 2293cbdda60SSimon J. Gerraty.endif 2303cbdda60SSimon J. Gerraty.endif 2313cbdda60SSimon J. Gerraty 2323cbdda60SSimon J. Gerraty.NOPATH: ${PROG} 2333cbdda60SSimon J. Gerraty.if defined(OBJS) && !empty(OBJS) 2343cbdda60SSimon J. Gerraty.NOPATH: ${OBJS} 2353cbdda60SSimon J. Gerraty.endif 2363cbdda60SSimon J. Gerraty 237cac6fd11SSimon J. Gerraty.if defined(FILES) || defined(FILESGROUPS) 238cac6fd11SSimon J. Gerraty.include <files.mk> 239cac6fd11SSimon J. Gerraty.endif 240cac6fd11SSimon J. Gerraty 2413cbdda60SSimon J. Gerraty.if ${MK_MAN} != "no" 2423cbdda60SSimon J. Gerraty.include <man.mk> 2433cbdda60SSimon J. Gerraty.endif 2443cbdda60SSimon J. Gerraty 2453cbdda60SSimon J. Gerraty.if ${MK_NLS} != "no" 2463cbdda60SSimon J. Gerraty.include <nls.mk> 2473cbdda60SSimon J. Gerraty.endif 2483cbdda60SSimon J. Gerraty 2493cbdda60SSimon J. Gerraty.include <obj.mk> 2503cbdda60SSimon J. Gerraty.include <dep.mk> 2513cbdda60SSimon J. Gerraty.include <subdir.mk> 252cac6fd11SSimon J. Gerraty 253cac6fd11SSimon J. Gerraty.if !empty(PROG) && ${MK_STAGING_PROG} == "yes" 254cac6fd11SSimon J. GerratySTAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR} 255cac6fd11SSimon J. GerratySTAGE_DIR.prog ?= ${STAGE_BINDIR} 256cac6fd11SSimon J. Gerraty.if ${PROG_NAME:U${PROG}} != ${PROG} 257cac6fd11SSimon J. GerratySTAGE_AS_SETS += prog 258cac6fd11SSimon J. GerratySTAGE_AS_${PROG} = ${PROG_NAME} 259cac6fd11SSimon J. Gerratystage_as.prog: ${PROG} 260cac6fd11SSimon J. Gerraty.else 261cac6fd11SSimon J. GerratySTAGE_SETS += prog 262cac6fd11SSimon J. Gerratystage_files.prog: ${PROG} 263cac6fd11SSimon J. Gerraty.endif 264cac6fd11SSimon J. Gerraty.endif 265cac6fd11SSimon J. Gerraty 2663cbdda60SSimon J. Gerraty.include <final.mk> 2673cbdda60SSimon J. Gerraty 2683cbdda60SSimon J. Gerraty.endif 269