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