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