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