bsd.prog.mk revision 24861
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.prog.mk,v 1.46 1997/04/09 16:10:27 bde Exp $
3
4.if exists(${.CURDIR}/../Makefile.inc)
5.include "${.CURDIR}/../Makefile.inc"
6.endif
7
8.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
9
10CFLAGS+=${COPTS} ${DEBUG_FLAGS}
11.if defined(DESTDIR)
12CFLAGS+= -I${DESTDIR}/usr/include
13CXXINCLUDES+= -I${DESTDIR}/usr/include/${CXX}
14.endif
15
16.if !defined(DEBUG_FLAGS)
17STRIP?=	-s
18.endif
19
20.if defined(NOSHARED)
21LDFLAGS+= -static
22.endif
23
24.if defined(DESTDIR)
25LDDESTDIR?=	-L${DESTDIR}${SHLIBDIR} -L${DESTDIR}/usr/lib
26# LDDESTDIR+=	-nostdlib
27.endif
28
29# XXX obsolescent.
30.include <bsd.libnames.mk>
31
32.if defined(PROG)
33.if defined(SRCS)
34
35DPSRCS+= ${SRCS:M*.h}
36OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
37
38.if defined(LDONLY)
39
40# XXX is this used?  -static in ${LDFLAGS} can't be passed here.
41${PROG}: ${DPSRCS} ${OBJS}
42	${LD} ${LDFLAGS} -o ${.TARGET} ${LIBCRT0} ${OBJS} ${LIBC} ${LDDESTDIR} \
43		${LDADD}
44
45.else defined(LDONLY)
46
47${PROG}: ${DPSRCS} ${OBJS}
48	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
49
50.endif
51
52.else !defined(SRCS)
53
54SRCS=	${PROG}.c
55
56.if 0
57${PROG}: ${DPSRCS} ${SRCS}
58	${CC} ${LDFLAGS} ${CFLAGS} -o ${.TARGET} ${.CURDIR}/${SRCS} \
59		${LDDESTDIR} ${LDADD}
60
61MKDEP=	-p
62.else
63# Always make an intermediate object file because:
64# - it saves time rebuilding when only the library has changed
65# - the name of the object gets put into the executable symbol table instead of
66#   the name of a variable temporary object.
67# - it's useful to keep objects around for crunching.
68OBJS=	${PROG}.o
69${PROG}: ${DPSRCS} ${OBJS}
70	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
71.endif
72
73.endif
74
75.if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
76	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
77	!defined(MAN7) && !defined(MAN8) && !defined(NOMAN)
78MAN1=	${PROG}.1
79.endif
80.endif
81
82# XXX I think MANDEPEND is only used for groff.  It should be named more
83# generally and perhaps not be in the maninstall dependencies now it is
84# here (or does maninstall always work when nothing is made?),
85
86.MAIN: all
87all: objwarn ${PROG} all-man _SUBDIR
88
89.if !target(clean)
90clean: _SUBDIR
91	rm -f a.out Errs errs mklog ${PROG} ${OBJS} ${CLEANFILES} 
92.if defined(CLEANDIRS) && !empty(CLEANDIRS)
93	rm -rf ${CLEANDIRS}
94.endif
95.endif
96
97.if defined(PROG)
98_EXTRADEPEND:
99	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} ${LDDESTDIR} \
100	    ${LDADD}` >> ${DEPENDFILE}
101.endif
102
103.if !target(install)
104.if !target(beforeinstall)
105beforeinstall:
106.endif
107
108realinstall: beforeinstall
109.if defined(PROG)
110	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
111	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
112.endif
113.if defined(HIDEGAME)
114	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
115	    chown games:bin ${PROG})
116.endif
117.if defined(LINKS) && !empty(LINKS)
118	@set ${LINKS}; \
119	while test $$# -ge 2; do \
120		l=${DESTDIR}$$1; \
121		shift; \
122		t=${DESTDIR}$$1; \
123		shift; \
124		${ECHO} $$t -\> $$l; \
125		rm -f $$t; \
126		ln ${LN_FLAGS} $$l $$t; \
127	done; true
128.endif
129
130install: afterinstall _SUBDIR
131.if !defined(NOMAN)
132afterinstall: realinstall maninstall
133.else
134afterinstall: realinstall
135.endif
136.endif
137
138DISTRIBUTION?=	bin
139.if !target(distribute)
140distribute: _SUBDIR
141	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${DISTRIBUTION} SHARED=copies
142.endif
143
144.if !target(lint)
145lint: ${SRCS} _SUBDIR
146.if defined(PROG)
147	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
148.endif
149.endif
150
151.if defined(NOTAGS)
152tags:
153.endif
154
155.if !target(tags)
156tags: ${SRCS} _SUBDIR
157.if defined(PROG)
158	@cd ${.CURDIR} && gtags ${GTAGSFLAGS}
159.if defined(HTML)
160	@cd ${.CURDIR} && htags ${HTAGSFLAGS}
161.endif
162.endif
163.endif
164
165.if !defined(NOMAN)
166.include <bsd.man.mk>
167.elif !target(maninstall)
168maninstall:
169all-man:
170.endif
171
172.include <bsd.dep.mk>
173.include <bsd.obj.mk>
174