bsd.prog.mk revision 94424
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD: head/share/mk/bsd.prog.mk 94424 2002-04-11 10:44:30Z ru $
3
4.if !target(__initialized__)
5__initialized__:
6.if exists(${.CURDIR}/../Makefile.inc)
7.include "${.CURDIR}/../Makefile.inc"
8.endif
9.endif
10
11.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .s .S
12
13CFLAGS+=${COPTS} ${DEBUG_FLAGS}
14
15.if !defined(DEBUG_FLAGS)
16STRIP?=	-s
17.endif
18
19.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
20LDFLAGS+= -static
21.endif
22
23.if defined(PROG_CXX)
24PROG=	${PROG_CXX}
25DPADD+=	${LIBSTDCPLUSPLUS}
26LDADD+=	-lstdc++
27.endif
28
29.if defined(PROG)
30.if defined(SRCS)
31
32# If there are Objective C sources, link with Objective C libraries.
33.if ${SRCS:M*.m} != ""
34OBJCLIBS?= -lobjc
35LDADD+=	${OBJCLIBS}
36.endif
37
38OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
39
40${PROG}: ${OBJS}
41	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
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	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
61.endif
62
63.endif
64
65.if	!defined(NOMAN) && !defined(MAN) && \
66	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
67	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
68	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
69	!defined(MAN1aout)
70MAN=	${PROG}.1
71MAN1=	${MAN}
72.endif
73.endif
74
75.MAIN: all
76all: objwarn ${PROG} ${SCRIPTS} ${FILES}
77.if !defined(NOMAN)
78all: all-man 
79.endif
80all: _SUBDIR
81
82CLEANFILES+= ${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.endif
92.endif
93
94.if !target(install)
95.if !target(beforeinstall)
96beforeinstall:
97.endif
98
99_INSTALLFLAGS:=	${INSTALLFLAGS}
100.for ie in ${INSTALLFLAGS_EDIT}
101_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
102.endfor
103
104realinstall: beforeinstall
105.if defined(PROG)
106.if defined(PROGNAME)
107	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
108	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
109.else
110	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
111	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
112.endif
113.endif
114.if defined(HIDEGAME)
115	(cd ${DESTDIR}${ORIGBINDIR}; ln -fs dm ${PROG}; \
116	    chown -h ${BINOWN}:${ORIGBINGRP} ${PROG})
117.endif
118.if defined(LINKS) && !empty(LINKS)
119	@set ${LINKS}; \
120	while test $$# -ge 2; do \
121		l=${DESTDIR}$$1; \
122		shift; \
123		t=${DESTDIR}$$1; \
124		shift; \
125		${ECHO} $$t -\> $$l; \
126		ln -f $$l $$t; \
127	done; true
128.endif
129.if defined(SYMLINKS) && !empty(SYMLINKS)
130	@set ${SYMLINKS}; \
131	while test $$# -ge 2; do \
132		l=$$1; \
133		shift; \
134		t=${DESTDIR}$$1; \
135		shift; \
136		${ECHO} $$t -\> $$l; \
137		ln -fs $$l $$t; \
138	done; true
139.endif
140
141.if defined(SCRIPTS) && !empty(SCRIPTS)
142realinstall: _scriptsinstall
143
144SCRIPTSDIR?=	${BINDIR}
145SCRIPTSOWN?=	${BINOWN}
146SCRIPTSGRP?=	${BINGRP}
147SCRIPTSMODE?=	${BINMODE}
148
149.for script in ${SCRIPTS}
150.if defined(SCRIPTSNAME)
151SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
152.else
153SCRIPTSNAME_${script:T}?=	${script:T:R}
154.endif
155SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
156SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
157SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
158SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
159_scriptsinstall: _SCRIPTSINS_${script:T}
160_SCRIPTSINS_${script:T}: ${script}
161	${INSTALL} ${COPY} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
162	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
163	    ${_INSTALLFLAGS} ${.ALLSRC} \
164	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
165.endfor
166.endif
167
168.if defined(FILES) && !empty(FILES)
169realinstall: _filesinstall
170
171FILESDIR?=	${BINDIR}
172FILESOWN?=	${SHAREOWN}
173FILESGRP?=	${SHAREGRP}
174FILESMODE?=	${SHAREMODE}
175
176.for file in ${FILES}
177.if defined(FILESNAME)
178FILESNAME_${file:T}?=	${FILESNAME}
179.else
180FILESNAME_${file:T}?=	${file:T}
181.endif
182FILESDIR_${file:T}?=	${FILESDIR}
183FILESOWN_${file:T}?=	${FILESOWN}
184FILESGRP_${file:T}?=	${FILESGRP}
185FILESMODE_${file:T}?=	${FILESMODE}
186_filesinstall: _FILESINS_${file:T}
187_FILESINS_${file:T}: ${file}
188	${INSTALL} ${COPY} -o ${FILESOWN_${.ALLSRC:T}} \
189	    -g ${FILESGRP_${.ALLSRC:T}} -m ${FILESMODE_${.ALLSRC:T}} \
190	    ${_INSTALLFLAGS} ${.ALLSRC} \
191	    ${DESTDIR}${FILESDIR_${.ALLSRC:T}}/${FILESNAME_${.ALLSRC:T}}
192.endfor
193.endif
194
195install: afterinstall _SUBDIR
196.if !defined(NOMAN)
197afterinstall: realinstall maninstall
198.else
199afterinstall: realinstall
200.endif
201.endif
202
203DISTRIBUTION?=	bin
204.if !target(distribute)
205distribute: _SUBDIR
206.for dist in ${DISTRIBUTION}
207	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
208.endfor
209.endif
210
211.if !target(lint)
212lint: ${SRCS} _SUBDIR
213.if defined(PROG)
214	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} | more 2>&1
215.endif
216.endif
217
218.if defined(NOTAGS)
219tags:
220.endif
221
222.if !target(tags)
223tags: ${SRCS} _SUBDIR
224.if defined(PROG)
225	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
226.if defined(HTML)
227	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
228.endif
229.endif
230.endif
231
232.if !defined(NOMAN)
233.include <bsd.man.mk>
234.else
235.if !target(all-man)
236all-man:
237.endif
238.if !target(maninstall)
239maninstall:
240.endif
241.endif
242
243.if !target(regress)
244regress:
245.endif
246
247.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
248.include <bsd.libnames.mk>
249.endif
250
251.include <bsd.dep.mk>
252
253.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
254${OBJS}: ${SRCS:M*.h}
255.endif
256
257.include <bsd.obj.mk>
258
259.include <bsd.sys.mk>
260