xref: /original-bsd/share/mk/bsd.prog.mk (revision 4cda19ca)
1#	@(#)bsd.prog.mk	5.23 (Berkeley) 02/01/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 -mandoc -h ${.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(PROG)
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}
71
72_PROGSUBDIR: .USE
73.if defined(SUBDIR) && !empty(SUBDIR)
74	@for entry in ${SUBDIR}; do \
75		(echo "===> $$entry"; \
76		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
77			cd ${.CURDIR}/$${entry}.${MACHINE}; \
78		else \
79			cd ${.CURDIR}/$${entry}; \
80		fi; \
81		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/}); \
82	done
83.endif
84
85.MAIN: all
86all: ${PROG} ${MANALL} _PROGSUBDIR
87
88.if !target(clean)
89clean: _PROGSUBDIR
90	rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
91.endif
92
93.if !target(cleandir)
94cleandir: _PROGSUBDIR
95	rm -f a.out [Ee]rrs mklog core ${PROG} ${OBJS} ${CLEANFILES}
96	rm -f .depend ${.CURDIR}/tags ${MANALL}
97.endif
98
99# some of the rules involve .h sources, so remove them from mkdep line
100.if !target(depend)
101depend: .depend _PROGSUBDIR
102.depend: ${SRCS}
103.if defined(PROG)
104	mkdep ${MKDEP} ${CFLAGS:M-[ID]*} ${.ALLSRC:M*.c}
105.endif
106.endif
107
108.if !target(install)
109.if !target(beforeinstall)
110beforeinstall:
111.endif
112.if !target(afterinstall)
113afterinstall:
114.endif
115
116realinstall: _PROGSUBDIR
117.if defined(PROG)
118	install ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
119	    ${PROG} ${DESTDIR}${BINDIR}
120.endif
121.if defined(HIDEGAME)
122	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
123	    chown games.bin ${PROG})
124.endif
125.if defined(LINKS) && !empty(LINKS)
126	@set ${LINKS}; \
127	while test $$# -ge 2; do \
128		l=${DESTDIR}$$1; \
129		shift; \
130		t=${DESTDIR}$$1; \
131		shift; \
132		echo $$t -\> $$l; \
133		rm -f $$t; \
134		ln $$l $$t; \
135	done; true
136.endif
137
138install: maninstall
139maninstall: afterinstall
140afterinstall: realinstall
141realinstall: beforeinstall
142.endif
143
144.if !target(lint)
145lint: ${SRCS} _PROGSUBDIR
146.if defined(PROG)
147	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
148.endif
149.endif
150
151.if !target(obj)
152.if defined(NOOBJ)
153obj: _PROGSUBDIR
154.else
155obj: _PROGSUBDIR
156	@cd ${.CURDIR}; rm -rf obj; \
157	here=`pwd`; dest=/usr/obj/`echo $$here | sed 's,/usr/src/,,'`; \
158	echo "$$here -> $$dest"; ln -s $$dest obj; \
159	if test -d /usr/obj -a ! -d $$dest; then \
160		mkdir -p $$dest; \
161	else \
162		true; \
163	fi;
164.endif
165.endif
166
167.if !target(tags)
168tags: ${SRCS} _PROGSUBDIR
169.if defined(PROG)
170	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
171	    sed "s;\${.CURDIR}/;;" > tags
172.endif
173.endif
174
175.if !defined(NOMAN)
176.include <bsd.man.mk>
177.endif
178