prog.mk revision 319884
1319884Ssjg# $Id: prog.mk,v 1.32 2017/05/06 17:30:09 sjg Exp $ 2246149Ssjg 3246149Ssjg.if !target(__${.PARSEFILE}__) 4246149Ssjg__${.PARSEFILE}__: 5246149Ssjg 6246149Ssjg.include <init.mk> 7246149Ssjg 8246149Ssjg# FreeBSD at least expects MAN8 etc. 9246149Ssjg.if defined(MAN) && !empty(MAN) 10246149Ssjg_sect:=${MAN:E} 11246149SsjgMAN${_sect}=${MAN} 12246149Ssjg.endif 13246149Ssjg 14246149Ssjg.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0 15246149Ssjg 16246149SsjgCFLAGS+= ${COPTS} 17246149Ssjg 18246149Ssjg.if ${TARGET_OSNAME} == "NetBSD" 19246149Ssjg.if ${MACHINE_ARCH} == "sparc64" 20246149SsjgCFLAGS+= -mcmodel=medlow 21246149Ssjg.endif 22246149Ssjg 23246149Ssjg# ELF platforms depend on crtbegin.o and crtend.o 24246149Ssjg.if ${OBJECT_FMT} == "ELF" 25246149Ssjg.ifndef LIBCRTBEGIN 26246149SsjgLIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o 27246149Ssjg.MADE: ${LIBCRTBEGIN} 28246149Ssjg.endif 29246149Ssjg.ifndef LIBCRTEND 30246149SsjgLIBCRTEND= ${DESTDIR}/usr/lib/crtend.o 31246149Ssjg.MADE: ${LIBCRTEND} 32246149Ssjg.endif 33246149Ssjg_SHLINKER= ${SHLINKDIR}/ld.elf_so 34246149Ssjg.else 35246149SsjgLIBCRTBEGIN?= 36246149SsjgLIBCRTEND?= 37246149Ssjg_SHLINKER= ${SHLINKDIR}/ld.so 38246149Ssjg.endif 39246149Ssjg 40246149Ssjg.ifndef LIBCRT0 41246149SsjgLIBCRT0= ${DESTDIR}/usr/lib/crt0.o 42246149Ssjg.MADE: ${LIBCRT0} 43246149Ssjg.endif 44246149Ssjg.endif # NetBSD 45246149Ssjg 46246149Ssjg# here is where you can define what LIB* are 47246149Ssjg.-include <libnames.mk> 48246149Ssjg.if ${MK_DPADD_MK} == "yes" 49246149Ssjg# lots of cool magic, but might not suit everyone. 50246149Ssjg.include <dpadd.mk> 51246149Ssjg.endif 52246149Ssjg 53253883Ssjg.if ${MK_GPROF} == "yes" 54253883SsjgCFLAGS+= ${CC_PG} ${PROFFLAGS} 55253883SsjgLDADD+= ${CC_PG} 56253883Ssjg.if ${MK_DPADD_MK} == "no" 57253883SsjgLDADD_LIBC_P?= -lc_p 58253883SsjgLDADD_LAST+= ${LDADD_LIBC_P} 59253883Ssjg.endif 60253883Ssjg.endif 61253883Ssjg 62246149Ssjg.if defined(SHAREDSTRINGS) 63246149SsjgCLEANFILES+=strings 64246149Ssjg.c.o: 65246149Ssjg ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c - 66246149Ssjg @${CC} ${CFLAGS} -c x.c -o ${.TARGET} 67246149Ssjg @rm -f x.c 68246149Ssjg 69300313Ssjg${CXX_SUFFIXES:%=%.o}: 70246149Ssjg ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c - 71246149Ssjg @mv -f x.c x.cc 72246149Ssjg @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET} 73246149Ssjg @rm -f x.cc 74246149Ssjg.endif 75246149Ssjg 76246149Ssjg 77246149Ssjg.if defined(PROG) 78319884SsjgBINDIR ?= ${prefix}/bin 79319884Ssjg 80246149SsjgSRCS?= ${PROG}.c 81246149Ssjg.for s in ${SRCS:N*.h:N*.sh:M*/*} 82246149Ssjg${.o .po .lo:L:@o@${s:T:R}$o@}: $s 83246149Ssjg.endfor 84246149Ssjg.if !empty(SRCS:N*.h:N*.sh) 85246149SsjgOBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g} 86246149SsjgLOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} 87246149Ssjg.endif 88246149Ssjg 89246149Ssjg.if defined(OBJS) && !empty(OBJS) 90246149Ssjg.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} 91246149Ssjg 92246149Ssjg# this is known to work for NetBSD 1.6 and FreeBSD 4.2 93246149Ssjg.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" 94246149Ssjg_PROGLDOPTS= 95246149Ssjg.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves 96246149Ssjg_PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER} 97246149Ssjg.endif 98246149Ssjg.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR} 99246149Ssjg_PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \ 100246149Ssjg -L${DESTDIR}${SHLIBDIR} 101246149Ssjg.endif 102246149Ssjg_PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib 103246149Ssjg 104246149Ssjg.if defined(PROG_CXX) 105246149Ssjg_CCLINK= ${CXX} 106246149Ssjg_SUPCXX= -lstdc++ -lm 107246149Ssjg.endif 108246149Ssjg.endif # NetBSD 109246149Ssjg 110246149Ssjg_CCLINK?= ${CC} 111246149Ssjg 112246149Ssjg.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null" 113246149Ssjg 114246149Ssjg${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 115246149Ssjg ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND} 116246149Ssjg 117246149Ssjg.else 118246149Ssjg 119246149Ssjg${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 120246149Ssjg ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD} 121246149Ssjg 122246149Ssjg.endif # defined(DESTDIR) 123246149Ssjg.endif # defined(OBJS) && !empty(OBJS) 124246149Ssjg 125246149Ssjg.if !defined(MAN) 126246149SsjgMAN= ${PROG}.1 127246149Ssjg.endif # !defined(MAN) 128246149Ssjg.endif # defined(PROG) 129246149Ssjg 130246149Ssjg.if !defined(_SKIP_BUILD) 131319884Ssjgrealbuild: ${PROG} 132246149Ssjg.endif 133319884Ssjg 134246149Ssjgall: _SUBDIRUSE 135246149Ssjg 136246149Ssjg.if !target(clean) 137246149Ssjgcleanprog: 138246149Ssjg rm -f a.out [Ee]rrs mklog core *.core \ 139246149Ssjg ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES} 140246149Ssjg 141246149Ssjgclean: _SUBDIRUSE cleanprog 142246149Ssjgcleandir: _SUBDIRUSE cleanprog 143246149Ssjg.else 144246149Ssjgcleandir: _SUBDIRUSE clean 145246149Ssjg.endif 146246149Ssjg 147246149Ssjg.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep) 148246149Ssjgafterdepend: .depend 149246149Ssjg @(TMP=/tmp/_depend$$$$; \ 150246149Ssjg sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \ 151246149Ssjg < .depend > $$TMP; \ 152246149Ssjg mv $$TMP .depend) 153246149Ssjg.endif 154246149Ssjg 155246149Ssjg.if !target(install) 156246149Ssjg.if !target(beforeinstall) 157246149Ssjgbeforeinstall: 158246149Ssjg.endif 159246149Ssjg.if !target(afterinstall) 160246149Ssjgafterinstall: 161246149Ssjg.endif 162246149Ssjg 163246149Ssjg.if !empty(BINOWN) 164246149SsjgPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP} 165246149Ssjg.endif 166246149Ssjg 167246149Ssjg.if !target(realinstall) 168246149Ssjgrealinstall: proginstall 169246149Ssjg.endif 170246149Ssjg.if !target(proginstall) 171246149Ssjgproginstall: 172246149Ssjg.if defined(PROG) 173246149Ssjg [ -d ${DESTDIR}${BINDIR} ] || \ 174246149Ssjg ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR} 175246149Ssjg ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \ 176246149Ssjg ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME} 177246149Ssjg.endif 178246149Ssjg.if defined(HIDEGAME) 179246149Ssjg (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}) 180246149Ssjg.endif 181246149Ssjg.endif 182246149Ssjg 183246149Ssjg.include <links.mk> 184246149Ssjg 185246149Ssjginstall: maninstall install_links _SUBDIRUSE 186246149Ssjg 187246149Ssjginstall_links: 188246149Ssjg.if !empty(SYMLINKS) 189246149Ssjg @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT} 190246149Ssjg.endif 191246149Ssjg.if !empty(LINKS) 192246149Ssjg @set ${LINKS}; ${_LINKS_SCRIPT} 193246149Ssjg.endif 194246149Ssjg 195246149Ssjgmaninstall: afterinstall 196246149Ssjgafterinstall: realinstall 197319884Ssjginstall_links: realinstall 198319884Ssjgproginstall: beforeinstall 199246149Ssjgrealinstall: beforeinstall 200246149Ssjg.endif 201246149Ssjg 202246149Ssjg.if !target(lint) 203246149Ssjglint: ${LOBJS} 204246149Ssjg.if defined(LOBJS) && !empty(LOBJS) 205246149Ssjg @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD} 206246149Ssjg.endif 207246149Ssjg.endif 208246149Ssjg 209246149Ssjg.NOPATH: ${PROG} 210246149Ssjg.if defined(OBJS) && !empty(OBJS) 211246149Ssjg.NOPATH: ${OBJS} 212246149Ssjg.endif 213246149Ssjg 214319884Ssjg.if defined(FILES) || defined(FILESGROUPS) 215319884Ssjg.include <files.mk> 216319884Ssjg.endif 217319884Ssjg 218246149Ssjg.if ${MK_MAN} != "no" 219246149Ssjg.include <man.mk> 220246149Ssjg.endif 221246149Ssjg 222246149Ssjg.if ${MK_NLS} != "no" 223246149Ssjg.include <nls.mk> 224246149Ssjg.endif 225246149Ssjg 226246149Ssjg.include <obj.mk> 227246149Ssjg.include <dep.mk> 228246149Ssjg.include <subdir.mk> 229319884Ssjg 230319884Ssjg.if !empty(PROG) && ${MK_STAGING_PROG} == "yes" 231319884SsjgSTAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR} 232319884SsjgSTAGE_DIR.prog ?= ${STAGE_BINDIR} 233319884Ssjg.if ${PROG_NAME:U${PROG}} != ${PROG} 234319884SsjgSTAGE_AS_SETS += prog 235319884SsjgSTAGE_AS_${PROG} = ${PROG_NAME} 236319884Ssjgstage_as.prog: ${PROG} 237319884Ssjg.else 238319884SsjgSTAGE_SETS += prog 239319884Ssjgstage_files.prog: ${PROG} 240319884Ssjg.endif 241319884Ssjg.endif 242319884Ssjg 243246149Ssjg.include <final.mk> 244246149Ssjg 245246149Ssjg.endif 246