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