vendor/bmake: upgrade from 20210206 to 20210314
[dragonfly.git] / contrib / bmake / mk / prog.mk
1 #       $Id: prog.mk,v 1.36 2020/08/19 17:51:53 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 ${MK_PROG_LDORDER_MK} != "no"
113 ${PROG}: ldorder
114
115 .include <ldorder.mk>
116 .endif
117
118 .if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
119
120 ${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
121         ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD_LDORDER} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
122
123 .else
124
125 ${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
126         ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD_LDORDER} ${LDADD}
127
128 .endif  # defined(DESTDIR)
129 .endif  # defined(OBJS) && !empty(OBJS)
130
131 .if     !defined(MAN)
132 MAN=    ${PROG}.1
133 .endif  # !defined(MAN)
134 .endif  # defined(PROG)
135
136 .if !defined(_SKIP_BUILD)
137 realbuild: ${PROG}
138 .endif
139
140 all: _SUBDIRUSE
141
142 .if !target(clean)
143 cleanprog:
144         rm -f a.out [Ee]rrs mklog core *.core \
145             ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
146
147 clean: _SUBDIRUSE cleanprog
148 cleandir: _SUBDIRUSE cleanprog
149 .else
150 cleandir: _SUBDIRUSE clean
151 .endif
152
153 .if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
154 afterdepend: .depend
155         @(TMP=/tmp/_depend$$$$; \
156             sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
157               < .depend > $$TMP; \
158             mv $$TMP .depend)
159 .endif
160
161 .if !target(install)
162 .if !target(beforeinstall)
163 beforeinstall:
164 .endif
165 .if !target(afterinstall)
166 afterinstall:
167 .endif
168
169 .if !empty(BINOWN)
170 PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
171 .endif
172
173 .if !target(realinstall)
174 realinstall: proginstall
175 .endif
176 .if !target(proginstall)
177 proginstall:
178 .if defined(PROG)
179         [ -d ${DESTDIR}${BINDIR} ] || \
180         ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
181         ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
182             ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
183 .endif
184 .if defined(HIDEGAME)
185         (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
186 .endif
187 .endif
188
189 .include <links.mk>
190
191 install: maninstall install_links _SUBDIRUSE
192
193 install_links:
194 .if !empty(SYMLINKS)
195         @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
196 .endif
197 .if !empty(LINKS)
198         @set ${LINKS}; ${_LINKS_SCRIPT}
199 .endif
200
201 maninstall: afterinstall
202 afterinstall: realinstall
203 install_links: realinstall
204 proginstall: beforeinstall
205 realinstall: beforeinstall
206 .endif
207
208 .if !target(lint)
209 lint: ${LOBJS}
210 .if defined(LOBJS) && !empty(LOBJS)
211         @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
212 .endif
213 .endif
214
215 .NOPATH:        ${PROG}
216 .if defined(OBJS) && !empty(OBJS)
217 .NOPATH:        ${OBJS}
218 .endif
219
220 .if defined(FILES) || defined(FILESGROUPS)
221 .include <files.mk>
222 .endif
223
224 .if ${MK_MAN} != "no"
225 .include <man.mk>
226 .endif
227
228 .if ${MK_NLS} != "no"
229 .include <nls.mk>
230 .endif
231
232 .include <obj.mk>
233 .include <dep.mk>
234 .include <subdir.mk>
235
236 .if !empty(PROG) && ${MK_STAGING_PROG} == "yes"
237 STAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR}
238 STAGE_DIR.prog ?= ${STAGE_BINDIR}
239 .if ${PROG_NAME:U${PROG}} != ${PROG}
240 STAGE_AS_SETS += prog
241 STAGE_AS_${PROG} = ${PROG_NAME}
242 stage_as.prog: ${PROG}
243 .else
244 STAGE_SETS += prog
245 stage_files.prog: ${PROG}
246 .endif
247 .endif
248
249 .include <final.mk>
250
251 .endif