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