xref: /freebsd/share/mk/bsd.prog.mk (revision 17ee9d00bc1ae1e598c38f25826f861e4bc6c3ce)
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.prog.mk,v 1.21 1995/01/30 07:20:01 jkh 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# XXX I think MANDEPEND is only used for groff.  It should be named more
131# generally and perhaps not be in the maninstall dependencies now it is
132# here (or does maninstall always work when nothing is made?),
133
134.MAIN: all
135all: ${PROG} ${MANDEPEND} _PROGSUBDIR
136
137.if !target(clean)
138clean: _PROGSUBDIR
139	rm -f a.out [Ee]rrs mklog ${PROG} ${OBJS} ${CLEANFILES}
140.endif
141
142.if !target(cleandir)
143cleandir: _PROGSUBDIR
144	rm -f a.out [Ee]rrs mklog ${PROG} ${OBJS} ${CLEANFILES}
145	rm -f ${.CURDIR}/tags .depend
146	cd ${.CURDIR}; rm -rf obj;
147.endif
148
149.if !target(install)
150.if !target(beforeinstall)
151beforeinstall:
152.endif
153.if !target(afterinstall)
154afterinstall:
155.endif
156
157realinstall: _PROGSUBDIR
158.if defined(PROG)
159	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
160	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
161.endif
162.if defined(HIDEGAME)
163	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
164	    chown games.bin ${PROG})
165.endif
166.if defined(LINKS) && !empty(LINKS)
167	@set ${LINKS}; \
168	while test $$# -ge 2; do \
169		l=${DESTDIR}$$1; \
170		shift; \
171		t=${DESTDIR}$$1; \
172		shift; \
173		${ECHO} $$t -\> $$l; \
174		rm -f $$t; \
175		ln ${LN_FLAGS} $$l $$t; \
176	done; true
177.endif
178
179install: afterinstall
180.if !defined(NOMAN)
181afterinstall: realinstall maninstall
182.else
183afterinstall: realinstall
184.endif
185realinstall: beforeinstall
186.endif
187
188DISTRIBUTION?=	bin
189.if !target(distribute)
190distribute:
191	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${RELEASEDIR}/${DISTRIBUTION} SHARED=copies
192.endif
193
194.if !target(lint)
195lint: ${SRCS} _PROGSUBDIR
196.if defined(PROG)
197	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
198.endif
199.endif
200
201.if !target(obj)
202.if defined(NOOBJ)
203obj: _PROGSUBDIR
204.else
205obj: _PROGSUBDIR
206	@cd ${.CURDIR}; rm -rf obj; \
207	here=`pwd`; dest=/usr/obj`echo $$here | sed 's,^/usr/src,,'`; \
208	${ECHO} "$$here -> $$dest"; ln -s $$dest obj; \
209	if test -d /usr/obj -a ! -d $$dest; then \
210		mkdir -p $$dest; \
211	else \
212		true; \
213	fi;
214.endif
215.endif
216
217.if !target(tags)
218tags: ${SRCS} _PROGSUBDIR
219.if defined(PROG)
220	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
221	    sed "s;\${.CURDIR}/;;" > tags
222.endif
223.endif
224
225.if !defined(NOMAN)
226.include <bsd.man.mk>
227.elif !target(maninstall)
228maninstall:
229.endif
230
231_DEPSUBDIR=	_PROGSUBDIR
232.include <bsd.dep.mk>
233