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