bsd.prog.mk revision 114580
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD: head/share/mk/bsd.prog.mk 114580 2003-05-03 15:48:12Z markm $
3
4.include <bsd.init.mk>
5
6.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
7
8CFLAGS+=${COPTS} ${DEBUG_FLAGS}
9
10.if !defined(DEBUG_FLAGS)
11STRIP?=	-s
12.endif
13
14.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
15LDFLAGS+= -static
16.endif
17
18.if defined(PROG_CXX)
19PROG=	${PROG_CXX}
20.endif
21
22.if defined(PROG)
23.if defined(SRCS)
24
25# If there are Objective C sources, link with Objective C libraries.
26.if ${SRCS:M*.m} != ""
27OBJCLIBS?= -lobjc
28LDADD+=	${OBJCLIBS}
29.endif
30
31OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
32
33${PROG}: ${OBJS}
34.if defined(PROG_CXX)
35	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
36.else
37	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
38.endif
39
40.else !defined(SRCS)
41
42.if !target(${PROG})
43.if defined(PROG_CXX)
44SRCS=	${PROG}.cc
45.else
46SRCS=	${PROG}.c
47.endif
48
49# Always make an intermediate object file because:
50# - it saves time rebuilding when only the library has changed
51# - the name of the object gets put into the executable symbol table instead of
52#   the name of a variable temporary object.
53# - it's useful to keep objects around for crunching.
54OBJS=	${PROG}.o
55
56${PROG}: ${OBJS}
57.if defined(PROG_CXX)
58	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
59.else
60	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
61.endif
62.endif
63
64.endif
65
66.if	!defined(NOMAN) && !defined(MAN) && \
67	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
68	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
69	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
70	!defined(MAN1aout)
71MAN=	${PROG}.1
72MAN1=	${MAN}
73.endif
74.endif
75
76all: objwarn ${PROG} ${SCRIPTS}
77.if !defined(NOMAN)
78all: _manpages
79.endif
80
81CLEANFILES+= ${PROG} ${OBJS}
82
83.if defined(PROG)
84_EXTRADEPEND:
85	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
86.if defined(PROG_CXX)
87	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
88.endif
89.endif
90
91.if !target(install)
92
93_INSTALLFLAGS:=	${INSTALLFLAGS}
94.for ie in ${INSTALLFLAGS_EDIT}
95_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
96.endfor
97
98.if !target(realinstall)
99realinstall: _proginstall
100.ORDER: beforeinstall _proginstall
101_proginstall:
102.if defined(PROG)
103.if defined(PROGNAME)
104	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
105	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
106.else
107	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
108	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
109.endif
110.endif
111.endif !target(realinstall)
112
113.if defined(SCRIPTS) && !empty(SCRIPTS)
114realinstall: _scriptsinstall
115.ORDER: beforeinstall _scriptsinstall
116
117SCRIPTSDIR?=	${BINDIR}
118SCRIPTSOWN?=	${BINOWN}
119SCRIPTSGRP?=	${BINGRP}
120SCRIPTSMODE?=	${BINMODE}
121
122.for script in ${SCRIPTS}
123.if defined(SCRIPTSNAME)
124SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
125.else
126SCRIPTSNAME_${script:T}?=	${script:T:R}
127.endif
128SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
129SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
130SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
131SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
132_scriptsinstall: _SCRIPTSINS_${script:T}
133_SCRIPTSINS_${script:T}: ${script}
134	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
135	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
136	    ${.ALLSRC} \
137	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
138.endfor
139.endif
140
141NLSNAME?=	${PROG}
142.include <bsd.nls.mk>
143
144.include <bsd.files.mk>
145.include <bsd.incs.mk>
146.include <bsd.links.mk>
147
148.if !defined(NOMAN)
149realinstall: _maninstall
150.ORDER: beforeinstall _maninstall
151.endif
152
153.endif
154
155.if !target(lint)
156lint: ${SRCS:M*.c}
157.if defined(PROG)
158	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
159.endif
160.endif
161
162.if !defined(NOMAN)
163.include <bsd.man.mk>
164.endif
165
166.include <bsd.libnames.mk>
167
168.include <bsd.dep.mk>
169
170.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
171${OBJS}: ${SRCS:M*.h}
172.endif
173
174.include <bsd.obj.mk>
175
176.include <bsd.sys.mk>
177