bsd.prog.mk revision 162293
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD: head/share/mk/bsd.prog.mk 162293 2006-09-13 23:27:21Z obrien $
3
4.include <bsd.init.mk>
5
6.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
7
8# XXX The use of COPTS in modern makefiles is discouraged.
9.if defined(COPTS)
10CFLAGS+=${COPTS}
11.endif
12
13.if ${MK_ASSERT_DEBUG} == "no"
14CFLAGS+= -DNDEBUG
15NO_WERROR=
16.endif
17
18.if defined(DEBUG_FLAGS)
19CFLAGS+=${DEBUG_FLAGS}
20.endif
21
22.if defined(CRUNCH_CFLAGS)
23CFLAGS+=${CRUNCH_CFLAGS}
24.endif
25
26.if !defined(DEBUG_FLAGS)
27STRIP?=	-s
28.endif
29
30.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
31LDFLAGS+= -static
32.endif
33
34.if defined(PROG_CXX)
35PROG=	${PROG_CXX}
36.endif
37
38.if defined(PROG)
39.if defined(SRCS)
40
41# If there are Objective C sources, link with Objective C libraries.
42.if !empty(SRCS:M*.m)
43OBJCLIBS?= -lobjc -lpthread
44LDADD+=	${OBJCLIBS}
45.endif
46
47OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
48
49${PROG}: ${OBJS}
50.if defined(PROG_CXX)
51	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
52.else
53	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
54.endif
55
56.else	# !defined(SRCS)
57
58.if !target(${PROG})
59.if defined(PROG_CXX)
60SRCS=	${PROG}.cc
61.else
62SRCS=	${PROG}.c
63.endif
64
65# Always make an intermediate object file because:
66# - it saves time rebuilding when only the library has changed
67# - the name of the object gets put into the executable symbol table instead of
68#   the name of a variable temporary object.
69# - it's useful to keep objects around for crunching.
70OBJS=	${PROG}.o
71
72${PROG}: ${OBJS}
73.if defined(PROG_CXX)
74	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
75.else
76	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
77.endif
78.endif
79
80.endif
81
82.if	${MK_MAN} != "no" && !defined(MAN) && \
83	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
84	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
85	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
86	!defined(MAN1aout)
87MAN=	${PROG}.1
88MAN1=	${MAN}
89.endif
90.endif
91
92all: objwarn ${PROG} ${SCRIPTS}
93.if ${MK_MAN} != "no"
94all: _manpages
95.endif
96
97.if defined(PROG)
98CLEANFILES+= ${PROG}
99.endif
100
101.if defined(OBJS)
102CLEANFILES+= ${OBJS}
103.endif
104
105.include <bsd.libnames.mk>
106
107.if defined(PROG)
108_EXTRADEPEND:
109.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
110.if defined(DPADD) && !empty(DPADD)
111	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
112.endif
113.else
114	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
115.if defined(PROG_CXX)
116	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
117.endif
118.endif
119.endif
120
121.if !target(install)
122
123.if defined(PRECIOUSPROG)
124.if !defined(NO_FSCHG)
125INSTALLFLAGS+= -fschg
126.endif
127INSTALLFLAGS+= -S
128.endif
129
130_INSTALLFLAGS:=	${INSTALLFLAGS}
131.for ie in ${INSTALLFLAGS_EDIT}
132_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
133.endfor
134
135.if !target(realinstall) && !defined(INTERNALPROG)
136realinstall: _proginstall
137.ORDER: beforeinstall _proginstall
138_proginstall:
139.if defined(PROG)
140.if defined(PROGNAME)
141	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
142	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
143.else
144	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
145	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
146.endif
147.endif
148.endif	# !target(realinstall)
149
150.if defined(SCRIPTS) && !empty(SCRIPTS)
151realinstall: _scriptsinstall
152.ORDER: beforeinstall _scriptsinstall
153
154SCRIPTSDIR?=	${BINDIR}
155SCRIPTSOWN?=	${BINOWN}
156SCRIPTSGRP?=	${BINGRP}
157SCRIPTSMODE?=	${BINMODE}
158
159.for script in ${SCRIPTS}
160.if defined(SCRIPTSNAME)
161SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
162.else
163SCRIPTSNAME_${script:T}?=	${script:T:R}
164.endif
165SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
166SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
167SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
168SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
169_scriptsinstall: _SCRIPTSINS_${script:T}
170_SCRIPTSINS_${script:T}: ${script}
171	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
172	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
173	    ${.ALLSRC} \
174	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
175.endfor
176.endif
177
178NLSNAME?=	${PROG}
179.include <bsd.nls.mk>
180
181.include <bsd.files.mk>
182.include <bsd.incs.mk>
183.include <bsd.links.mk>
184
185.if ${MK_MAN} != "no"
186realinstall: _maninstall
187.ORDER: beforeinstall _maninstall
188.endif
189
190.endif
191
192.if !target(lint)
193lint: ${SRCS:M*.c}
194.if defined(PROG)
195	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
196.endif
197.endif
198
199.if ${MK_MAN} != "no"
200.include <bsd.man.mk>
201.endif
202
203.include <bsd.dep.mk>
204
205.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
206${OBJS}: ${SRCS:M*.h}
207.endif
208
209.include <bsd.obj.mk>
210
211.include <bsd.sys.mk>
212
213.if defined(PORTNAME)
214.include <bsd.pkg.mk>
215.endif
216