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