xref: /freebsd/share/mk/bsd.prog.mk (revision 2bdaf7e81c40bb62614080808c42c6a9208e0246)
13585b293SGarrett Wollman#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
27f3dea24SPeter Wemm# $FreeBSD$
3afe61c15SRodney W. Grimes
42bdaf7e8SRuslan Ermilov.include <bsd.init.mk>
5afe61c15SRodney W. Grimes
6c7cbe79eSDmitrij Tejblum.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .s .S
7afe61c15SRodney W. Grimes
8e82b0b99SJordan K. HubbardCFLAGS+=${COPTS} ${DEBUG_FLAGS}
9afe61c15SRodney W. Grimes
10e82b0b99SJordan K. Hubbard.if !defined(DEBUG_FLAGS)
11afe61c15SRodney W. GrimesSTRIP?=	-s
12e82b0b99SJordan K. Hubbard.endif
13afe61c15SRodney W. Grimes
143d8cd70cSPaul Traina.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
153585b293SGarrett WollmanLDFLAGS+= -static
163585b293SGarrett Wollman.endif
17afe61c15SRodney W. Grimes
1847bf8a5cSRuslan Ermilov.if defined(PROG_CXX)
1947bf8a5cSRuslan ErmilovPROG=	${PROG_CXX}
2047bf8a5cSRuslan Ermilov.endif
2147bf8a5cSRuslan Ermilov
22afe61c15SRodney W. Grimes.if defined(PROG)
23afe61c15SRodney W. Grimes.if defined(SRCS)
24afe61c15SRodney W. Grimes
2570a6e331SBruce Evans# If there are Objective C sources, link with Objective C libraries.
2670a6e331SBruce Evans.if ${SRCS:M*.m} != ""
2770a6e331SBruce EvansOBJCLIBS?= -lobjc
2870a6e331SBruce EvansLDADD+=	${OBJCLIBS}
2970a6e331SBruce Evans.endif
3070a6e331SBruce Evans
313585b293SGarrett WollmanOBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
32afe61c15SRodney W. Grimes
335d68012aSRuslan Ermilov${PROG}: ${OBJS}
345d68012aSRuslan Ermilov.if defined(PROG_CXX)
355d68012aSRuslan Ermilov	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
365d68012aSRuslan Ermilov.else
375d68012aSRuslan Ermilov	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
385d68012aSRuslan Ermilov.endif
395d68012aSRuslan Ermilov
40fd2e43eaSBruce Evans.else !defined(SRCS)
41afe61c15SRodney W. Grimes
425d68012aSRuslan Ermilov.if !target(${PROG})
4347bf8a5cSRuslan Ermilov.if defined(PROG_CXX)
4447bf8a5cSRuslan ErmilovSRCS=	${PROG}.cc
4547bf8a5cSRuslan Ermilov.else
46afe61c15SRodney W. GrimesSRCS=	${PROG}.c
4747bf8a5cSRuslan Ermilov.endif
48afe61c15SRodney W. Grimes
49a4c39c7aSBruce Evans# Always make an intermediate object file because:
50a4c39c7aSBruce Evans# - it saves time rebuilding when only the library has changed
51a4c39c7aSBruce Evans# - the name of the object gets put into the executable symbol table instead of
52a4c39c7aSBruce Evans#   the name of a variable temporary object.
53a4c39c7aSBruce Evans# - it's useful to keep objects around for crunching.
54a4c39c7aSBruce EvansOBJS=	${PROG}.o
55f5c75051SEivind Eklund
56987afe2aSBruce Evans${PROG}: ${OBJS}
57f8ba1555SRuslan Ermilov.if defined(PROG_CXX)
58f8ba1555SRuslan Ermilov	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
59f8ba1555SRuslan Ermilov.else
60de0d6977SRuslan Ermilov	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
61afe61c15SRodney W. Grimes.endif
625d68012aSRuslan Ermilov.endif
63f5c75051SEivind Eklund
646fe6af9fSEivind Eklund.endif
65afe61c15SRodney W. Grimes
66862d3deaSRuslan Ermilov.if	!defined(NOMAN) && !defined(MAN) && \
67862d3deaSRuslan Ermilov	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
68afe61c15SRodney W. Grimes	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
69500d8265SRuslan Ermilov	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
70862d3deaSRuslan Ermilov	!defined(MAN1aout)
7119ea15a1SRuslan ErmilovMAN=	${PROG}.1
7219ea15a1SRuslan ErmilovMAN1=	${MAN}
73afe61c15SRodney W. Grimes.endif
74afe61c15SRodney W. Grimes.endif
75afe61c15SRodney W. Grimes
76a7aaf57eSRuslan Ermilovall: objwarn ${PROG} ${SCRIPTS} ${FILES}
77862d3deaSRuslan Ermilov.if !defined(NOMAN)
78a7aaf57eSRuslan Ermilovall: all-man
79862d3deaSRuslan Ermilov.endif
80a7aaf57eSRuslan Ermilovall: _SUBDIR
81afe61c15SRodney W. Grimes
8289d11b8aSBruce EvansCLEANFILES+= ${PROG} ${OBJS}
83afe61c15SRodney W. Grimes
84218a2cd2SBruce Evans.if defined(PROG)
85663e9677SBruce Evans_EXTRADEPEND:
86cdaa52cfSJohn Birrell.if ${OBJFORMAT} == aout
87de0d6977SRuslan Ermilov	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} \
881c735bb4SBruce Evans	    ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
898c05a446SPeter Wemm.else
906e19760bSBruce Evans	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
91f8ba1555SRuslan Ermilov.if defined(PROG_CXX)
92f8ba1555SRuslan Ermilov	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
93f8ba1555SRuslan Ermilov.endif
948c05a446SPeter Wemm.endif
95663e9677SBruce Evans.endif
96663e9677SBruce Evans
97afe61c15SRodney W. Grimes.if !target(install)
98afe61c15SRodney W. Grimes.if !target(beforeinstall)
99afe61c15SRodney W. Grimesbeforeinstall:
100afe61c15SRodney W. Grimes.endif
101afe61c15SRodney W. Grimes
102e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${INSTALLFLAGS}
103e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT}
104e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
105e902c1bbSTim Vanderhoek.endfor
106e902c1bbSTim Vanderhoek
107cd9a2f5cSJordan K. Hubbardrealinstall: beforeinstall
108afe61c15SRodney W. Grimes.if defined(PROG)
10995f8c826SRuslan Ermilov.if defined(PROGNAME)
11095f8c826SRuslan Ermilov	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
11195f8c826SRuslan Ermilov	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
11295f8c826SRuslan Ermilov.else
1133585b293SGarrett Wollman	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
114e902c1bbSTim Vanderhoek	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
115afe61c15SRodney W. Grimes.endif
11695f8c826SRuslan Ermilov.endif
117afe61c15SRodney W. Grimes.if defined(HIDEGAME)
118dfcf88a3SRuslan Ermilov	(cd ${DESTDIR}${ORIGBINDIR}; ln -fs dm ${PROG}; \
119dfcf88a3SRuslan Ermilov	    chown -h ${BINOWN}:${ORIGBINGRP} ${PROG})
120afe61c15SRodney W. Grimes.endif
121afe61c15SRodney W. Grimes.if defined(LINKS) && !empty(LINKS)
122afe61c15SRodney W. Grimes	@set ${LINKS}; \
123afe61c15SRodney W. Grimes	while test $$# -ge 2; do \
124afe61c15SRodney W. Grimes		l=${DESTDIR}$$1; \
125afe61c15SRodney W. Grimes		shift; \
126afe61c15SRodney W. Grimes		t=${DESTDIR}$$1; \
127afe61c15SRodney W. Grimes		shift; \
128a4c39c7aSBruce Evans		${ECHO} $$t -\> $$l; \
1292336a7eaSBruce Evans		ln -f $$l $$t; \
1302336a7eaSBruce Evans	done; true
1312336a7eaSBruce Evans.endif
1322336a7eaSBruce Evans.if defined(SYMLINKS) && !empty(SYMLINKS)
1332336a7eaSBruce Evans	@set ${SYMLINKS}; \
1342336a7eaSBruce Evans	while test $$# -ge 2; do \
1352336a7eaSBruce Evans		l=$$1; \
1362336a7eaSBruce Evans		shift; \
1372336a7eaSBruce Evans		t=${DESTDIR}$$1; \
1382336a7eaSBruce Evans		shift; \
1392336a7eaSBruce Evans		${ECHO} $$t -\> $$l; \
1402336a7eaSBruce Evans		ln -fs $$l $$t; \
141afe61c15SRodney W. Grimes	done; true
142afe61c15SRodney W. Grimes.endif
143afe61c15SRodney W. Grimes
144f7ee8cfeSRuslan Ermilov.if defined(SCRIPTS) && !empty(SCRIPTS)
145f7ee8cfeSRuslan Ermilovrealinstall: _scriptsinstall
146f7ee8cfeSRuslan Ermilov
147f7ee8cfeSRuslan ErmilovSCRIPTSDIR?=	${BINDIR}
148f7ee8cfeSRuslan ErmilovSCRIPTSOWN?=	${BINOWN}
149f7ee8cfeSRuslan ErmilovSCRIPTSGRP?=	${BINGRP}
150f7ee8cfeSRuslan ErmilovSCRIPTSMODE?=	${BINMODE}
151f7ee8cfeSRuslan Ermilov
152f7ee8cfeSRuslan Ermilov.for script in ${SCRIPTS}
153f7ee8cfeSRuslan Ermilov.if defined(SCRIPTSNAME)
154f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
155f7ee8cfeSRuslan Ermilov.else
156f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${script:T:R}
157f7ee8cfeSRuslan Ermilov.endif
158f7ee8cfeSRuslan ErmilovSCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
159f7ee8cfeSRuslan ErmilovSCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
160f7ee8cfeSRuslan ErmilovSCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
161f7ee8cfeSRuslan ErmilovSCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
162a7aaf57eSRuslan Ermilov_scriptsinstall: _SCRIPTSINS_${script:T}
163a7aaf57eSRuslan Ermilov_SCRIPTSINS_${script:T}: ${script}
164f7ee8cfeSRuslan Ermilov	${INSTALL} ${COPY} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
165f7ee8cfeSRuslan Ermilov	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
166f7ee8cfeSRuslan Ermilov	    ${_INSTALLFLAGS} ${.ALLSRC} \
167f7ee8cfeSRuslan Ermilov	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
168f7ee8cfeSRuslan Ermilov.endfor
169f7ee8cfeSRuslan Ermilov.endif
170f7ee8cfeSRuslan Ermilov
171a7aaf57eSRuslan Ermilov.if defined(FILES) && !empty(FILES)
172a7aaf57eSRuslan Ermilovrealinstall: _filesinstall
173a7aaf57eSRuslan Ermilov
174a7aaf57eSRuslan ErmilovFILESDIR?=	${BINDIR}
175a7aaf57eSRuslan ErmilovFILESOWN?=	${SHAREOWN}
176a7aaf57eSRuslan ErmilovFILESGRP?=	${SHAREGRP}
177a7aaf57eSRuslan ErmilovFILESMODE?=	${SHAREMODE}
178a7aaf57eSRuslan Ermilov
179a7aaf57eSRuslan Ermilov.for file in ${FILES}
180a7aaf57eSRuslan Ermilov.if defined(FILESNAME)
181a7aaf57eSRuslan ErmilovFILESNAME_${file:T}?=	${FILESNAME}
182a7aaf57eSRuslan Ermilov.else
183a7aaf57eSRuslan ErmilovFILESNAME_${file:T}?=	${file:T}
184a7aaf57eSRuslan Ermilov.endif
185a7aaf57eSRuslan ErmilovFILESDIR_${file:T}?=	${FILESDIR}
186a7aaf57eSRuslan ErmilovFILESOWN_${file:T}?=	${FILESOWN}
187a7aaf57eSRuslan ErmilovFILESGRP_${file:T}?=	${FILESGRP}
188a7aaf57eSRuslan ErmilovFILESMODE_${file:T}?=	${FILESMODE}
189a7aaf57eSRuslan Ermilov_filesinstall: _FILESINS_${file:T}
190a7aaf57eSRuslan Ermilov_FILESINS_${file:T}: ${file}
191a7aaf57eSRuslan Ermilov	${INSTALL} ${COPY} -o ${FILESOWN_${.ALLSRC:T}} \
192a7aaf57eSRuslan Ermilov	    -g ${FILESGRP_${.ALLSRC:T}} -m ${FILESMODE_${.ALLSRC:T}} \
193a7aaf57eSRuslan Ermilov	    ${_INSTALLFLAGS} ${.ALLSRC} \
194a7aaf57eSRuslan Ermilov	    ${DESTDIR}${FILESDIR_${.ALLSRC:T}}/${FILESNAME_${.ALLSRC:T}}
195a7aaf57eSRuslan Ermilov.endfor
196a7aaf57eSRuslan Ermilov.endif
197a7aaf57eSRuslan Ermilov
198cd9a2f5cSJordan K. Hubbardinstall: afterinstall _SUBDIR
1993585b293SGarrett Wollman.if !defined(NOMAN)
2003585b293SGarrett Wollmanafterinstall: realinstall maninstall
2013585b293SGarrett Wollman.else
202afe61c15SRodney W. Grimesafterinstall: realinstall
2033585b293SGarrett Wollman.endif
204afe61c15SRodney W. Grimes.endif
205afe61c15SRodney W. Grimes
206d9584d76SJordan K. HubbardDISTRIBUTION?=	bin
20755ff8fb1SPoul-Henning Kamp.if !target(distribute)
208cd9a2f5cSJordan K. Hubbarddistribute: _SUBDIR
209398ac038SJordan K. Hubbard.for dist in ${DISTRIBUTION}
210398ac038SJordan K. Hubbard	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
211398ac038SJordan K. Hubbard.endfor
21255ff8fb1SPoul-Henning Kamp.endif
21355ff8fb1SPoul-Henning Kamp
214afe61c15SRodney W. Grimes.if !target(lint)
215cd9a2f5cSJordan K. Hubbardlint: ${SRCS} _SUBDIR
216afe61c15SRodney W. Grimes.if defined(PROG)
21708b44302SBruce Evans	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} | more 2>&1
218afe61c15SRodney W. Grimes.endif
219afe61c15SRodney W. Grimes.endif
220afe61c15SRodney W. Grimes
2216eb5e456SJordan K. Hubbard.if defined(NOTAGS)
2226eb5e456SJordan K. Hubbardtags:
2236eb5e456SJordan K. Hubbard.endif
2246eb5e456SJordan K. Hubbard
225afe61c15SRodney W. Grimes.if !target(tags)
226cd9a2f5cSJordan K. Hubbardtags: ${SRCS} _SUBDIR
227afe61c15SRodney W. Grimes.if defined(PROG)
2281ed9b1c3SEivind Eklund	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
2296eb5e456SJordan K. Hubbard.if defined(HTML)
2301ed9b1c3SEivind Eklund	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
2316eb5e456SJordan K. Hubbard.endif
232afe61c15SRodney W. Grimes.endif
233afe61c15SRodney W. Grimes.endif
234afe61c15SRodney W. Grimes
235afe61c15SRodney W. Grimes.if !defined(NOMAN)
236afe61c15SRodney W. Grimes.include <bsd.man.mk>
237918fb560SRuslan Ermilov.else
238918fb560SRuslan Ermilov.if !target(all-man)
239918fb560SRuslan Ermilovall-man:
240918fb560SRuslan Ermilov.endif
241918fb560SRuslan Ermilov.if !target(maninstall)
242afe61c15SRodney W. Grimesmaninstall:
243afe61c15SRodney W. Grimes.endif
244918fb560SRuslan Ermilov.endif
2453585b293SGarrett Wollman
24669b87d3eSEivind Eklund.if !target(regress)
24769b87d3eSEivind Eklundregress:
24869b87d3eSEivind Eklund.endif
24969b87d3eSEivind Eklund
250368c8de4SJohn Polstra.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
2518c05a446SPeter Wemm.include <bsd.libnames.mk>
2528c05a446SPeter Wemm.endif
2538c05a446SPeter Wemm
2543585b293SGarrett Wollman.include <bsd.dep.mk>
255987afe2aSBruce Evans
25688505e11SRuslan Ermilov.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
257589d9341SBruce Evans${OBJS}: ${SRCS:M*.h}
258987afe2aSBruce Evans.endif
259987afe2aSBruce Evans
260cd9a2f5cSJordan K. Hubbard.include <bsd.obj.mk>
261d510ecb4SKris Kennaway
262d510ecb4SKris Kennaway.include <bsd.sys.mk>
263