bsd.prog.mk revision 36055
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.prog.mk,v 1.73 1998/05/15 09:30:12 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 .m .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
30# If there are Objective C sources, link with Objective C libraries.
31.if ${SRCS:M*.m} != ""
32OBJCLIBS?= -lobjc
33LDADD+=	${OBJCLIBS}
34.endif
35
36OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
37
38${PROG}: ${OBJS}
39	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
40
41.else !defined(SRCS)
42
43.if !target(${PROG})
44SRCS=	${PROG}.c
45
46# Always make an intermediate object file because:
47# - it saves time rebuilding when only the library has changed
48# - the name of the object gets put into the executable symbol table instead of
49#   the name of a variable temporary object.
50# - it's useful to keep objects around for crunching.
51OBJS=	${PROG}.o
52
53${PROG}: ${OBJS}
54	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
55.endif
56
57.endif
58
59.if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
60	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
61	!defined(MAN7) && !defined(MAN8) && !defined(NOMAN)
62MAN1=	${PROG}.1
63.endif
64.endif
65
66.MAIN: all
67all: objwarn ${PROG} all-man _SUBDIR
68
69CLEANFILES+= ${PROG} ${OBJS}
70
71.if defined(PROG) && !defined(NOEXTRADEPEND)
72_EXTRADEPEND:
73.if ${BINFORMAT} == aout
74	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} ${LDDESTDIR} \
75	    ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
76.else
77.if defined(DPADD) && !empty(DPADD)
78	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
79.endif
80.endif
81.endif
82
83.if !target(install)
84.if !target(beforeinstall)
85beforeinstall:
86.endif
87
88realinstall: beforeinstall
89.if defined(PROG)
90	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
91	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
92.endif
93.if defined(HIDEGAME)
94	(cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG}; \
95	    chown games:bin ${PROG})
96.endif
97.if defined(LINKS) && !empty(LINKS)
98	@set ${LINKS}; \
99	while test $$# -ge 2; do \
100		l=${DESTDIR}$$1; \
101		shift; \
102		t=${DESTDIR}$$1; \
103		shift; \
104		${ECHO} $$t -\> $$l; \
105		rm -f $$t; \
106		ln ${LN_FLAGS} $$l $$t; \
107	done; true
108.endif
109
110install: afterinstall _SUBDIR
111.if !defined(NOMAN)
112afterinstall: realinstall maninstall
113.else
114afterinstall: realinstall
115.endif
116.endif
117
118DISTRIBUTION?=	bin
119.if !target(distribute)
120distribute: _SUBDIR
121.for dist in ${DISTRIBUTION}
122	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
123.endfor
124.endif
125
126.if !target(lint)
127lint: ${SRCS} _SUBDIR
128.if defined(PROG)
129	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
130.endif
131.endif
132
133.if defined(NOTAGS)
134tags:
135.endif
136
137.if !target(tags)
138tags: ${SRCS} _SUBDIR
139.if defined(PROG)
140	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
141.if defined(HTML)
142	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
143.endif
144.endif
145.endif
146
147.if !defined(NOMAN)
148.include <bsd.man.mk>
149.elif !target(maninstall)
150maninstall:
151all-man:
152.endif
153
154.if !target(regress)
155regress:
156.endif
157
158.if ${BINFORMAT} != aout || make(checkdpadd)
159.include <bsd.libnames.mk>
160.endif
161
162.include <bsd.dep.mk>
163
164.if defined(PROG) && !exists(${DEPENDFILE})
165${OBJS}: ${SRCS:M*.h}
166.endif
167
168.include <bsd.obj.mk>
169