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