bsd.prog.mk revision 94113
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD: head/share/mk/bsd.prog.mk 94113 2002-04-07 14:58:12Z 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)
24.if defined(SRCS)
25
26# If there are Objective C sources, link with Objective C libraries.
27.if ${SRCS:M*.m} != ""
28OBJCLIBS?= -lobjc
29LDADD+=	${OBJCLIBS}
30.endif
31
32OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
33
34${PROG}: ${OBJS}
35	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
36
37.else !defined(SRCS)
38
39.if !target(${PROG})
40SRCS=	${PROG}.c
41
42# Always make an intermediate object file because:
43# - it saves time rebuilding when only the library has changed
44# - the name of the object gets put into the executable symbol table instead of
45#   the name of a variable temporary object.
46# - it's useful to keep objects around for crunching.
47OBJS=	${PROG}.o
48
49${PROG}: ${OBJS}
50	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
51.endif
52
53.endif
54
55.if	!defined(NOMAN) && !defined(MAN) && \
56	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
57	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
58	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
59	!defined(MAN1aout)
60MAN=	${PROG}.1
61MAN1=	${MAN}
62.endif
63.endif
64
65.MAIN: all
66all: objwarn ${PROG} ${SCRIPTS} ${FILES}
67.if !defined(NOMAN)
68all: all-man 
69.endif
70all: _SUBDIR
71
72CLEANFILES+= ${PROG} ${OBJS}
73
74.if defined(PROG)
75_EXTRADEPEND:
76.if ${OBJFORMAT} == aout
77	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} ${LDDESTDIR} \
78	    ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
79.else
80	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
81.endif
82.endif
83
84.if !target(install)
85.if !target(beforeinstall)
86beforeinstall:
87.endif
88
89_INSTALLFLAGS:=	${INSTALLFLAGS}
90.for ie in ${INSTALLFLAGS_EDIT}
91_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
92.endfor
93
94realinstall: beforeinstall
95.if defined(PROG)
96.if defined(PROGNAME)
97	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
98	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
99.else
100	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
101	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
102.endif
103.endif
104.if defined(HIDEGAME)
105	(cd ${DESTDIR}${ORIGBINDIR}; ln -fs dm ${PROG}; \
106	    chown -h ${BINOWN}:${ORIGBINGRP} ${PROG})
107.endif
108.if defined(LINKS) && !empty(LINKS)
109	@set ${LINKS}; \
110	while test $$# -ge 2; do \
111		l=${DESTDIR}$$1; \
112		shift; \
113		t=${DESTDIR}$$1; \
114		shift; \
115		${ECHO} $$t -\> $$l; \
116		ln -f $$l $$t; \
117	done; true
118.endif
119.if defined(SYMLINKS) && !empty(SYMLINKS)
120	@set ${SYMLINKS}; \
121	while test $$# -ge 2; do \
122		l=$$1; \
123		shift; \
124		t=${DESTDIR}$$1; \
125		shift; \
126		${ECHO} $$t -\> $$l; \
127		ln -fs $$l $$t; \
128	done; true
129.endif
130
131.if defined(SCRIPTS) && !empty(SCRIPTS)
132realinstall: _scriptsinstall
133
134SCRIPTSDIR?=	${BINDIR}
135SCRIPTSOWN?=	${BINOWN}
136SCRIPTSGRP?=	${BINGRP}
137SCRIPTSMODE?=	${BINMODE}
138
139.for script in ${SCRIPTS}
140.if defined(SCRIPTSNAME)
141SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
142.else
143SCRIPTSNAME_${script:T}?=	${script:T:R}
144.endif
145SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
146SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
147SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
148SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
149_scriptsinstall: _SCRIPTSINS_${script:T}
150_SCRIPTSINS_${script:T}: ${script}
151	${INSTALL} ${COPY} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
152	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
153	    ${_INSTALLFLAGS} ${.ALLSRC} \
154	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
155.endfor
156.endif
157
158.if defined(FILES) && !empty(FILES)
159realinstall: _filesinstall
160
161FILESDIR?=	${BINDIR}
162FILESOWN?=	${SHAREOWN}
163FILESGRP?=	${SHAREGRP}
164FILESMODE?=	${SHAREMODE}
165
166.for file in ${FILES}
167.if defined(FILESNAME)
168FILESNAME_${file:T}?=	${FILESNAME}
169.else
170FILESNAME_${file:T}?=	${file:T}
171.endif
172FILESDIR_${file:T}?=	${FILESDIR}
173FILESOWN_${file:T}?=	${FILESOWN}
174FILESGRP_${file:T}?=	${FILESGRP}
175FILESMODE_${file:T}?=	${FILESMODE}
176_filesinstall: _FILESINS_${file:T}
177_FILESINS_${file:T}: ${file}
178	${INSTALL} ${COPY} -o ${FILESOWN_${.ALLSRC:T}} \
179	    -g ${FILESGRP_${.ALLSRC:T}} -m ${FILESMODE_${.ALLSRC:T}} \
180	    ${_INSTALLFLAGS} ${.ALLSRC} \
181	    ${DESTDIR}${FILESDIR_${.ALLSRC:T}}/${FILESNAME_${.ALLSRC:T}}
182.endfor
183.endif
184
185install: afterinstall _SUBDIR
186.if !defined(NOMAN)
187afterinstall: realinstall maninstall
188.else
189afterinstall: realinstall
190.endif
191.endif
192
193DISTRIBUTION?=	bin
194.if !target(distribute)
195distribute: _SUBDIR
196.for dist in ${DISTRIBUTION}
197	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
198.endfor
199.endif
200
201.if !target(lint)
202lint: ${SRCS} _SUBDIR
203.if defined(PROG)
204	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} | more 2>&1
205.endif
206.endif
207
208.if defined(NOTAGS)
209tags:
210.endif
211
212.if !target(tags)
213tags: ${SRCS} _SUBDIR
214.if defined(PROG)
215	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
216.if defined(HTML)
217	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
218.endif
219.endif
220.endif
221
222.if !defined(NOMAN)
223.include <bsd.man.mk>
224.else
225.if !target(all-man)
226all-man:
227.endif
228.if !target(maninstall)
229maninstall:
230.endif
231.endif
232
233.if !target(regress)
234regress:
235.endif
236
237.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
238.include <bsd.libnames.mk>
239.endif
240
241.include <bsd.dep.mk>
242
243.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
244${OBJS}: ${SRCS:M*.h}
245.endif
246
247.include <bsd.obj.mk>
248
249.include <bsd.sys.mk>
250