bsd.prog.mk revision 35695
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.prog.mk,v 1.68 1998/05/04 13:54:41 bde Exp $
3
4.if exists(${.CURDIR}/../Makefile.inc)
5.include "${.CURDIR}/../Makefile.inc"
6.endif
7
8# Default executable format
9BINFORMAT?=	aout
10
11.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
12
13CFLAGS+=${COPTS} ${DEBUG_FLAGS}
14.if defined(DESTDIR)
15CFLAGS+= -I${DESTDIR}/usr/include
16CXXINCLUDES+= -I${DESTDIR}/usr/include/g++
17.endif
18
19.if !defined(DEBUG_FLAGS)
20STRIP?=	-s
21.endif
22
23.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
24LDFLAGS+= -static
25.endif
26
27.if defined(PROG)
28.if defined(SRCS)
29
30CLEANFILES?=
31
32.for _LSRC in ${SRCS:M*.l}
33.for _LC in ${_LSRC:S/.l/.c/}
34${_LC}: ${_LSRC}
35	${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
36SRCS:=	${SRCS:S/${_LSRC}/${_LC}/}
37CLEANFILES:= ${CLEANFILES} ${_LC}
38.endfor
39.endfor
40
41.for _YSRC in ${SRCS:M*.y}
42.for _YC in ${_YSRC:S/.y/.c/}
43.for _YH in ${_YSRC:S/.y/.h/}
44.ORDER: ${_YC} ${_YH}
45${_YC} ${_YH}: ${_YSRC}
46	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
47SRCS:=	${SRCS:S/${_YSRC}/${_YC}/}
48CLEANFILES:= ${CLEANFILES} ${_YC}
49.if ${YFLAGS:M-d} != ""
50y.tab.h:
51	ln -sf ${_YH} ${.TARGET}
52SRCS:=	${SRCS} y.tab.h
53CLEANFILES:= ${CLEANFILES} ${_YH} y.tab.h
54.endif
55.endfor
56.endfor
57.endfor
58
59OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
60
61${PROG}: ${OBJS}
62	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
63
64.else !defined(SRCS)
65
66.if !target(${PROG})
67SRCS=	${PROG}.c
68
69# Always make an intermediate object file because:
70# - it saves time rebuilding when only the library has changed
71# - the name of the object gets put into the executable symbol table instead of
72#   the name of a variable temporary object.
73# - it's useful to keep objects around for crunching.
74OBJS=	${PROG}.o
75
76${PROG}: ${OBJS}
77	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
78.endif
79
80.endif
81
82.if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
83	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
84	!defined(MAN7) && !defined(MAN8) && !defined(NOMAN)
85MAN1=	${PROG}.1
86.endif
87.endif
88
89.MAIN: all
90all: objwarn ${PROG} all-man _SUBDIR
91
92CLEANFILES+= ${PROG} ${OBJS}
93
94.if defined(PROG) && !defined(NOEXTRADEPEND)
95_EXTRADEPEND:
96.if ${BINFORMAT} == aout
97	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} ${LDDESTDIR} \
98	    ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
99.else
100.if defined(DPADD) && !empty(DPADD)
101	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
102.endif
103.endif
104.endif
105
106.if !target(install)
107.if !target(beforeinstall)
108beforeinstall:
109.endif
110
111realinstall: beforeinstall
112.if defined(PROG)
113	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
114	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
115.endif
116.if defined(HIDEGAME)
117	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
118	    chown games:bin ${PROG})
119.endif
120.if defined(LINKS) && !empty(LINKS)
121	@set ${LINKS}; \
122	while test $$# -ge 2; do \
123		l=${DESTDIR}$$1; \
124		shift; \
125		t=${DESTDIR}$$1; \
126		shift; \
127		${ECHO} $$t -\> $$l; \
128		rm -f $$t; \
129		ln ${LN_FLAGS} $$l $$t; \
130	done; true
131.endif
132
133install: afterinstall _SUBDIR
134.if !defined(NOMAN)
135afterinstall: realinstall maninstall
136.else
137afterinstall: realinstall
138.endif
139.endif
140
141DISTRIBUTION?=	bin
142.if !target(distribute)
143distribute: _SUBDIR
144.for dist in ${DISTRIBUTION}
145	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
146.endfor
147.endif
148
149.if !target(lint)
150lint: ${SRCS} _SUBDIR
151.if defined(PROG)
152	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
153.endif
154.endif
155
156.if defined(NOTAGS)
157tags:
158.endif
159
160.if !target(tags)
161tags: ${SRCS} _SUBDIR
162.if defined(PROG)
163	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
164.if defined(HTML)
165	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
166.endif
167.endif
168.endif
169
170.if !defined(NOMAN)
171.include <bsd.man.mk>
172.elif !target(maninstall)
173maninstall:
174all-man:
175.endif
176
177.if !target(regress)
178regress:
179.endif
180
181.if ${BINFORMAT} != aout || make(checkdpadd)
182.include <bsd.libnames.mk>
183.endif
184
185.include <bsd.dep.mk>
186
187.if defined(PROG) && !exists(${DEPENDFILE})
188${OBJS}: ${SRCS:M*.h}
189.endif
190
191.include <bsd.obj.mk>
192