]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - share/mk/bsd.prog.mk
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / share / mk / bsd.prog.mk
1 #       from: @(#)bsd.prog.mk   5.26 (Berkeley) 6/25/91
2 # $FreeBSD$
3
4 .include <bsd.init.mk>
5
6 .SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
7
8 # XXX The use of COPTS in modern makefiles is discouraged.
9 .if defined(COPTS)
10 CFLAGS+=${COPTS}
11 .endif
12
13 .if ${MK_ASSERT_DEBUG} == "no"
14 CFLAGS+= -DNDEBUG
15 NO_WERROR=
16 .endif
17
18 # Enable CTF conversion on request.
19 .if defined(WITH_CTF)
20 .undef NO_CTF
21 .endif
22
23 .if defined(DEBUG_FLAGS)
24 CFLAGS+=${DEBUG_FLAGS}
25 CXXFLAGS+=${DEBUG_FLAGS}
26
27 .if !defined(NO_CTF) && (${DEBUG_FLAGS:M-g} != "")
28 CTFFLAGS+= -g
29 .endif
30 .endif
31
32 .if defined(CRUNCH_CFLAGS)
33 CFLAGS+=${CRUNCH_CFLAGS}
34 .endif
35
36 .if !defined(DEBUG_FLAGS)
37 STRIP?= -s
38 .endif
39
40 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
41 LDFLAGS+= -static
42 .endif
43
44 .if defined(PROG_CXX)
45 PROG=   ${PROG_CXX}
46 .endif
47
48 .if defined(PROG)
49 .if defined(SRCS)
50
51 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
52
53 .if target(beforelinking)
54 ${PROG}: ${OBJS} beforelinking
55 .else
56 ${PROG}: ${OBJS}
57 .endif
58 .if defined(PROG_CXX)
59         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
60 .else
61         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
62 .endif
63         @[ -z "${CTFMERGE}" -o -n "${NO_CTF}" ] || \
64                 (${ECHO} ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} && \
65                 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS})
66
67 .else   # !defined(SRCS)
68
69 .if !target(${PROG})
70 .if defined(PROG_CXX)
71 SRCS=   ${PROG}.cc
72 .else
73 SRCS=   ${PROG}.c
74 .endif
75
76 # Always make an intermediate object file because:
77 # - it saves time rebuilding when only the library has changed
78 # - the name of the object gets put into the executable symbol table instead of
79 #   the name of a variable temporary object.
80 # - it's useful to keep objects around for crunching.
81 OBJS=   ${PROG}.o
82
83 .if target(beforelinking)
84 ${PROG}: ${OBJS} beforelinking
85 .else
86 ${PROG}: ${OBJS}
87 .endif
88 .if defined(PROG_CXX)
89         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
90 .else
91         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
92 .endif
93         @[ -z "${CTFMERGE}" -o -n "${NO_CTF}" ] || \
94                 (${ECHO} ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} && \
95                 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS})
96 .endif
97
98 .endif
99
100 .if     ${MK_MAN} != "no" && !defined(MAN) && \
101         !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
102         !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
103         !defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
104         !defined(MAN1aout)
105 MAN=    ${PROG}.1
106 MAN1=   ${MAN}
107 .endif
108 .endif
109
110 all: objwarn ${PROG} ${SCRIPTS}
111 .if ${MK_MAN} != "no"
112 all: _manpages
113 .endif
114
115 .if defined(PROG)
116 CLEANFILES+= ${PROG}
117 .endif
118
119 .if defined(OBJS)
120 CLEANFILES+= ${OBJS}
121 .endif
122
123 .include <bsd.libnames.mk>
124
125 .if defined(PROG)
126 _EXTRADEPEND:
127 .if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
128 .if defined(DPADD) && !empty(DPADD)
129         echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
130 .endif
131 .else
132         echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
133 .if defined(PROG_CXX)
134         echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
135 .endif
136 .endif
137 .endif
138
139 .if !target(install)
140
141 .if defined(PRECIOUSPROG)
142 .if !defined(NO_FSCHG)
143 INSTALLFLAGS+= -fschg
144 .endif
145 INSTALLFLAGS+= -S
146 .endif
147
148 _INSTALLFLAGS:= ${INSTALLFLAGS}
149 .for ie in ${INSTALLFLAGS_EDIT}
150 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
151 .endfor
152
153 .if !target(realinstall) && !defined(INTERNALPROG)
154 realinstall: _proginstall
155 .ORDER: beforeinstall _proginstall
156 _proginstall:
157 .if defined(PROG)
158 .if defined(PROGNAME)
159         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
160             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
161 .else
162         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
163             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
164 .endif
165 .endif
166 .endif  # !target(realinstall)
167
168 .if defined(SCRIPTS) && !empty(SCRIPTS)
169 realinstall: _scriptsinstall
170 .ORDER: beforeinstall _scriptsinstall
171
172 SCRIPTSDIR?=    ${BINDIR}
173 SCRIPTSOWN?=    ${BINOWN}
174 SCRIPTSGRP?=    ${BINGRP}
175 SCRIPTSMODE?=   ${BINMODE}
176
177 .for script in ${SCRIPTS}
178 .if defined(SCRIPTSNAME)
179 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
180 .else
181 SCRIPTSNAME_${script:T}?=       ${script:T:R}
182 .endif
183 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
184 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
185 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
186 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
187 _scriptsinstall: _SCRIPTSINS_${script:T}
188 _SCRIPTSINS_${script:T}: ${script}
189         ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
190             -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
191             ${.ALLSRC} \
192             ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
193 .endfor
194 .endif
195
196 NLSNAME?=       ${PROG}
197 .include <bsd.nls.mk>
198
199 .include <bsd.files.mk>
200 .include <bsd.incs.mk>
201 .include <bsd.links.mk>
202
203 .if ${MK_MAN} != "no"
204 realinstall: _maninstall
205 .ORDER: beforeinstall _maninstall
206 .endif
207
208 .endif
209
210 .if !target(lint)
211 lint: ${SRCS:M*.c}
212 .if defined(PROG)
213         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
214 .endif
215 .endif
216
217 .if ${MK_MAN} != "no"
218 .include <bsd.man.mk>
219 .endif
220
221 .include <bsd.dep.mk>
222
223 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
224 ${OBJS}: ${SRCS:M*.h}
225 .endif
226
227 .include <bsd.obj.mk>
228
229 .include <bsd.sys.mk>
230
231 .if defined(PORTNAME)
232 .include <bsd.pkg.mk>
233 .endif