bsd.prog.mk revision 6031
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.prog.mk,v 1.20 1995/01/25 20:24:01 ache 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
20BINGRP?=	bin
21BINOWN?=	bin
22BINMODE?=	555
23
24LIBCRT0?=	${DESTDIR}/usr/lib/crt0.o
25LIBC?=		${DESTDIR}/usr/lib/libc.a
26LIBCOMPAT?=	${DESTDIR}/usr/lib/libcompat.a
27LIBCRYPT?=	${DESTDIR}/usr/lib/libcrypt.a
28LIBCURSES?=	${DESTDIR}/usr/lib/libcurses.a
29LIBDES?=	${DESTDIR}/usr/lib/libdes.a	# XXX doesn't exist
30LIBDIALOG?=	${DESTDIR}/usr/lib/libdialog.a
31LIBEDIT?=	${DESTDIR}/usr/lib/libedit.a
32LIBFORMS?=	${DESTDIR}/usr/lib/libforms.a
33LIBGCC?=	${DESTDIR}/usr/lib/libgcc.a
34LIBGNUMALLOC?=	${DESTDIR}/usr/lib/libgnumalloc.a
35LIBGNUREGEX?=	${DESTDIR}/usr/lib/libgnuregex.a
36LIBKDB?=	${DESTDIR}/usr/lib/libkdb.a	# XXX doesn't exist
37LIBKRB?=	${DESTDIR}/usr/lib/libkrb.a	# XXX doesn't exist
38LIBKVM?=	${DESTDIR}/usr/lib/libkvm.a
39LIBL?=		${DESTDIR}/usr/lib/libl.a
40LIBM?=		${DESTDIR}/usr/lib/libm.a
41LIBMD?=		${DESTDIR}/usr/lib/libmd.a
42LIBMP?=		${DESTDIR}/usr/lib/libmp.a	# XXX doesn't exist
43LIBMYTINFO?=	${DESTDIR}/usr/lib/libmytinfo.a
44LIBNCURSES?=	${DESTDIR}/usr/lib/libncurses.a
45LIBPC?=		${DESTDIR}/usr/lib/libpc.a	# XXX doesn't exist
46LIBPLOT?=	${DESTDIR}/usr/lib/libplot.a	# XXX doesn't exist
47LIBREADLINE?=	${DESTDIR}/usr/lib/libreadline.a
48LIBRESOLV?=	${DESTDIR}/usr/lib/libresolv.a
49LIBRPCSVC?=	${DESTDIR}/usr/lib/librpcsvc.a
50LIBSCRYPT?=	${DESTDIR}/usr/lib/libscrypt.a	# XXX don't use, use LIBCRYPT
51LIBSCSI?=	${DESTDIR}/usr/lib/libscsi.a
52LIBSKEY?=	${DESTDIR}/usr/lib/libskey.a
53LIBTELNET?=	${DESTDIR}/usr/lib/libtelnet.a
54LIBTERMCAP?=	${DESTDIR}/usr/lib/libtermcap.a
55LIBUTIL?=	${DESTDIR}/usr/lib/libutil.a
56LIBY?=		${DESTDIR}/usr/lib/liby.a
57
58.if defined(NOSHARED)
59LDFLAGS+= -static
60.endif
61
62.if defined(DESTDIR)
63LDDESTDIR+=	-L${DESTDIR}/usr/lib
64.endif
65
66.if defined(PROG)
67.if defined(SRCS)
68
69DPSRCS+= ${SRCS:M*.h}
70.if !defined(NOOBJ)
71OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
72.endif
73
74.if defined(LDONLY)
75
76${PROG}: ${LIBCRT0} ${LIBC} ${DPSRCS} ${OBJS} ${DPADD} 
77	${LD} ${LDFLAGS} -o ${.TARGET} ${LIBCRT0} ${OBJS} ${LIBC} ${LDDESTDIR} \
78		${LDADD}
79
80.else defined(LDONLY)
81
82${PROG}: ${DPSRCS} ${OBJS} ${LIBC} ${DPADD}
83	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
84
85.endif
86
87.else defined(PROG)
88
89SRCS=	${PROG}.c
90
91.if 0
92${PROG}: ${DPSRCS} ${SRCS} ${LIBC} ${DPADD}
93	${CC} ${LDFLAGS} ${CFLAGS} -o ${.TARGET} ${.CURDIR}/${SRCS} \
94		${LDDESTDIR} ${LDADD}
95
96MKDEP=	-p
97.else
98# Always make an intermediate object file because:
99# - it saves time rebuilding when only the library has changed
100# - the name of the object gets put into the executable symbol table instead of
101#   the name of a variable temporary object.
102# - it's useful to keep objects around for crunching.
103OBJS=	${PROG}.o
104${PROG}: ${DPSRCS} ${OBJS} ${LIBC} ${DPADD}
105	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
106.endif
107
108.endif
109
110.if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
111	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
112	!defined(MAN7) && !defined(MAN8) && !defined(NOMAN)
113MAN1=	${PROG}.1
114.endif
115.endif
116
117_PROGSUBDIR: .USE
118.if defined(SUBDIR) && !empty(SUBDIR)
119	@for entry in ${SUBDIR}; do \
120		(${ECHODIR} "===> ${DIRPRFX}$$entry"; \
121		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
122			cd ${.CURDIR}/$${entry}.${MACHINE}; \
123		else \
124			cd ${.CURDIR}/$${entry}; \
125		fi; \
126		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/} DIRPRFX=${DIRPRFX}$$entry/); \
127	done
128.endif
129
130.MAIN: all
131all: ${PROG} _PROGSUBDIR
132
133.if !target(clean)
134clean: _PROGSUBDIR
135	rm -f a.out [Ee]rrs mklog ${PROG} ${OBJS} ${CLEANFILES} 
136.endif
137
138.if !target(cleandir)
139cleandir: _PROGSUBDIR
140	rm -f a.out [Ee]rrs mklog ${PROG} ${OBJS} ${CLEANFILES}
141	rm -f ${.CURDIR}/tags .depend
142	cd ${.CURDIR}; rm -rf obj;
143.endif
144
145.if !target(install)
146.if !target(beforeinstall)
147beforeinstall:
148.endif
149.if !target(afterinstall)
150afterinstall:
151.endif
152
153realinstall: _PROGSUBDIR
154.if defined(PROG)
155	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
156	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
157.endif
158.if defined(HIDEGAME)
159	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
160	    chown games.bin ${PROG})
161.endif
162.if defined(LINKS) && !empty(LINKS)
163	@set ${LINKS}; \
164	while test $$# -ge 2; do \
165		l=${DESTDIR}$$1; \
166		shift; \
167		t=${DESTDIR}$$1; \
168		shift; \
169		${ECHO} $$t -\> $$l; \
170		rm -f $$t; \
171		ln ${LN_FLAGS} $$l $$t; \
172	done; true
173.endif
174
175install: afterinstall
176.if !defined(NOMAN)
177afterinstall: realinstall maninstall
178.else
179afterinstall: realinstall
180.endif
181realinstall: beforeinstall
182.endif
183
184DISTRIBUTION?=	bin
185.if !target(distribute)
186distribute:
187	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${RELEASEDIR}/${DISTRIBUTION} SHARED=copies
188.endif
189
190.if !target(lint)
191lint: ${SRCS} _PROGSUBDIR
192.if defined(PROG)
193	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
194.endif
195.endif
196
197.if !target(obj)
198.if defined(NOOBJ)
199obj: _PROGSUBDIR
200.else
201obj: _PROGSUBDIR
202	@cd ${.CURDIR}; rm -rf obj; \
203	here=`pwd`; dest=/usr/obj`echo $$here | sed 's,^/usr/src,,'`; \
204	${ECHO} "$$here -> $$dest"; ln -s $$dest obj; \
205	if test -d /usr/obj -a ! -d $$dest; then \
206		mkdir -p $$dest; \
207	else \
208		true; \
209	fi;
210.endif
211.endif
212
213.if !target(tags)
214tags: ${SRCS} _PROGSUBDIR
215.if defined(PROG)
216	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
217	    sed "s;\${.CURDIR}/;;" > tags
218.endif
219.endif
220
221.if !defined(NOMAN)
222.include <bsd.man.mk>
223.elif !target(maninstall)
224maninstall:
225.endif
226
227.include <bsd.dep.mk>
228