bsd.prog.mk revision 23542
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.prog.mk,v 1.44 1997/02/22 13:56:13 peter 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}/usr/lib
26.endif
27
28.include <bsd.libnames.mk>
29
30.if defined(PROG)
31.if defined(SRCS)
32
33DPSRCS+= ${SRCS:M*.h}
34OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
35
36.if defined(LDONLY)
37
38${PROG}: ${LIBCRT0} ${LIBC} ${DPSRCS} ${OBJS} ${DPADD} 
39	${LD} ${LDFLAGS} -o ${.TARGET} ${LIBCRT0} ${OBJS} ${LIBC} ${LDDESTDIR} \
40		${LDADD}
41
42.else defined(LDONLY)
43
44${PROG}: ${DPSRCS} ${OBJS} ${LIBC} ${DPADD}
45	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
46
47.endif
48
49.else !defined(SRCS)
50
51SRCS=	${PROG}.c
52
53.if 0
54${PROG}: ${DPSRCS} ${SRCS} ${LIBC} ${DPADD}
55	${CC} ${LDFLAGS} ${CFLAGS} -o ${.TARGET} ${.CURDIR}/${SRCS} \
56		${LDDESTDIR} ${LDADD}
57
58MKDEP=	-p
59.else
60# Always make an intermediate object file because:
61# - it saves time rebuilding when only the library has changed
62# - the name of the object gets put into the executable symbol table instead of
63#   the name of a variable temporary object.
64# - it's useful to keep objects around for crunching.
65OBJS=	${PROG}.o
66${PROG}: ${DPSRCS} ${OBJS} ${LIBC} ${DPADD}
67	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
68.endif
69
70.endif
71
72.if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
73	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
74	!defined(MAN7) && !defined(MAN8) && !defined(NOMAN)
75MAN1=	${PROG}.1
76.endif
77.endif
78
79# XXX I think MANDEPEND is only used for groff.  It should be named more
80# generally and perhaps not be in the maninstall dependencies now it is
81# here (or does maninstall always work when nothing is made?),
82
83.MAIN: all
84all: objwarn ${PROG} all-man _SUBDIR
85
86.if !target(clean)
87clean: _SUBDIR
88	rm -f a.out Errs errs mklog ${PROG} ${OBJS} ${CLEANFILES} 
89.if defined(CLEANDIRS) && !empty(CLEANDIRS)
90	rm -rf ${CLEANDIRS}
91.endif
92.endif
93
94.if !target(install)
95.if !target(beforeinstall)
96beforeinstall:
97.endif
98
99realinstall: beforeinstall
100.if defined(PROG)
101	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
102	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
103.endif
104.if defined(HIDEGAME)
105	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
106	    chown games:bin ${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		rm -f $$t; \
117		ln ${LN_FLAGS} $$l $$t; \
118	done; true
119.endif
120
121install: afterinstall _SUBDIR
122.if !defined(NOMAN)
123afterinstall: realinstall maninstall
124.else
125afterinstall: realinstall
126.endif
127.endif
128
129DISTRIBUTION?=	bin
130.if !target(distribute)
131distribute: _SUBDIR
132	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${DISTRIBUTION} SHARED=copies
133.endif
134
135.if !target(lint)
136lint: ${SRCS} _SUBDIR
137.if defined(PROG)
138	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
139.endif
140.endif
141
142.if !target(tags)
143tags: ${SRCS} _SUBDIR
144.if defined(PROG)
145	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
146	    sed "s;\${.CURDIR}/;;" > tags
147.endif
148.endif
149
150.if !defined(NOMAN)
151.include <bsd.man.mk>
152.elif !target(maninstall)
153maninstall:
154all-man:
155.endif
156
157.include <bsd.dep.mk>
158.include <bsd.obj.mk>
159