bsd.prog.mk revision 75083
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD: head/share/mk/bsd.prog.mk 75083 2001-04-02 11:44:20Z ru $
3
4.if !target(__initialized__)
5__initialized__:
6.if exists(${.CURDIR}/../Makefile.inc)
7.include "${.CURDIR}/../Makefile.inc"
8.endif
9.endif
10
11.SUFFIXES: .out .o .c .cc .cpp .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(NOMAN) && !defined(MAN) && \
60	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
61	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
62	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
63	!defined(MAN1aout)
64MAN=	${PROG}.1
65MAN1=	${MAN}
66.endif
67.endif
68
69.MAIN: all
70.if !defined(NOMAN)
71all: objwarn ${PROG} all-man _SUBDIR
72.else
73all: objwarn ${PROG} _SUBDIR
74.endif
75
76CLEANFILES+= ${PROG} ${OBJS}
77
78.if defined(PROG)
79_EXTRADEPEND:
80.if ${OBJFORMAT} == aout
81	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} ${LDDESTDIR} \
82	    ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
83.else
84	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
85.endif
86.endif
87
88.if !target(install)
89.if !target(beforeinstall)
90beforeinstall:
91.endif
92
93_INSTALLFLAGS:=	${INSTALLFLAGS}
94.for ie in ${INSTALLFLAGS_EDIT}
95_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
96.endfor
97
98realinstall: beforeinstall
99.if defined(PROG)
100.if defined(PROGNAME)
101	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
102	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
103.else
104	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
105	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
106.endif
107.endif
108.if defined(HIDEGAME)
109	(cd ${DESTDIR}/${GBINDIR}; rm -f ${PROG}; ln -s dm ${PROG}; \
110	    chown games:bin ${PROG})
111.endif
112.if defined(LINKS) && !empty(LINKS)
113	@set ${LINKS}; \
114	while test $$# -ge 2; do \
115		l=${DESTDIR}$$1; \
116		shift; \
117		t=${DESTDIR}$$1; \
118		shift; \
119		${ECHO} $$t -\> $$l; \
120		ln -f $$l $$t; \
121	done; true
122.endif
123.if defined(SYMLINKS) && !empty(SYMLINKS)
124	@set ${SYMLINKS}; \
125	while test $$# -ge 2; do \
126		l=$$1; \
127		shift; \
128		t=${DESTDIR}$$1; \
129		shift; \
130		${ECHO} $$t -\> $$l; \
131		ln -fs $$l $$t; \
132	done; true
133.endif
134
135install: afterinstall _SUBDIR
136.if !defined(NOMAN)
137afterinstall: realinstall maninstall
138.else
139afterinstall: realinstall
140.endif
141.endif
142
143DISTRIBUTION?=	bin
144.if !target(distribute)
145distribute: _SUBDIR
146.for dist in ${DISTRIBUTION}
147	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
148.endfor
149.endif
150
151.if !target(lint)
152lint: ${SRCS} _SUBDIR
153.if defined(PROG)
154	@${LINT} ${LINTFLAGS} ${CFLAGS} ${.ALLSRC} | more 2>&1
155.endif
156.endif
157
158.if defined(NOTAGS)
159tags:
160.endif
161
162.if !target(tags)
163tags: ${SRCS} _SUBDIR
164.if defined(PROG)
165	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
166.if defined(HTML)
167	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
168.endif
169.endif
170.endif
171
172.if !defined(NOMAN)
173.include <bsd.man.mk>
174.else
175.if !target(all-man)
176all-man:
177.endif
178.if !target(maninstall)
179maninstall:
180.endif
181.endif
182
183.if !target(regress)
184regress:
185.endif
186
187.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
188.include <bsd.libnames.mk>
189.endif
190
191.include <bsd.dep.mk>
192
193.if defined(PROG) && !exists(${DEPENDFILE})
194${OBJS}: ${SRCS:M*.h}
195.endif
196
197.include <bsd.obj.mk>
198