xref: /dragonfly/share/mk/bsd.prog.mk (revision 36a3d1d6)
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.14 2008/05/19 10:26:02 corecode Exp $
4
5.include <bsd.init.mk>
6
7.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .s .S
8
9CFLAGS+=${COPTS} ${DEBUG_FLAGS}
10
11.if !defined(DEBUG_FLAGS)
12STRIP?=	-s
13.endif
14
15.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
16LDFLAGS+= -static
17.endif
18
19.if defined(PROG_CXX)
20PROG=	${PROG_CXX}
21.endif
22
23.include <bsd.patch.mk>
24
25.if defined(PROG)
26.if defined(SRCS)
27
28# If there are Objective C sources, link with Objective C libraries.
29.if ${SRCS:M*.m} != ""
30OBJCLIBS?= -lobjc
31LDADD+=	${OBJCLIBS}
32.endif
33
34OBJS+=  ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
35
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
43.else # !defined(SRCS)
44
45.if !target(${PROG})
46.if defined(PROG_CXX)
47SRCS=	${PROG}.cc
48.else
49SRCS=	${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.
57OBJS=	${PROG}.o
58
59${PROG}: ${OBJS}
60.if defined(PROG_CXX)
61	${CXX_LINK} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
62.else
63	${CC_LINK} ${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)
73MAN=	${PROG}.1
74MAN1=	${MAN}
75.endif
76.endif
77
78all: objwarn ${PROG} ${SCRIPTS}
79.if !defined(NOMAN)
80all: _manpages
81.endif
82
83CLEANFILES+= ${PROG} ${OBJS}
84
85.if defined(PROG)
86_EXTRADEPEND:
87	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
88.if defined(PROG_CXX)
89	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
90.endif
91.endif
92
93.if !target(install)
94
95_INSTALLFLAGS:=	${INSTALLFLAGS}
96.for ie in ${INSTALLFLAGS_EDIT}
97_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
98.endfor
99
100.if !target(realinstall)
101realinstall: _proginstall
102.ORDER: beforeinstall _proginstall
103_proginstall:
104.if defined(PROG)
105.if defined(PROGNAME)
106	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
107	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
108.else
109	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
110	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
111.endif
112.endif
113.if defined(HIDEGAME)
114	(cd ${DESTDIR}${ORIGBINDIR}; ${LN} -fs dm ${PROG}; \
115	    chown -h ${BINOWN}:${ORIGBINGRP} ${PROG})
116.endif
117.endif # !target(realinstall)
118
119.if defined(SCRIPTS) && !empty(SCRIPTS)
120realinstall: _scriptsinstall
121.ORDER: beforeinstall _scriptsinstall
122
123SCRIPTSDIR?=	${BINDIR}
124SCRIPTSOWN?=	${BINOWN}
125SCRIPTSGRP?=	${BINGRP}
126SCRIPTSMODE?=	${BINMODE}
127
128.for script in ${SCRIPTS}
129.if defined(SCRIPTSNAME)
130SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
131.else
132SCRIPTSNAME_${script:T}?=	${script:T:R}
133.endif
134SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
135SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
136SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
137SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
138_scriptsinstall: _SCRIPTSINS_${script:T}
139_SCRIPTSINS_${script:T}: ${script}
140	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
141	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
142	    ${.ALLSRC} \
143	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
144.endfor
145.endif
146
147NLSNAME?=	${PROG}
148
149.include <bsd.nls.mk>
150.include <bsd.files.mk>
151.include <bsd.incs.mk>
152.include <bsd.links.mk>
153
154.if !defined(NOMAN)
155realinstall: _maninstall
156.ORDER: beforeinstall _maninstall
157.endif
158
159.endif
160
161.if !target(lint)
162lint: ${SRCS}
163.if defined(PROG)
164	@${LINT} ${LINTFLAGS} ${.ALLSRC} | more 2>&1
165.endif
166.endif
167
168.if !defined(NOMAN)
169.include <bsd.man.mk>
170.endif
171
172.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
173.include <bsd.libnames.mk>
174.endif
175
176.include <bsd.dep.mk>
177
178.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
179${OBJS}: ${SRCS:M*.h}
180.endif
181
182.include <bsd.obj.mk>
183
184.include <bsd.sys.mk>
185
186