bsd.prog.mk revision 2676
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.prog.mk,v 1.4 1994/08/28 15:32:10 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}
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
45LIBTERMCAP?=	/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
69LIBTERMCAP?=	${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} ${LDDESTDIR} \
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.if 0
118${PROG}: ${DPSRCS} ${SRCS} ${LIBC} ${DPADD}
119	${CC} ${LDFLAGS} ${CFLAGS} -o ${.TARGET} ${.CURDIR}/${SRCS} \
120		${LDDESTDIR} ${LDADD}
121.else
122# Always make an intermediate object file because:
123# - it saves time rebuilding when only the library has changed
124# - the name of the object gets put into the executable symbol table instead of
125#   the name of a variable temporary object.
126# - it's useful to keep objects around for crunching.
127OBJS=	${PROG}.o
128${PROG}: ${DPSRCS} ${OBJS} ${LIBC} ${DPADD}
129	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
130.endif
131
132MKDEP=	-p
133
134.endif
135
136.if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
137	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
138	!defined(MAN7) && !defined(MAN8) && !defined(NOMAN)
139MAN1=	${PROG}.1
140.endif
141.endif
142
143_PROGSUBDIR: .USE
144.if defined(SUBDIR) && !empty(SUBDIR)
145	@for entry in ${SUBDIR}; do \
146		(${ECHODIR} "===> $$entry"; \
147		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
148			cd ${.CURDIR}/$${entry}.${MACHINE}; \
149		else \
150			cd ${.CURDIR}/$${entry}; \
151		fi; \
152		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/}); \
153	done
154.endif
155
156.MAIN: all
157all: ${PROG} _PROGSUBDIR
158
159.if !target(clean)
160clean: _PROGSUBDIR
161	rm -f a.out [Ee]rrs mklog ${PROG} ${OBJS} ${CLEANFILES} 
162.endif
163
164.if !target(cleandir)
165cleandir: _PROGSUBDIR
166	rm -f a.out [Ee]rrs mklog ${PROG} ${OBJS} ${CLEANFILES}
167	rm -f ${.CURDIR}/tags .depend
168	cd ${.CURDIR}; rm -rf obj;
169.endif
170
171.if !target(install)
172.if !target(beforeinstall)
173beforeinstall:
174.endif
175.if !target(afterinstall)
176afterinstall:
177.endif
178
179realinstall: _PROGSUBDIR
180.if defined(PROG)
181	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
182	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
183.endif
184.if defined(HIDEGAME)
185	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
186	    chown games.bin ${PROG})
187.endif
188.if defined(LINKS) && !empty(LINKS)
189	@set ${LINKS}; \
190	while test $$# -ge 2; do \
191		l=${DESTDIR}$$1; \
192		shift; \
193		t=${DESTDIR}$$1; \
194		shift; \
195		${ECHO} $$t -\> $$l; \
196		rm -f $$t; \
197		ln $$l $$t; \
198	done; true
199.endif
200
201install: afterinstall
202.if !defined(NOMAN)
203afterinstall: realinstall maninstall
204.else
205afterinstall: realinstall
206.endif
207realinstall: beforeinstall
208.endif
209
210.if !target(lint)
211lint: ${SRCS} _PROGSUBDIR
212.if defined(PROG)
213	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
214.endif
215.endif
216
217.if !target(obj)
218.if defined(NOOBJ)
219obj: _PROGSUBDIR
220.else
221obj: _PROGSUBDIR
222	@cd ${.CURDIR}; rm -rf obj; \
223	here=`pwd`; dest=/usr/obj`echo $$here | sed 's,^/usr/src,,'`; \
224	${ECHO} "$$here -> $$dest"; ln -s $$dest obj; \
225	if test -d /usr/obj -a ! -d $$dest; then \
226		mkdir -p $$dest; \
227	else \
228		true; \
229	fi;
230.endif
231.endif
232
233.if !target(tags)
234tags: ${SRCS} _PROGSUBDIR
235.if defined(PROG)
236	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
237	    sed "s;\${.CURDIR}/;;" > tags
238.endif
239.endif
240
241.if !defined(NOMAN)
242.include <bsd.man.mk>
243.elif !target(maninstall)
244maninstall:
245.endif
246
247.include <bsd.dep.mk>
248