]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - share/mk/bsd.prog.mk
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.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 !defined(NO_CTF) && (${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 ${PROG}: ${OBJS}
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 .if defined(CTFMERGE)
64         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
65 .endif
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 ${PROG}: ${OBJS}
84 .if defined(PROG_CXX)
85         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
86 .else
87         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
88 .endif
89 .if defined(CTFMERGE)
90         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
91 .endif
92 .endif
93
94 .endif
95
96 .if     ${MK_MAN} != "no" && !defined(MAN) && \
97         !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
98         !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
99         !defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
100         !defined(MAN1aout)
101 MAN=    ${PROG}.1
102 MAN1=   ${MAN}
103 .endif
104 .endif
105
106 all: objwarn ${PROG} ${SCRIPTS}
107 .if ${MK_MAN} != "no"
108 all: _manpages
109 .endif
110
111 .if defined(PROG)
112 CLEANFILES+= ${PROG}
113 .endif
114
115 .if defined(OBJS)
116 CLEANFILES+= ${OBJS}
117 .endif
118
119 .include <bsd.libnames.mk>
120
121 .if defined(PROG)
122 _EXTRADEPEND:
123 .if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
124 .if defined(DPADD) && !empty(DPADD)
125         echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
126 .endif
127 .else
128         echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
129 .if defined(PROG_CXX)
130         echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
131 .endif
132 .endif
133 .endif
134
135 .if !target(install)
136
137 .if defined(PRECIOUSPROG)
138 .if !defined(NO_FSCHG)
139 INSTALLFLAGS+= -fschg
140 .endif
141 INSTALLFLAGS+= -S
142 .endif
143
144 _INSTALLFLAGS:= ${INSTALLFLAGS}
145 .for ie in ${INSTALLFLAGS_EDIT}
146 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
147 .endfor
148
149 .if !target(realinstall) && !defined(INTERNALPROG)
150 realinstall: _proginstall
151 .ORDER: beforeinstall _proginstall
152 _proginstall:
153 .if defined(PROG)
154 .if defined(PROGNAME)
155         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
156             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
157 .else
158         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
159             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
160 .endif
161 .endif
162 .endif  # !target(realinstall)
163
164 .if defined(SCRIPTS) && !empty(SCRIPTS)
165 realinstall: _scriptsinstall
166 .ORDER: beforeinstall _scriptsinstall
167
168 SCRIPTSDIR?=    ${BINDIR}
169 SCRIPTSOWN?=    ${BINOWN}
170 SCRIPTSGRP?=    ${BINGRP}
171 SCRIPTSMODE?=   ${BINMODE}
172
173 .for script in ${SCRIPTS}
174 .if defined(SCRIPTSNAME)
175 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
176 .else
177 SCRIPTSNAME_${script:T}?=       ${script:T:R}
178 .endif
179 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
180 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
181 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
182 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
183 _scriptsinstall: _SCRIPTSINS_${script:T}
184 _SCRIPTSINS_${script:T}: ${script}
185         ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
186             -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
187             ${.ALLSRC} \
188             ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
189 .endfor
190 .endif
191
192 NLSNAME?=       ${PROG}
193 .include <bsd.nls.mk>
194
195 .include <bsd.files.mk>
196 .include <bsd.incs.mk>
197 .include <bsd.links.mk>
198
199 .if ${MK_MAN} != "no"
200 realinstall: _maninstall
201 .ORDER: beforeinstall _maninstall
202 .endif
203
204 .endif
205
206 .if !target(lint)
207 lint: ${SRCS:M*.c}
208 .if defined(PROG)
209         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
210 .endif
211 .endif
212
213 .if ${MK_MAN} != "no"
214 .include <bsd.man.mk>
215 .endif
216
217 .include <bsd.dep.mk>
218
219 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
220 ${OBJS}: ${SRCS:M*.h}
221 .endif
222
223 .include <bsd.obj.mk>
224
225 .include <bsd.sys.mk>
226
227 .if defined(PORTNAME)
228 .include <bsd.pkg.mk>
229 .endif