1*6eef5f0cSAntonio Huete Jimenez# $Id: prog.mk,v 1.38 2022/07/22 20:08:56 sjg Exp $ 25f1e34d9SAlexandre Perrin 35f1e34d9SAlexandre Perrin.if !target(__${.PARSEFILE}__) 4*6eef5f0cSAntonio Huete Jimenez__${.PARSEFILE}__: .NOTMAIN 55f1e34d9SAlexandre Perrin 65f1e34d9SAlexandre Perrin.include <init.mk> 75f1e34d9SAlexandre Perrin 85f1e34d9SAlexandre Perrin# FreeBSD at least expects MAN8 etc. 95f1e34d9SAlexandre Perrin.if defined(MAN) && !empty(MAN) 105f1e34d9SAlexandre Perrin_sect:=${MAN:E} 115f1e34d9SAlexandre PerrinMAN${_sect}=${MAN} 125f1e34d9SAlexandre Perrin.endif 135f1e34d9SAlexandre Perrin 145f1e34d9SAlexandre Perrin.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0 155f1e34d9SAlexandre Perrin 165f1e34d9SAlexandre PerrinCFLAGS+= ${COPTS} 175f1e34d9SAlexandre Perrin 185f1e34d9SAlexandre Perrin.if ${TARGET_OSNAME} == "NetBSD" 195f1e34d9SAlexandre Perrin.if ${MACHINE_ARCH} == "sparc64" 205f1e34d9SAlexandre PerrinCFLAGS+= -mcmodel=medlow 215f1e34d9SAlexandre Perrin.endif 225f1e34d9SAlexandre Perrin 235f1e34d9SAlexandre Perrin# ELF platforms depend on crtbegin.o and crtend.o 245f1e34d9SAlexandre Perrin.if ${OBJECT_FMT} == "ELF" 255f1e34d9SAlexandre Perrin.ifndef LIBCRTBEGIN 265f1e34d9SAlexandre PerrinLIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o 275f1e34d9SAlexandre Perrin.MADE: ${LIBCRTBEGIN} 285f1e34d9SAlexandre Perrin.endif 295f1e34d9SAlexandre Perrin.ifndef LIBCRTEND 305f1e34d9SAlexandre PerrinLIBCRTEND= ${DESTDIR}/usr/lib/crtend.o 315f1e34d9SAlexandre Perrin.MADE: ${LIBCRTEND} 325f1e34d9SAlexandre Perrin.endif 335f1e34d9SAlexandre Perrin_SHLINKER= ${SHLINKDIR}/ld.elf_so 345f1e34d9SAlexandre Perrin.else 355f1e34d9SAlexandre PerrinLIBCRTBEGIN?= 365f1e34d9SAlexandre PerrinLIBCRTEND?= 375f1e34d9SAlexandre Perrin_SHLINKER= ${SHLINKDIR}/ld.so 385f1e34d9SAlexandre Perrin.endif 395f1e34d9SAlexandre Perrin 405f1e34d9SAlexandre Perrin.ifndef LIBCRT0 415f1e34d9SAlexandre PerrinLIBCRT0= ${DESTDIR}/usr/lib/crt0.o 425f1e34d9SAlexandre Perrin.MADE: ${LIBCRT0} 435f1e34d9SAlexandre Perrin.endif 445f1e34d9SAlexandre Perrin.endif # NetBSD 455f1e34d9SAlexandre Perrin 465f1e34d9SAlexandre Perrin# here is where you can define what LIB* are 475f1e34d9SAlexandre Perrin.-include <libnames.mk> 485f1e34d9SAlexandre Perrin.if ${MK_DPADD_MK} == "yes" 495f1e34d9SAlexandre Perrin# lots of cool magic, but might not suit everyone. 505f1e34d9SAlexandre Perrin.include <dpadd.mk> 515f1e34d9SAlexandre Perrin.endif 525f1e34d9SAlexandre Perrin 535f1e34d9SAlexandre Perrin.if ${MK_GPROF} == "yes" 545f1e34d9SAlexandre PerrinCFLAGS+= ${CC_PG} ${PROFFLAGS} 555f1e34d9SAlexandre PerrinLDADD+= ${CC_PG} 565f1e34d9SAlexandre Perrin.if ${MK_DPADD_MK} == "no" 575f1e34d9SAlexandre PerrinLDADD_LIBC_P?= -lc_p 585f1e34d9SAlexandre PerrinLDADD_LAST+= ${LDADD_LIBC_P} 595f1e34d9SAlexandre Perrin.endif 605f1e34d9SAlexandre Perrin.endif 615f1e34d9SAlexandre Perrin 625f1e34d9SAlexandre Perrin.if defined(SHAREDSTRINGS) 635f1e34d9SAlexandre PerrinCLEANFILES+=strings 645f1e34d9SAlexandre Perrin.c.o: 655f1e34d9SAlexandre Perrin ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c - 665f1e34d9SAlexandre Perrin @${CC} ${CFLAGS} -c x.c -o ${.TARGET} 675f1e34d9SAlexandre Perrin @rm -f x.c 685f1e34d9SAlexandre Perrin 69f445c897SJohn Marino${CXX_SUFFIXES:%=%.o}: 705f1e34d9SAlexandre Perrin ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c - 715f1e34d9SAlexandre Perrin @mv -f x.c x.cc 725f1e34d9SAlexandre Perrin @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET} 735f1e34d9SAlexandre Perrin @rm -f x.cc 745f1e34d9SAlexandre Perrin.endif 755f1e34d9SAlexandre Perrin 76*6eef5f0cSAntonio Huete Jimenez.if defined(PROG_CXX) 77*6eef5f0cSAntonio Huete JimenezPROG= ${PROG_CXX} 78*6eef5f0cSAntonio Huete Jimenez_CCLINK= ${CXX} 79*6eef5f0cSAntonio Huete Jimenez_SUPCXX?= -lstdc++ -lm 80*6eef5f0cSAntonio Huete Jimenez.endif 81*6eef5f0cSAntonio Huete Jimenez 82*6eef5f0cSAntonio Huete Jimenez_CCLINK?= ${CC} 835f1e34d9SAlexandre Perrin 845f1e34d9SAlexandre Perrin.if defined(PROG) 85ca58f742SDaniel FojtBINDIR ?= ${prefix}/bin 86ca58f742SDaniel Fojt 875f1e34d9SAlexandre PerrinSRCS?= ${PROG}.c 885f1e34d9SAlexandre Perrin.for s in ${SRCS:N*.h:N*.sh:M*/*} 895f1e34d9SAlexandre Perrin${.o .po .lo:L:@o@${s:T:R}$o@}: $s 905f1e34d9SAlexandre Perrin.endfor 915f1e34d9SAlexandre Perrin.if !empty(SRCS:N*.h:N*.sh) 925f1e34d9SAlexandre PerrinOBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g} 935f1e34d9SAlexandre PerrinLOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} 945f1e34d9SAlexandre Perrin.endif 955f1e34d9SAlexandre Perrin 965f1e34d9SAlexandre Perrin.if defined(OBJS) && !empty(OBJS) 975f1e34d9SAlexandre Perrin.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} 985f1e34d9SAlexandre Perrin 995f1e34d9SAlexandre Perrin# this is known to work for NetBSD 1.6 and FreeBSD 4.2 1005f1e34d9SAlexandre Perrin.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" 1015f1e34d9SAlexandre Perrin_PROGLDOPTS= 1025f1e34d9SAlexandre Perrin.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves 1035f1e34d9SAlexandre Perrin_PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER} 1045f1e34d9SAlexandre Perrin.endif 1055f1e34d9SAlexandre Perrin.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR} 1065f1e34d9SAlexandre Perrin_PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \ 1075f1e34d9SAlexandre Perrin -L${DESTDIR}${SHLIBDIR} 1085f1e34d9SAlexandre Perrin.endif 1095f1e34d9SAlexandre Perrin_PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib 1105f1e34d9SAlexandre Perrin.endif # NetBSD 1115f1e34d9SAlexandre Perrin 112ca58f742SDaniel Fojt.if ${MK_PROG_LDORDER_MK} != "no" 113ca58f742SDaniel Fojt${PROG}: ldorder 114ca58f742SDaniel Fojt 115ca58f742SDaniel Fojt.include <ldorder.mk> 116ca58f742SDaniel Fojt.endif 117ca58f742SDaniel Fojt 1185f1e34d9SAlexandre Perrin.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null" 1195f1e34d9SAlexandre Perrin 1205f1e34d9SAlexandre Perrin${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 121ca58f742SDaniel Fojt ${_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} 1225f1e34d9SAlexandre Perrin 1235f1e34d9SAlexandre Perrin.else 1245f1e34d9SAlexandre Perrin 1255f1e34d9SAlexandre Perrin${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 126ca58f742SDaniel Fojt ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD_LDORDER} ${LDADD} 1275f1e34d9SAlexandre Perrin 1285f1e34d9SAlexandre Perrin.endif # defined(DESTDIR) 1295f1e34d9SAlexandre Perrin.endif # defined(OBJS) && !empty(OBJS) 1305f1e34d9SAlexandre Perrin 1315f1e34d9SAlexandre Perrin.if !defined(MAN) 1325f1e34d9SAlexandre PerrinMAN= ${PROG}.1 1335f1e34d9SAlexandre Perrin.endif # !defined(MAN) 1345f1e34d9SAlexandre Perrin.endif # defined(PROG) 1355f1e34d9SAlexandre Perrin 1365f1e34d9SAlexandre Perrin.if !defined(_SKIP_BUILD) 137ca58f742SDaniel Fojtrealbuild: ${PROG} 1385f1e34d9SAlexandre Perrin.endif 139ca58f742SDaniel Fojt 1405f1e34d9SAlexandre Perrinall: _SUBDIRUSE 1415f1e34d9SAlexandre Perrin 1425f1e34d9SAlexandre Perrin.if !target(clean) 1435f1e34d9SAlexandre Perrincleanprog: 1445f1e34d9SAlexandre Perrin rm -f a.out [Ee]rrs mklog core *.core \ 1455f1e34d9SAlexandre Perrin ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES} 1465f1e34d9SAlexandre Perrin 1475f1e34d9SAlexandre Perrinclean: _SUBDIRUSE cleanprog 1485f1e34d9SAlexandre Perrincleandir: _SUBDIRUSE cleanprog 1495f1e34d9SAlexandre Perrin.else 1505f1e34d9SAlexandre Perrincleandir: _SUBDIRUSE clean 1515f1e34d9SAlexandre Perrin.endif 1525f1e34d9SAlexandre Perrin 1535f1e34d9SAlexandre Perrin.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep) 1545f1e34d9SAlexandre Perrinafterdepend: .depend 1555f1e34d9SAlexandre Perrin @(TMP=/tmp/_depend$$$$; \ 1565f1e34d9SAlexandre Perrin sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \ 1575f1e34d9SAlexandre Perrin < .depend > $$TMP; \ 1585f1e34d9SAlexandre Perrin mv $$TMP .depend) 1595f1e34d9SAlexandre Perrin.endif 1605f1e34d9SAlexandre Perrin 1615f1e34d9SAlexandre Perrin.if !target(install) 1625f1e34d9SAlexandre Perrin.if !target(beforeinstall) 1635f1e34d9SAlexandre Perrinbeforeinstall: 1645f1e34d9SAlexandre Perrin.endif 1655f1e34d9SAlexandre Perrin.if !target(afterinstall) 1665f1e34d9SAlexandre Perrinafterinstall: 1675f1e34d9SAlexandre Perrin.endif 1685f1e34d9SAlexandre Perrin 1695f1e34d9SAlexandre Perrin.if !empty(BINOWN) 1705f1e34d9SAlexandre PerrinPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP} 1715f1e34d9SAlexandre Perrin.endif 1725f1e34d9SAlexandre Perrin 1735f1e34d9SAlexandre Perrin.if !target(realinstall) 1745f1e34d9SAlexandre Perrinrealinstall: proginstall 1755f1e34d9SAlexandre Perrin.endif 1765f1e34d9SAlexandre Perrin.if !target(proginstall) 1775f1e34d9SAlexandre Perrinproginstall: 1785f1e34d9SAlexandre Perrin.if defined(PROG) 1795f1e34d9SAlexandre Perrin [ -d ${DESTDIR}${BINDIR} ] || \ 1805f1e34d9SAlexandre Perrin ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR} 1815f1e34d9SAlexandre Perrin ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \ 1825f1e34d9SAlexandre Perrin ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME} 1835f1e34d9SAlexandre Perrin.endif 1845f1e34d9SAlexandre Perrin.if defined(HIDEGAME) 1855f1e34d9SAlexandre Perrin (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}) 1865f1e34d9SAlexandre Perrin.endif 1875f1e34d9SAlexandre Perrin.endif 1885f1e34d9SAlexandre Perrin 1895f1e34d9SAlexandre Perrin.include <links.mk> 1905f1e34d9SAlexandre Perrin 1915f1e34d9SAlexandre Perrininstall: maninstall install_links _SUBDIRUSE 1925f1e34d9SAlexandre Perrin 1935f1e34d9SAlexandre Perrininstall_links: 1945f1e34d9SAlexandre Perrin.if !empty(SYMLINKS) 1955f1e34d9SAlexandre Perrin @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT} 1965f1e34d9SAlexandre Perrin.endif 1975f1e34d9SAlexandre Perrin.if !empty(LINKS) 1985f1e34d9SAlexandre Perrin @set ${LINKS}; ${_LINKS_SCRIPT} 1995f1e34d9SAlexandre Perrin.endif 2005f1e34d9SAlexandre Perrin 2015f1e34d9SAlexandre Perrinmaninstall: afterinstall 2025f1e34d9SAlexandre Perrinafterinstall: realinstall 203ca58f742SDaniel Fojtinstall_links: realinstall 204f445c897SJohn Marinoproginstall: beforeinstall 2055f1e34d9SAlexandre Perrinrealinstall: beforeinstall 2065f1e34d9SAlexandre Perrin.endif 2075f1e34d9SAlexandre Perrin 2085f1e34d9SAlexandre Perrin.if !target(lint) 2095f1e34d9SAlexandre Perrinlint: ${LOBJS} 2105f1e34d9SAlexandre Perrin.if defined(LOBJS) && !empty(LOBJS) 2115f1e34d9SAlexandre Perrin @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD} 2125f1e34d9SAlexandre Perrin.endif 2135f1e34d9SAlexandre Perrin.endif 2145f1e34d9SAlexandre Perrin 2155f1e34d9SAlexandre Perrin.NOPATH: ${PROG} 2165f1e34d9SAlexandre Perrin.if defined(OBJS) && !empty(OBJS) 2175f1e34d9SAlexandre Perrin.NOPATH: ${OBJS} 2185f1e34d9SAlexandre Perrin.endif 2195f1e34d9SAlexandre Perrin 220ca58f742SDaniel Fojt.if defined(FILES) || defined(FILESGROUPS) 221ca58f742SDaniel Fojt.include <files.mk> 222ca58f742SDaniel Fojt.endif 223ca58f742SDaniel Fojt 2245f1e34d9SAlexandre Perrin.if ${MK_MAN} != "no" 2255f1e34d9SAlexandre Perrin.include <man.mk> 2265f1e34d9SAlexandre Perrin.endif 2275f1e34d9SAlexandre Perrin 2285f1e34d9SAlexandre Perrin.if ${MK_NLS} != "no" 2295f1e34d9SAlexandre Perrin.include <nls.mk> 2305f1e34d9SAlexandre Perrin.endif 2315f1e34d9SAlexandre Perrin 2325f1e34d9SAlexandre Perrin.include <obj.mk> 2335f1e34d9SAlexandre Perrin.include <dep.mk> 2345f1e34d9SAlexandre Perrin.include <subdir.mk> 235ca58f742SDaniel Fojt 236ca58f742SDaniel Fojt.if !empty(PROG) && ${MK_STAGING_PROG} == "yes" 237ca58f742SDaniel FojtSTAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR} 238ca58f742SDaniel FojtSTAGE_DIR.prog ?= ${STAGE_BINDIR} 239ca58f742SDaniel Fojt.if ${PROG_NAME:U${PROG}} != ${PROG} 240ca58f742SDaniel FojtSTAGE_AS_SETS += prog 241ca58f742SDaniel FojtSTAGE_AS_${PROG} = ${PROG_NAME} 242ca58f742SDaniel Fojtstage_as.prog: ${PROG} 243ca58f742SDaniel Fojt.else 244ca58f742SDaniel FojtSTAGE_SETS += prog 245ca58f742SDaniel Fojtstage_files.prog: ${PROG} 246ca58f742SDaniel Fojt.endif 247ca58f742SDaniel Fojt.endif 248ca58f742SDaniel Fojt 2495f1e34d9SAlexandre Perrin.include <final.mk> 2505f1e34d9SAlexandre Perrin 2515f1e34d9SAlexandre Perrin.endif 252