xref: /freebsd/share/mk/bsd.prog.mk (revision 298cf604ccf133b101c6fad42d1a078a1fac58ca)
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD$
3
4.include <bsd.init.mk>
5
6.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
7
8# XXX The use of COPTS in modern makefiles is discouraged.
9.if defined(COPTS)
10CFLAGS+=${COPTS}
11.endif
12
13.if ${MK_ASSERT_DEBUG} == "no"
14CFLAGS+= -DNDEBUG
15NO_WERROR=
16.endif
17
18.if defined(DEBUG_FLAGS)
19CFLAGS+=${DEBUG_FLAGS}
20CXXFLAGS+=${DEBUG_FLAGS}
21
22.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
23CTFFLAGS+= -g
24.endif
25.endif
26
27.if defined(CRUNCH_CFLAGS)
28CFLAGS+=${CRUNCH_CFLAGS}
29.endif
30
31.if !defined(DEBUG_FLAGS)
32STRIP?=	-s
33.endif
34
35.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
36LDFLAGS+= -static
37.endif
38
39.if defined(PROG_CXX)
40PROG=	${PROG_CXX}
41.endif
42
43.if defined(PROG)
44.if defined(SRCS)
45
46OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
47
48.if target(beforelinking)
49${PROG}: beforelinking
50.endif
51${PROG}: ${OBJS}
52.if defined(PROG_CXX)
53	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
54.else
55	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
56.endif
57.if ${MK_CTF} != "no"
58	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
59.endif
60
61.else	# !defined(SRCS)
62
63.if !target(${PROG})
64.if defined(PROG_CXX)
65SRCS=	${PROG}.cc
66.else
67SRCS=	${PROG}.c
68.endif
69
70# Always make an intermediate object file because:
71# - it saves time rebuilding when only the library has changed
72# - the name of the object gets put into the executable symbol table instead of
73#   the name of a variable temporary object.
74# - it's useful to keep objects around for crunching.
75OBJS=	${PROG}.o
76
77.if target(beforelinking)
78${PROG}: beforelinking
79.endif
80${PROG}: ${OBJS}
81.if defined(PROG_CXX)
82	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
83.else
84	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
85.endif
86.if ${MK_CTF} != "no"
87	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
88.endif
89.endif
90
91.endif # !defined(SRCS)
92
93.if	${MK_MAN} != "no" && !defined(MAN) && \
94	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
95	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
96	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
97	!defined(MAN1aout)
98MAN=	${PROG}.1
99MAN1=	${MAN}
100.endif
101.endif # defined(PROG)
102
103all: objwarn ${PROG} ${SCRIPTS}
104.if ${MK_MAN} != "no"
105all: _manpages
106.endif
107
108.if defined(PROG)
109CLEANFILES+= ${PROG}
110.endif
111
112.if defined(OBJS)
113CLEANFILES+= ${OBJS}
114.endif
115
116.include <bsd.libnames.mk>
117
118.if defined(PROG)
119_EXTRADEPEND:
120.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
121.if defined(DPADD) && !empty(DPADD)
122	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
123.endif
124.else
125	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
126.if defined(PROG_CXX)
127.if !empty(CXXFLAGS:M-stdlib=libc++)
128	echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
129.else
130	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
131.endif
132.endif
133.endif
134.endif
135
136.if !target(install)
137
138.if defined(PRECIOUSPROG)
139.if !defined(NO_FSCHG)
140INSTALLFLAGS+= -fschg
141.endif
142INSTALLFLAGS+= -S
143.endif
144
145_INSTALLFLAGS:=	${INSTALLFLAGS}
146.for ie in ${INSTALLFLAGS_EDIT}
147_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
148.endfor
149
150.if !target(realinstall) && !defined(INTERNALPROG)
151realinstall: _proginstall
152.ORDER: beforeinstall _proginstall
153_proginstall:
154.if defined(PROG)
155.if defined(PROGNAME)
156	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
157	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
158.else
159	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
160	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
161.endif
162.endif
163.endif	# !target(realinstall)
164
165.if defined(SCRIPTS) && !empty(SCRIPTS)
166realinstall: _scriptsinstall
167.ORDER: beforeinstall _scriptsinstall
168
169SCRIPTSDIR?=	${BINDIR}
170SCRIPTSOWN?=	${BINOWN}
171SCRIPTSGRP?=	${BINGRP}
172SCRIPTSMODE?=	${BINMODE}
173
174.for script in ${SCRIPTS}
175.if defined(SCRIPTSNAME)
176SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
177.else
178SCRIPTSNAME_${script:T}?=	${script:T:R}
179.endif
180SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
181SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
182SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
183SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
184_scriptsinstall: _SCRIPTSINS_${script:T}
185_SCRIPTSINS_${script:T}: ${script}
186	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
187	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
188	    ${.ALLSRC} \
189	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
190.endfor
191.endif
192
193NLSNAME?=	${PROG}
194.include <bsd.nls.mk>
195
196.include <bsd.files.mk>
197.include <bsd.incs.mk>
198.include <bsd.links.mk>
199
200.if ${MK_MAN} != "no"
201realinstall: _maninstall
202.ORDER: beforeinstall _maninstall
203.endif
204
205.endif
206
207.if !target(lint)
208lint: ${SRCS:M*.c}
209.if defined(PROG)
210	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
211.endif
212.endif
213
214.if ${MK_MAN} != "no"
215.include <bsd.man.mk>
216.endif
217
218.include <bsd.dep.mk>
219
220.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
221${OBJS}: ${SRCS:M*.h}
222.endif
223
224.include <bsd.obj.mk>
225
226.include <bsd.sys.mk>
227
228.if defined(PORTNAME)
229.include <bsd.pkg.mk>
230.endif
231