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