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