]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/bmake/mk/prog.mk
MFC bmake-20170720
[FreeBSD/stable/10.git] / contrib / bmake / mk / prog.mk
1 #       $Id: prog.mk,v 1.32 2017/05/06 17:30:09 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}
11 MAN${_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
16 CFLAGS+=        ${COPTS}
17
18 .if ${TARGET_OSNAME} == "NetBSD"
19 .if ${MACHINE_ARCH} == "sparc64"
20 CFLAGS+=        -mcmodel=medlow
21 .endif
22
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
39
40 .ifndef LIBCRT0
41 LIBCRT0=        ${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 ${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
61
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
68
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
75
76
77 .if defined(PROG)
78 BINDIR ?= ${prefix}/bin
79
80 SRCS?=  ${PROG}.c
81 .for s in ${SRCS:N*.h:N*.sh:M*/*}
82 ${.o .po .lo:L:@o@${s:T:R}$o@}: $s
83 .endfor
84 .if !empty(SRCS:N*.h:N*.sh)
85 OBJS+=  ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
86 LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
87 .endif
88
89 .if defined(OBJS) && !empty(OBJS)
90 .NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
91
92 # this is known to work for NetBSD 1.6 and FreeBSD 4.2
93 .if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
94 _PROGLDOPTS=
95 .if ${SHLINKDIR} != "/usr/libexec"      # XXX: change or remove if ld.so moves
96 _PROGLDOPTS+=   -Wl,-dynamic-linker=${_SHLINKER}
97 .endif
98 .if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
99 _PROGLDOPTS+=   -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
100                 -L${DESTDIR}${SHLIBDIR}
101 .endif
102 _PROGLDOPTS+=   -Wl,-rpath,${SHLIBDIR}:/usr/lib 
103
104 .if defined(PROG_CXX)
105 _CCLINK=        ${CXX}
106 _SUPCXX=        -lstdc++ -lm
107 .endif
108 .endif  # NetBSD
109
110 _CCLINK?=       ${CC}
111
112 .if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
113
114 ${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
115         ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
116
117 .else
118
119 ${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
120         ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
121
122 .endif  # defined(DESTDIR)
123 .endif  # defined(OBJS) && !empty(OBJS)
124
125 .if     !defined(MAN)
126 MAN=    ${PROG}.1
127 .endif  # !defined(MAN)
128 .endif  # defined(PROG)
129
130 .if !defined(_SKIP_BUILD)
131 realbuild: ${PROG}
132 .endif
133
134 all: _SUBDIRUSE
135
136 .if !target(clean)
137 cleanprog:
138         rm -f a.out [Ee]rrs mklog core *.core \
139             ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
140
141 clean: _SUBDIRUSE cleanprog
142 cleandir: _SUBDIRUSE cleanprog
143 .else
144 cleandir: _SUBDIRUSE clean
145 .endif
146
147 .if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
148 afterdepend: .depend
149         @(TMP=/tmp/_depend$$$$; \
150             sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
151               < .depend > $$TMP; \
152             mv $$TMP .depend)
153 .endif
154
155 .if !target(install)
156 .if !target(beforeinstall)
157 beforeinstall:
158 .endif
159 .if !target(afterinstall)
160 afterinstall:
161 .endif
162
163 .if !empty(BINOWN)
164 PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
165 .endif
166
167 .if !target(realinstall)
168 realinstall: proginstall
169 .endif
170 .if !target(proginstall)
171 proginstall:
172 .if defined(PROG)
173         [ -d ${DESTDIR}${BINDIR} ] || \
174         ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
175         ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
176             ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
177 .endif
178 .if defined(HIDEGAME)
179         (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
180 .endif
181 .endif
182
183 .include <links.mk>
184
185 install: maninstall install_links _SUBDIRUSE
186
187 install_links:
188 .if !empty(SYMLINKS)
189         @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
190 .endif
191 .if !empty(LINKS)
192         @set ${LINKS}; ${_LINKS_SCRIPT}
193 .endif
194
195 maninstall: afterinstall
196 afterinstall: realinstall
197 install_links: realinstall
198 proginstall: beforeinstall
199 realinstall: beforeinstall
200 .endif
201
202 .if !target(lint)
203 lint: ${LOBJS}
204 .if defined(LOBJS) && !empty(LOBJS)
205         @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
206 .endif
207 .endif
208
209 .NOPATH:        ${PROG}
210 .if defined(OBJS) && !empty(OBJS)
211 .NOPATH:        ${OBJS}
212 .endif
213
214 .if defined(FILES) || defined(FILESGROUPS)
215 .include <files.mk>
216 .endif
217
218 .if ${MK_MAN} != "no"
219 .include <man.mk>
220 .endif
221
222 .if ${MK_NLS} != "no"
223 .include <nls.mk>
224 .endif
225
226 .include <obj.mk>
227 .include <dep.mk>
228 .include <subdir.mk>
229
230 .if !empty(PROG) && ${MK_STAGING_PROG} == "yes"
231 STAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR}
232 STAGE_DIR.prog ?= ${STAGE_BINDIR}
233 .if ${PROG_NAME:U${PROG}} != ${PROG}
234 STAGE_AS_SETS += prog
235 STAGE_AS_${PROG} = ${PROG_NAME}
236 stage_as.prog: ${PROG}
237 .else
238 STAGE_SETS += prog
239 stage_files.prog: ${PROG}
240 .endif
241 .endif
242
243 .include <final.mk>
244
245 .endif