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