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