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