1 # $Id: prog.mk,v 1.25 2013/07/18 05:46:24 sjg Exp $
3 .if !target(__${.PARSEFILE}__)
8 # FreeBSD at least expects MAN8 etc.
9 .if defined(MAN) && !empty(MAN)
14 .SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
18 .if ${TARGET_OSNAME} == "NetBSD"
19 .if ${MACHINE_ARCH} == "sparc64"
20 CFLAGS+= -mcmodel=medlow
23 # ELF platforms depend on crtbegin.o and crtend.o
24 .if ${OBJECT_FMT} == "ELF"
26 LIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o
30 LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o
33 _SHLINKER= ${SHLINKDIR}/ld.elf_so
37 _SHLINKER= ${SHLINKDIR}/ld.so
41 LIBCRT0= ${DESTDIR}/usr/lib/crt0.o
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.
53 .if ${MK_GPROF} == "yes"
54 CFLAGS+= ${CC_PG} ${PROFFLAGS}
56 .if ${MK_DPADD_MK} == "no"
58 LDADD_LAST+= ${LDADD_LIBC_P}
62 .if defined(SHAREDSTRINGS)
65 ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
66 @${CC} ${CFLAGS} -c x.c -o ${.TARGET}
70 ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
72 @${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
76 ${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
78 @${CXX} ${CXXFLAGS} -c x.C -o ${.TARGET}
85 .for s in ${SRCS:N*.h:N*.sh:M*/*}
86 ${.o .po .lo:L:@o@${s:T:R}$o@}: $s
88 .if !empty(SRCS:N*.h:N*.sh)
89 OBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
90 LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
93 .if defined(OBJS) && !empty(OBJS)
94 .NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
96 # this is known to work for NetBSD 1.6 and FreeBSD 4.2
97 .if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
99 .if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves
100 _PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER}
102 .if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
103 _PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
104 -L${DESTDIR}${SHLIBDIR}
106 _PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib
108 .if defined(PROG_CXX)
110 _SUPCXX= -lstdc++ -lm
116 .if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
118 ${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
119 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
123 ${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
124 ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
126 .endif # defined(DESTDIR)
127 .endif # defined(OBJS) && !empty(OBJS)
131 .endif # !defined(MAN)
132 .endif # defined(PROG)
134 .if !defined(_SKIP_BUILD)
141 rm -f a.out [Ee]rrs mklog core *.core \
142 ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
144 clean: _SUBDIRUSE cleanprog
145 cleandir: _SUBDIRUSE cleanprog
147 cleandir: _SUBDIRUSE clean
150 .if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
152 @(TMP=/tmp/_depend$$$$; \
153 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
159 .if !target(beforeinstall)
162 .if !target(afterinstall)
167 PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
170 .if !target(realinstall)
171 realinstall: proginstall
173 .if !target(proginstall)
176 [ -d ${DESTDIR}${BINDIR} ] || \
177 ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
178 ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
179 ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
181 .if defined(HIDEGAME)
182 (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
188 install: maninstall install_links _SUBDIRUSE
192 @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
195 @set ${LINKS}; ${_LINKS_SCRIPT}
198 maninstall: afterinstall
199 afterinstall: realinstall
200 realinstall: beforeinstall
205 .if defined(LOBJS) && !empty(LOBJS)
206 @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
211 .if defined(OBJS) && !empty(OBJS)
215 .if ${MK_MAN} != "no"
219 .if ${MK_NLS} != "no"