Merge from vendor branch BINUTILS:
[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.2 2003/06/17 04:37:02 dillon 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:R:S/$/.o/g}
33
34 ${PROG}: ${OBJS}
35 .if defined(PROG_CXX)
36         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
37 .else
38         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
39 .endif
40
41 .else !defined(SRCS)
42
43 .if !target(${PROG})
44 .if defined(PROG_CXX)
45 SRCS=   ${PROG}.cc
46 .else
47 SRCS=   ${PROG}.c
48 .endif
49
50 # Always make an intermediate object file because:
51 # - it saves time rebuilding when only the library has changed
52 # - the name of the object gets put into the executable symbol table instead of
53 #   the name of a variable temporary object.
54 # - it's useful to keep objects around for crunching.
55 OBJS=   ${PROG}.o
56
57 ${PROG}: ${OBJS}
58 .if defined(PROG_CXX)
59         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
60 .else
61         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
62 .endif
63 .endif
64
65 .endif
66
67 .if     !defined(NOMAN) && !defined(MAN) && \
68         !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
69         !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
70         !defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
71         !defined(MAN1aout)
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 .if ${OBJFORMAT} == aout
87         echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} \
88             ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
89 .else
90         echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
91 .if defined(PROG_CXX)
92         echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
93 .endif
94 .endif
95 .endif
96
97 .if !target(install)
98
99 _INSTALLFLAGS:= ${INSTALLFLAGS}
100 .for ie in ${INSTALLFLAGS_EDIT}
101 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
102 .endfor
103
104 .if !target(realinstall)
105 realinstall: _proginstall
106 .ORDER: beforeinstall _proginstall
107 _proginstall:
108 .if defined(PROG)
109 .if defined(PROGNAME)
110         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
111             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
112 .else
113         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
114             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
115 .endif
116 .endif
117 .if defined(HIDEGAME)
118         (cd ${DESTDIR}${ORIGBINDIR}; ln -fs dm ${PROG}; \
119             chown -h ${BINOWN}:${ORIGBINGRP} ${PROG})
120 .endif
121 .endif !target(realinstall)
122
123 .if defined(SCRIPTS) && !empty(SCRIPTS)
124 realinstall: _scriptsinstall
125 .ORDER: beforeinstall _scriptsinstall
126
127 SCRIPTSDIR?=    ${BINDIR}
128 SCRIPTSOWN?=    ${BINOWN}
129 SCRIPTSGRP?=    ${BINGRP}
130 SCRIPTSMODE?=   ${BINMODE}
131
132 .for script in ${SCRIPTS}
133 .if defined(SCRIPTSNAME)
134 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
135 .else
136 SCRIPTSNAME_${script:T}?=       ${script:T:R}
137 .endif
138 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
139 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
140 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
141 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
142 _scriptsinstall: _SCRIPTSINS_${script:T}
143 _SCRIPTSINS_${script:T}: ${script}
144         ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
145             -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
146             ${.ALLSRC} \
147             ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
148 .endfor
149 .endif
150
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} ${.ALLSRC} | more 2>&1
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>