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