1253883Ssjg# $Id: prog.mk,v 1.25 2013/07/18 05:46:24 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 69246149Ssjg.cc.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 75246149Ssjg.C.o: 76246149Ssjg ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c - 77246149Ssjg @mv -f x.c x.C 78246149Ssjg @${CXX} ${CXXFLAGS} -c x.C -o ${.TARGET} 79246149Ssjg @rm -f x.C 80246149Ssjg.endif 81246149Ssjg 82246149Ssjg 83246149Ssjg.if defined(PROG) 84246149SsjgSRCS?= ${PROG}.c 85246149Ssjg.for s in ${SRCS:N*.h:N*.sh:M*/*} 86246149Ssjg${.o .po .lo:L:@o@${s:T:R}$o@}: $s 87246149Ssjg.endfor 88246149Ssjg.if !empty(SRCS:N*.h:N*.sh) 89246149SsjgOBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g} 90246149SsjgLOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} 91246149Ssjg.endif 92246149Ssjg 93246149Ssjg.if defined(OBJS) && !empty(OBJS) 94246149Ssjg.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} 95246149Ssjg 96246149Ssjg# this is known to work for NetBSD 1.6 and FreeBSD 4.2 97246149Ssjg.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" 98246149Ssjg_PROGLDOPTS= 99246149Ssjg.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves 100246149Ssjg_PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER} 101246149Ssjg.endif 102246149Ssjg.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR} 103246149Ssjg_PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \ 104246149Ssjg -L${DESTDIR}${SHLIBDIR} 105246149Ssjg.endif 106246149Ssjg_PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib 107246149Ssjg 108246149Ssjg.if defined(PROG_CXX) 109246149Ssjg_CCLINK= ${CXX} 110246149Ssjg_SUPCXX= -lstdc++ -lm 111246149Ssjg.endif 112246149Ssjg.endif # NetBSD 113246149Ssjg 114246149Ssjg_CCLINK?= ${CC} 115246149Ssjg 116246149Ssjg.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null" 117246149Ssjg 118246149Ssjg${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 119246149Ssjg ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND} 120246149Ssjg 121246149Ssjg.else 122246149Ssjg 123246149Ssjg${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 124246149Ssjg ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD} 125246149Ssjg 126246149Ssjg.endif # defined(DESTDIR) 127246149Ssjg.endif # defined(OBJS) && !empty(OBJS) 128246149Ssjg 129246149Ssjg.if !defined(MAN) 130246149SsjgMAN= ${PROG}.1 131246149Ssjg.endif # !defined(MAN) 132246149Ssjg.endif # defined(PROG) 133246149Ssjg 134246149Ssjg.if !defined(_SKIP_BUILD) 135246149Ssjgall: ${PROG} 136246149Ssjg.endif 137246149Ssjgall: _SUBDIRUSE 138246149Ssjg 139246149Ssjg.if !target(clean) 140246149Ssjgcleanprog: 141246149Ssjg rm -f a.out [Ee]rrs mklog core *.core \ 142246149Ssjg ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES} 143246149Ssjg 144246149Ssjgclean: _SUBDIRUSE cleanprog 145246149Ssjgcleandir: _SUBDIRUSE cleanprog 146246149Ssjg.else 147246149Ssjgcleandir: _SUBDIRUSE clean 148246149Ssjg.endif 149246149Ssjg 150246149Ssjg.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep) 151246149Ssjgafterdepend: .depend 152246149Ssjg @(TMP=/tmp/_depend$$$$; \ 153246149Ssjg sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \ 154246149Ssjg < .depend > $$TMP; \ 155246149Ssjg mv $$TMP .depend) 156246149Ssjg.endif 157246149Ssjg 158246149Ssjg.if !target(install) 159246149Ssjg.if !target(beforeinstall) 160246149Ssjgbeforeinstall: 161246149Ssjg.endif 162246149Ssjg.if !target(afterinstall) 163246149Ssjgafterinstall: 164246149Ssjg.endif 165246149Ssjg 166246149Ssjg.if !empty(BINOWN) 167246149SsjgPROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP} 168246149Ssjg.endif 169246149Ssjg 170246149Ssjg.if !target(realinstall) 171246149Ssjgrealinstall: proginstall 172246149Ssjg.endif 173246149Ssjg.if !target(proginstall) 174246149Ssjgproginstall: 175246149Ssjg.if defined(PROG) 176246149Ssjg [ -d ${DESTDIR}${BINDIR} ] || \ 177246149Ssjg ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR} 178246149Ssjg ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \ 179246149Ssjg ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME} 180246149Ssjg.endif 181246149Ssjg.if defined(HIDEGAME) 182246149Ssjg (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}) 183246149Ssjg.endif 184246149Ssjg.endif 185246149Ssjg 186246149Ssjg.include <links.mk> 187246149Ssjg 188246149Ssjginstall: maninstall install_links _SUBDIRUSE 189246149Ssjg 190246149Ssjginstall_links: 191246149Ssjg.if !empty(SYMLINKS) 192246149Ssjg @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT} 193246149Ssjg.endif 194246149Ssjg.if !empty(LINKS) 195246149Ssjg @set ${LINKS}; ${_LINKS_SCRIPT} 196246149Ssjg.endif 197246149Ssjg 198246149Ssjgmaninstall: afterinstall 199246149Ssjgafterinstall: realinstall 200246149Ssjgrealinstall: beforeinstall 201246149Ssjg.endif 202246149Ssjg 203246149Ssjg.if !target(lint) 204246149Ssjglint: ${LOBJS} 205246149Ssjg.if defined(LOBJS) && !empty(LOBJS) 206246149Ssjg @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD} 207246149Ssjg.endif 208246149Ssjg.endif 209246149Ssjg 210246149Ssjg.NOPATH: ${PROG} 211246149Ssjg.if defined(OBJS) && !empty(OBJS) 212246149Ssjg.NOPATH: ${OBJS} 213246149Ssjg.endif 214246149Ssjg 215246149Ssjg.if ${MK_MAN} != "no" 216246149Ssjg.include <man.mk> 217246149Ssjg.endif 218246149Ssjg 219246149Ssjg.if ${MK_NLS} != "no" 220246149Ssjg.include <nls.mk> 221246149Ssjg.endif 222246149Ssjg 223246149Ssjg.include <obj.mk> 224246149Ssjg.include <dep.mk> 225246149Ssjg.include <subdir.mk> 226246149Ssjg.include <final.mk> 227246149Ssjg 228246149Ssjg.endif 229