1# $Id: prog.mk,v 1.24 2012/12/13 23:04:14 sjg Exp $ 2 3.if !target(__${.PARSEFILE}__) 4__${.PARSEFILE}__: 5 6.include <init.mk> 7 8# FreeBSD at least expects MAN8 etc. 9.if defined(MAN) && !empty(MAN) 10_sect:=${MAN:E} 11MAN${_sect}=${MAN} 12.endif 13 14.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0 15 16CFLAGS+= ${COPTS} 17 18.if ${TARGET_OSNAME} == "NetBSD" 19.if ${MACHINE_ARCH} == "sparc64" 20CFLAGS+= -mcmodel=medlow 21.endif 22 23# ELF platforms depend on crtbegin.o and crtend.o 24.if ${OBJECT_FMT} == "ELF" 25.ifndef LIBCRTBEGIN 26LIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o 27.MADE: ${LIBCRTBEGIN} 28.endif 29.ifndef LIBCRTEND 30LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o 31.MADE: ${LIBCRTEND} 32.endif 33_SHLINKER= ${SHLINKDIR}/ld.elf_so 34.else 35LIBCRTBEGIN?= 36LIBCRTEND?= 37_SHLINKER= ${SHLINKDIR}/ld.so 38.endif 39 40.ifndef LIBCRT0 41LIBCRT0= ${DESTDIR}/usr/lib/crt0.o 42.MADE: ${LIBCRT0} 43.endif 44.endif # NetBSD 45 46# here is where you can define what LIB* are 47.-include <libnames.mk> 48.if ${MK_DPADD_MK} == "yes" 49# lots of cool magic, but might not suit everyone. 50.include <dpadd.mk> 51.endif 52 53.if defined(SHAREDSTRINGS) 54CLEANFILES+=strings 55.c.o: 56 ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c - 57 @${CC} ${CFLAGS} -c x.c -o ${.TARGET} 58 @rm -f x.c 59 60.cc.o: 61 ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c - 62 @mv -f x.c x.cc 63 @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET} 64 @rm -f x.cc 65 66.C.o: 67 ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c - 68 @mv -f x.c x.C 69 @${CXX} ${CXXFLAGS} -c x.C -o ${.TARGET} 70 @rm -f x.C 71.endif 72 73 74.if defined(PROG) 75SRCS?= ${PROG}.c 76.for s in ${SRCS:N*.h:N*.sh:M*/*} 77${.o .po .lo:L:@o@${s:T:R}$o@}: $s 78.endfor 79.if !empty(SRCS:N*.h:N*.sh) 80OBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g} 81LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln} 82.endif 83 84.if defined(OBJS) && !empty(OBJS) 85.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} 86 87# this is known to work for NetBSD 1.6 and FreeBSD 4.2 88.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" 89_PROGLDOPTS= 90.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves 91_PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER} 92.endif 93.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR} 94_PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \ 95 -L${DESTDIR}${SHLIBDIR} 96.endif 97_PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib 98 99.if defined(PROG_CXX) 100_CCLINK= ${CXX} 101_SUPCXX= -lstdc++ -lm 102.endif 103.endif # NetBSD 104 105_CCLINK?= ${CC} 106 107.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null" 108 109${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 110 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND} 111 112.else 113 114${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD} 115 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD} 116 117.endif # defined(DESTDIR) 118.endif # defined(OBJS) && !empty(OBJS) 119 120.if !defined(MAN) 121MAN= ${PROG}.1 122.endif # !defined(MAN) 123.endif # defined(PROG) 124 125.if !defined(_SKIP_BUILD) 126all: ${PROG} 127.endif 128all: _SUBDIRUSE 129 130.if !target(clean) 131cleanprog: 132 rm -f a.out [Ee]rrs mklog core *.core \ 133 ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES} 134 135clean: _SUBDIRUSE cleanprog 136cleandir: _SUBDIRUSE cleanprog 137.else 138cleandir: _SUBDIRUSE clean 139.endif 140 141.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep) 142afterdepend: .depend 143 @(TMP=/tmp/_depend$$$$; \ 144 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \ 145 < .depend > $$TMP; \ 146 mv $$TMP .depend) 147.endif 148 149.if !target(install) 150.if !target(beforeinstall) 151beforeinstall: 152.endif 153.if !target(afterinstall) 154afterinstall: 155.endif 156 157.if !empty(BINOWN) 158PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP} 159.endif 160 161.if !target(realinstall) 162realinstall: proginstall 163.endif 164.if !target(proginstall) 165proginstall: 166.if defined(PROG) 167 [ -d ${DESTDIR}${BINDIR} ] || \ 168 ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR} 169 ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \ 170 ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME} 171.endif 172.if defined(HIDEGAME) 173 (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}) 174.endif 175.endif 176 177.include <links.mk> 178 179install: maninstall install_links _SUBDIRUSE 180 181install_links: 182.if !empty(SYMLINKS) 183 @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT} 184.endif 185.if !empty(LINKS) 186 @set ${LINKS}; ${_LINKS_SCRIPT} 187.endif 188 189maninstall: afterinstall 190afterinstall: realinstall 191realinstall: beforeinstall 192.endif 193 194.if !target(lint) 195lint: ${LOBJS} 196.if defined(LOBJS) && !empty(LOBJS) 197 @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD} 198.endif 199.endif 200 201.NOPATH: ${PROG} 202.if defined(OBJS) && !empty(OBJS) 203.NOPATH: ${OBJS} 204.endif 205 206.if ${MK_MAN} != "no" 207.include <man.mk> 208.endif 209 210.if ${MK_NLS} != "no" 211.include <nls.mk> 212.endif 213 214.include <obj.mk> 215.include <dep.mk> 216.include <subdir.mk> 217.include <final.mk> 218 219.endif 220