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