xref: /386bsd/usr/share/mk/bsd.prog.mk (revision a2142627)
1# $Id: $
2
3.if !defined(NOINCLUDE) && exists(${.CURDIR}/../Makefile.inc)
4.include "${.CURDIR}/../Makefile.inc"
5.endif
6
7.SUFFIXES: .out .o .c .y .l .s .9 .8 .7 .6 .5 .4 .3 .2 .1 .0
8
9.9.0 .8.0 .7.0 .6.0 .5.0 .4.0 .3.0 .2.0 .1.0:
10	nroff -mandoc ${.IMPSRC} > ${.TARGET}
11
12CFLAGS+=${COPTS} ${NONSTDINC}
13
14STRIP?=	-s
15
16BINGRP?=	bin
17BINOWN?=	bin
18BINMODE?=	555
19
20LIBCRT0?=	/usr/lib/crt0.o
21LIBC?=          /usr/lib/libc.a
22# LIBCOMPAT?=	/usr/lib/libcompat.a
23LIBCURSES?=	/usr/lib/libcurses.a
24LIBDES?=	/usr/lib/libdes.a
25LIBL?=		/usr/lib/libl.a
26LIBLN?=		/usr/lib/libln.a
27LIBKDB?=	/usr/lib/libkdb.a
28LIBKRB?=	/usr/lib/libkrb.a
29LIBM?=		/usr/lib/libm.a
30LIBMP?=		/usr/lib/libmp.a
31LIBPC?=		/usr/lib/libpc.a
32LIBPLOT?=	/usr/lib/libplot.a
33LIBRESOLV?=	/usr/lib/libresolv.a
34LIBRPC?=	/usr/lib/librpc.a
35LIBTERM?=	/usr/lib/libterm.a
36LIBUTIL?=	/usr/lib/libutil.a
37
38INCARPA?=	-I/usr/include/nonstd/arpa
39INCOLDBSD?=	-I/usr/include/nonstd/bsd
40INCLASTBSD?=	-I/usr/include/nonstd/lastbsd
41INCDB?=		-I/usr/include/nonstd/db
42INCDEV?=	-I/usr/include/nonstd/dev
43INCFS?=		-I/usr/include/nonstd/fs
44INCGNU?=	-I/usr/include/nonstd/gnu
45INCIC?=		-I/usr/include/nonstd/ic
46INCKERNEL?=	-I/usr/include/nonstd/kernel
47INCNET?=	-I/usr/include/nonstd/net
48INCSUN?=	-I/usr/include/nonstd/sun
49
50.if defined(SHAREDSTRINGS)
51CLEANFILES+=strings
52.c.o:
53	${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
54	@${CC} ${CFLAGS} -c x.c -o ${.TARGET}
55	@rm -f x.c
56.endif
57
58.if defined(PROG)
59.if defined(SRCS)
60
61OBJS+=  ${SRCS:R:S/$/.o/g}
62
63.if defined(LDONLY)
64
65${PROG}: ${LIBCRT0} ${LIBC} ${OBJS} ${DPADD}
66	${LD} ${LDFLAGS} -o ${.TARGET} ${LIBCRT0} ${OBJS} ${LIBC} ${LDADD}
67
68.else defined(LDONLY)
69
70${PROG}: ${OBJS} ${LIBC} ${DPADD}
71	${CC} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
72
73.endif
74
75.else defined(PROG)
76
77SRCS= ${PROG}.c
78
79${PROG}: ${SRCS} ${LIBC} ${DPADD}
80	${CC} ${CFLAGS} -o ${.TARGET} ${.CURDIR}/${SRCS} ${LDADD}
81
82MKDEP=	-p
83
84.endif
85
86.if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
87	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
88	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
89	!defined(NOMAN)
90MAN1=	${PROG}.0
91.endif
92.endif
93MANALL=	${MAN1} ${MAN2} ${MAN3} ${MAN4} ${MAN5} ${MAN6} ${MAN7} ${MAN8} ${MAN9}
94
95_PROGSUBDIR: .USE
96.if defined(SUBDIR) && !empty(SUBDIR)
97	@for entry in ${SUBDIR}; do \
98		(echo "===> $$entry"; \
99		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
100			cd ${.CURDIR}/$${entry}.${MACHINE}; \
101		else \
102			cd ${.CURDIR}/$${entry}; \
103		fi; \
104		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/}); \
105	done
106.endif
107
108.MAIN: all
109all: ${PROG} ${MANALL} _PROGSUBDIR
110
111.if !target(clean)
112clean: _PROGSUBDIR
113	rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES} ${MANALL}
114.endif
115
116.if !target(cleandir)
117cleandir: _PROGSUBDIR
118	rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
119	rm -f .depend ${MANALL}
120.endif
121
122# some of the rules involve .h sources, so remove them from mkdep line
123.if !target(depend)
124depend: .depend _PROGSUBDIR
125.depend: ${SRCS}
126.if defined(PROG)
127	mkdep ${MKDEP} ${CFLAGS:M-[ID]*} ${.ALLSRC:M*.c}
128.endif
129.endif
130
131.if !target(install)
132.if !target(beforeinstall)
133beforeinstall:
134.endif
135.if !target(afterinstall)
136afterinstall:
137.endif
138
139realinstall: _PROGSUBDIR
140.if defined(PROG)
141	install ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
142	    ${PROG} ${DESTDIR}${BINDIR}
143.endif
144.if defined(HIDEGAME)
145	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
146	    chown games.bin ${PROG})
147.endif
148.if defined(LINKS) && !empty(LINKS)
149	@set ${LINKS}; \
150	while test $$# -ge 2; do \
151		l=${DESTDIR}$$1; \
152		shift; \
153		t=${DESTDIR}$$1; \
154		shift; \
155		echo $$t -\> $$l; \
156		rm -f $$t; \
157		ln $$l $$t; \
158	done; true
159.endif
160
161install: maninstall
162maninstall: afterinstall
163afterinstall: realinstall
164realinstall: beforeinstall
165.endif
166
167.if !target(lint)
168lint: ${SRCS} _PROGSUBDIR
169.if defined(PROG)
170	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
171.endif
172.endif
173
174.if !target(obj)
175.if defined(NOOBJ)
176obj: _PROGSUBDIR
177.else
178obj: _PROGSUBDIR
179	@cd ${.CURDIR}; rm -rf obj; \
180	here=`pwd`; dest=/usr/obj/`echo $$here | sed 's,/usr/src/,,'`; \
181	echo "$$here -> $$dest"; ln -s $$dest obj; \
182	if test -d /usr/obj -a ! -d $$dest; then \
183		mkdir -p $$dest; \
184	else \
185		true; \
186	fi;
187.endif
188.endif
189
190.if !target(tags)
191tags: ${SRCS} _PROGSUBDIR
192.if defined(PROG)
193	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
194	    sed "s;\${.CURDIR}/;;" > tags
195.endif
196.endif
197
198.if !defined(NOMAN)
199.include <bsd.man.mk>
200.endif
201