mk/prog: Support CRUNCH_CFLAGS for crunchgen's buildopts
[dragonfly.git] / share / mk / bsd.prog.mk
1 #       from: @(#)bsd.prog.mk   5.26 (Berkeley) 6/25/91
2 # $FreeBSD: src/share/mk/bsd.prog.mk,v 1.86.2.17 2002/12/23 16:33:37 ru Exp $
3
4 .include <bsd.init.mk>
5
6 .SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .s .S
7
8 CFLAGS+=${COPTS} ${DEBUG_FLAGS}
9
10 .if defined(CRUNCH_CFLAGS)
11 CFLAGS+=${CRUNCH_CFLAGS}
12 .endif
13
14 PRIVATELIB_BLDFLAGS?=   -rpath /lib/priv -L /usr/lib/priv
15 PRIVATELIB_LDFLAGS?=    -rpath /lib/priv -L ${_SHLIBDIRPREFIX}/usr/lib/priv
16
17 .if !defined(DEBUG_FLAGS)
18 STRIP?= -s
19 .endif
20
21 .if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
22 LDFLAGS+= -static
23 .endif
24
25 .if defined(PROG_CXX)
26 PROG=   ${PROG_CXX}
27 .endif
28
29 .include <bsd.patch.mk>
30
31 .if defined(PROG)
32 .if defined(SRCS)
33
34 # If there are Objective C sources, link with Objective C libraries.
35 .if ${SRCS:M*.m} != ""
36 OBJCLIBS?= -lobjc
37 LDADD+= ${OBJCLIBS}
38 .endif
39
40 .if !empty(SRCS)
41 OBJS+=  ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
42 .endif
43
44 .if !target(${PROG})
45 ${PROG}: ${OBJS}
46 .if defined(PROG_CXX)
47         ${CXX_LINK} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
48 .else
49         ${CC_LINK} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
50 .endif
51 .endif
52
53 .else # !defined(SRCS)
54
55 .if !target(${PROG})
56 .if defined(PROG_CXX)
57 SRCS=   ${PROG}.cc
58 .else
59 SRCS=   ${PROG}.c
60 .endif
61
62 # Always make an intermediate object file because:
63 # - it saves time rebuilding when only the library has changed
64 # - the name of the object gets put into the executable symbol table instead of
65 #   the name of a variable temporary object.
66 # - it's useful to keep objects around for crunching.
67 OBJS=   ${PROG}.o
68
69 ${PROG}: ${OBJS}
70 .if defined(PROG_CXX)
71         ${CXX_LINK} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
72 .else
73         ${CC_LINK} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
74 .endif
75 .endif
76
77 .endif
78
79 .if     !defined(NOMAN) && !defined(MAN) && \
80         !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
81         !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
82         !defined(MAN7) && !defined(MAN8) && !defined(MAN9)
83 MAN=    ${PROG}.1
84 MAN1=   ${MAN}
85 .endif
86 .endif
87
88 all: objwarn ${PROG} ${SCRIPTS}
89 .if !defined(NOMAN)
90 all: _manpages
91 .endif
92
93 CLEANFILES+= ${PROG} ${OBJS}
94
95 .if defined(PROG)
96 _EXTRADEPEND:
97         echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
98 .if defined(PROG_CXX)
99         echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
100 .endif
101 .endif
102
103 .if !target(install)
104
105 _INSTALLFLAGS:= ${INSTALLFLAGS}
106 .for ie in ${INSTALLFLAGS_EDIT}
107 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
108 .endfor
109
110 .if !target(realinstall) && !defined(INTERNALPROG)
111 realinstall: _proginstall
112 .ORDER: beforeinstall _proginstall
113 _proginstall:
114 .if defined(PROG)
115 .if defined(PROGNAME)
116         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
117             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
118 .else
119         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
120             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
121 .endif
122 .endif
123 .endif # !target(realinstall) && !defined(INTERNALPROG)
124
125 .if defined(SCRIPTS) && !empty(SCRIPTS)
126 realinstall: _scriptsinstall
127 .ORDER: beforeinstall _scriptsinstall
128
129 SCRIPTSDIR?=    ${BINDIR}
130 SCRIPTSOWN?=    ${BINOWN}
131 SCRIPTSGRP?=    ${BINGRP}
132 SCRIPTSMODE?=   ${BINMODE}
133
134 .for script in ${SCRIPTS}
135 .if defined(SCRIPTSNAME)
136 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
137 .else
138 SCRIPTSNAME_${script:T}?=       ${script:T:R}
139 .endif
140 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
141 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
142 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
143 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
144 _scriptsinstall: _SCRIPTSINS_${script:T}
145 _SCRIPTSINS_${script:T}: ${script}
146         ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
147             -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
148             ${.ALLSRC} \
149             ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
150 .endfor
151 .endif
152
153 NLSNAME?=       ${PROG}
154
155 .include <bsd.nls.mk>
156 .include <bsd.files.mk>
157 .include <bsd.incs.mk>
158 .include <bsd.links.mk>
159
160 .if !defined(NOMAN)
161 realinstall: _maninstall
162 .ORDER: beforeinstall _maninstall
163 .endif
164
165 .endif
166
167 .if !target(lint)
168 lint: ${SRCS}
169 .if defined(PROG)
170         -@${LINT} ${LINTFLAGS} ${CFLAGS:M-I*:S/-I/-I /g} ${.ALLSRC}
171 .endif
172 .endif
173
174 .if !defined(NOMAN)
175 .include <bsd.man.mk>
176 .endif
177
178 .if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
179 .include <bsd.libnames.mk>
180 .endif
181
182 .include <bsd.dep.mk>
183
184 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
185 ${OBJS}: ${SRCS:M*.h}
186 .endif
187
188 .include <bsd.obj.mk>
189
190 .include <bsd.sys.mk>
191