1 # $NetBSD: bsd.prog.mk,v 1.278 2012/08/24 20:26:24 jmmv Exp $
2 # @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
7 .
include <bsd.shlib.mk
>
9 .
include <minix.gcov.mk
>
12 # Definitions and targets shared among all programs built by a single
17 realinstall
: proginstall scriptsinstall
21 .if defined
(DESTDIR
) && !empty
(DESTDIR
)
22 echo
"set solib-absolute-prefix ${DESTDIR}" > .gdbinit
26 .for __gdbinit in
${GDBINIT}
27 echo
"source ${__gdbinit}" >> .gdbinit
30 CLEANFILES
+= a.out
[Ee
]rrs mklog core
*.core .gdbinit
32 .if defined
(SHAREDSTRINGS
)
35 ${CC} -E
${CPPFLAGS} ${CFLAGS} ${.IMPSRC
} | xstr
-c
-
36 @
${CC} ${CPPFLAGS} ${CFLAGS} -c x.c
-o
${.TARGET
}
39 .
cc.o .
cpp.o .
cxx.o .C.o
:
40 ${CXX} -E
${CPPFLAGS} ${CXXFLAGS} ${.IMPSRC
} | xstr
-c
-
42 @
${CXX} ${CPPFLAGS} ${CXXFLAGS} -c x.
cc -o
${.TARGET
}
46 .if defined
(MKPIE
) && (${MKPIE} != "no")
47 CFLAGS
+= ${PIE_CFLAGS}
48 AFLAGS
+= ${PIE_AFLAGS}
49 LDFLAGS
+= ${PIE_LDFLAGS}
53 OBJCFLAGS
+= ${OBJCOPTS}
54 MKDEP_SUFFIXES?
= .o .ln
56 # CTF preserve debug symbols
57 .if defined
(MKDTRACE
) && (${MKDTRACE} != "no") && (${CFLAGS
:M-g
} != "")
62 # ELF platforms depend on crti.o, crtbegin.o, crtend.o, and crtn.o
64 LIBCRTBEGIN
= ${DESTDIR}/usr
/lib
/crti.o
${_GCC_CRTBEGIN}
68 LIBCRTEND
= ${_GCC_CRTEND} ${DESTDIR}/usr
/lib
/crtn.o
71 _SHLINKER
= ${SHLINKDIR}/ld.elf_so
74 LIBCRT0
= ${DESTDIR}/usr
/lib
/crt0.o
78 ##### Installed system library definitions
81 # LIBC?=${DESTDIR}/usr/lib/libc.a
82 # LIBX11?=${DESTDIR}/usr/X11R7/lib/libX11.a
84 # NB: If you are a library here, add it in bsd.README
116 .
ifndef LIB
${_lib
:tu
}
117 LIB
${_lib
:tu
}= ${DESTDIR}/usr
/lib
/lib
${_lib
:S
/xx
/++/:S
/atf_c
/atf-c
/}.a
118 .MADE
: ${LIB
${_lib
:tu
}} # Note: ${DESTDIR} will be expanded
122 # PAM applications, if linked statically, need more libraries
123 .if
(${MKPIC} == "no")
124 .if
(${MKCRYPTO} != "no")
125 PAM_STATIC_LDADD
+= -lssh
126 PAM_STATIC_DPADD
+= ${LIBSSH}
128 .if
(${MKKERBEROS} != "no")
129 PAM_STATIC_LDADD
+= -lkafs
-lkrb5
-lhx509
-lwind
-lasn1 \
130 -lroken
-lcom_err
-lheimbase
-lcrypto
131 PAM_STATIC_DPADD
+= ${LIBKAFS} ${LIBKRB5} ${LIBHX509} ${LIBWIND} ${LIBASN1} \
132 ${LIBROKEN} ${LIBCOM_ERR} ${LIBHEIMBASE} ${LIBCRYPTO}
134 .if
(${MKSKEY} != "no")
135 PAM_STATIC_LDADD
+= -lskey
136 PAM_STATIC_DPADD
+= ${LIBSKEY}
138 PAM_STATIC_LDADD
+= -lradius
-lcrypt
-lrpcsvc
-lutil
139 PAM_STATIC_DPADD
+= ${LIBRADIUS} ${LIBCRYPT} ${LIBRPCSVC} ${LIBUTIL}
145 # NB: If you are a library here, add it in bsd.README
182 .
ifndef LIB
${_lib
:tu
}
183 LIB
${_lib
:tu
}= ${DESTDIR}${X11USRLIBDIR}/lib
${_lib}.a
184 .MADE
: ${LIB
${_lib
:tu
}} # Note: ${DESTDIR} will be expanded
188 .if defined
(RESCUEDIR
)
189 CPPFLAGS
+= -DRESCUEDIR
=\"${RESCUEDIR}\"
193 .if
${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves
194 _PROGLDOPTS
+= -Wl
,-dynamic-linker
=${_SHLINKER}
196 .if
${SHLIBDIR} != "/usr/lib"
197 _PROGLDOPTS
+= -Wl
,-rpath
,${SHLIBDIR} \
199 .elif
${SHLIBINSTALLDIR} != "/usr/lib"
200 _PROGLDOPTS
+= -Wl
,-rpath-link
,${DESTDIR}${SHLIBINSTALLDIR} \
201 -L
=${SHLIBINSTALLDIR}
206 ${INSTALL_FILE} -o
${BINOWN} -g
${BINGRP} -m
${BINMODE} \
207 ${STRIPFLAG} ${.ALLSRC
} ${.TARGET
}
209 __progrumpinstall
: .USE
211 ${INSTALL_FILE} -o
${RUMPBINOWN} -g
${RUMPBINGRP} -m
${RUMPBINMODE} \
212 ${STRIPFLAG} ${.ALLSRC
} ${.TARGET
}
214 __progdebuginstall
: .USE
216 ${INSTALL_FILE} -o
${DEBUGOWN} -g
${DEBUGGRP} -m
${DEBUGMODE} \
217 ${.ALLSRC
} ${.TARGET
}
222 # Backwards compatibility with Makefiles that assume that bsd.prog.mk
223 # can only build a single binary.
231 .if defined
(PROG_CXX
)
233 _CCLINK
= ${CXX} ${_CCLINKFLAGS}
238 .
ifndef CRUNCHEDPROG
239 . if
(${MKRUMP} != "no")
240 PROGS
= ${RUMPPRG} rump.
${RUMPPRG}
245 . if
(${MKRUMP} != "no")
246 SRCS.rump.
${PROG}:= ${SRCS} ${PROG}_rumpops.c
${RUMPSRCS}
248 SRCS
+= ${PROG}_hostops.c
250 SRCS
= ${PROG}.c
${PROG}_hostops.c
251 . if
(${MKRUMP} != "no")
252 SRCS.rump.
${PROG}= ${PROG}.c
${PROG}_rumpops.c
${RUMPSRCS}
255 . if
(${MKRUMP} != "no")
256 DPSRCS
+= ${PROG}_rumpops.c
${RUMPSRCS}
257 LDADD.rump.
${PROG}+= -lrumpclient
258 DPADD.rump.
${PROG}+= ${LIBRUMPCLIENT}
259 MAN.rump.
${PROG}= # defined but feeling empty
260 _RUMPINSTALL.rump.
${PROG}=# defined
262 .
else # CRUNCHEDPROG
264 CPPFLAGS
+= -DCRUNCHOPS
269 _CCLINK?
= ${CC} ${_CCLINKFLAGS}
275 OBJS
= ${OBJS.
${PROG}}
277 . if defined
(PROGNAME
)
278 PROGNAME.
${PROG}= ${PROGNAME}
281 SRCS.
${PROG}= ${SRCS}
286 # Turn the single-program PROG and PROG_CXX variables into their multi-word
287 # counterparts, PROGS and PROGS_CXX.
288 .if
!defined
(RUMPPRG
)
289 . if defined
(PROG_CXX
) && !defined
(PROGS_CXX
)
290 PROGS_CXX
= ${PROG_CXX}
291 . elif defined
(PROG
) && !defined
(PROGS
)
297 # Per-program definitions and targets.
300 _CCLINK.CDEFAULT
= ${CC} ${_CCLINKFLAGS}
301 # Definitions specific to C programs.
304 _CCLINK.
${_P}= ${CC} ${_CCLINKFLAGS}
305 _CFLAGS.
${_P}= ${CFLAGS} ${CPUFLAGS}
306 _CPPFLAGS.
${_P}= ${CPPFLAGS}
307 _COPTS.
${_P}= ${COPTS}
310 _CCLINK.CXXDEFAULT
= ${CXX} ${_CCLINKFLAGS}
311 # Definitions specific to C++ programs.
312 .for _P in
${PROGS_CXX}
313 SRCS.
${_P}?
= ${_P}.
cc
314 _CCLINK.
${_P}= ${CXX} ${_CCLINKFLAGS}
317 # Language-independent definitions.
318 .for _P in
${PROGS} ${PROGS_CXX} # {
320 BINDIR.
${_P}?
= ${BINDIR}
321 PROGNAME.
${_P}?
= ${_P}
323 .if
${MKDEBUG} != "no" && !commands
(${_P})
324 _PROGDEBUG.
${_P}:= ${PROGNAME.
${_P}}.debug
327 .if defined
(PAXCTL_FLAGS
)
328 PAXCTL_FLAGS.
${_P}?
= ${PAXCTL_FLAGS}
331 ##### PROG specific flags.
333 _DPADD.
${_P}= ${DPADD} ${DPADD.
${_P}}
334 _LDADD.
${_P}= ${LDADD} ${LDADD.
${_P}}
335 _LDFLAGS.
${_P}= ${LDFLAGS} ${LDFLAGS.
${_P}}
336 _LDSTATIC.
${_P}= ${LDSTATIC} ${LDSTATIC.
${_P}}
338 ##### Build and install rules
339 .if
!empty
(_APPEND_SRCS
:M
[Yy
][Ee
][Ss
])
340 SRCS
+= ${SRCS.
${_P}} # For bsd.dep.mk
343 _YPSRCS.
${_P}= ${SRCS.
${_P}:M
*.
[ly
]:C
/\..
$/.c
/} ${YHEADER
:D
${SRCS.
${_P}:M
*.y
:.y
=.h
}}
345 DPSRCS
+= ${_YPSRCS.
${_P}}
346 CLEANFILES
+= ${_YPSRCS.
${_P}}
348 .if
!empty
(SRCS.
${_P}:N
*.h
:N
*.sh
:N
*.fth
)
349 OBJS.
${_P}+= ${SRCS.
${_P}:N
*.h
:N
*.sh
:N
*.fth
:R
:S
/$/.o
/g
}
350 LOBJS.
${_P}+= ${LSRCS
:.c
=.ln
} ${SRCS.
${_P}:M
*.c
:.c
=.ln
}
353 .if defined
(OBJS.
${_P}) && !empty
(OBJS.
${_P}) # {
354 .NOPATH
: ${OBJS.
${_P}} ${_P} ${_YPSRCS.
${_P}}
356 .if
(defined
(USE_COMBINE
) && ${USE_COMBINE} != "no" && !commands
(${_P}) \
357 && (${_CCLINK.
${_P}} == ${_CCLINK.CDEFAULT
} \
358 ||
${_CCLINK.
${_P}} == ${_CCLINK.CXXDEFAULT
}) \
359 && !defined
(NOCOMBINE.
${_P}) && !defined
(NOCOMBINE
))
360 .for f in
${SRCS.
${_P}:N
*.h
:N
*.sh
:N
*.fth
:C
/\.
[yl
]$/.c
/g
}
361 #_XFLAGS.$f := ${CPPFLAGS.$f:D1} ${CPUFLAGS.$f:D2} \
362 # ${COPTS.$f:D3} ${OBJCOPTS.$f:D4} ${CXXFLAGS.$f:D5}
363 .if
(${CPPFLAGS.
$f:D1
} == "1" ||
${CPUFLAGS.
$f:D2
} == "2" \
364 ||
${COPTS.
$f:D3
} == "3" ||
${OBJCOPTS.
$f:D4
} == "4" \
365 ||
${CXXFLAGS.
$f:D5
} == "5") \
366 ||
("${f:M*.[cyl]}" == "" || commands
(${f
:R
:S
/$/.o
/}))
367 XOBJS.
${_P}+= ${f
:R
:S
/$/.o
/}
374 ${_P}: .gdbinit
${LIBCRT0} ${XOBJS.
${_P}} ${SRCS.
${_P}} ${DPSRCS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${_DPADD.
${_P}}
377 ${_CCLINK.
${_P}} -Wl
,-nostdlib \
378 ${_LDFLAGS.
${_P}} ${_LDSTATIC.
${_P}} -o
${.TARGET
} ${_PROGLDOPTS} \
379 -B
${_GCC_CRTDIR}/ -B
${DESTDIR}/usr
/lib
/ \
380 -MD
--combine
${_CPPFLAGS.
${_P}} ${_CFLAGS.
${_P}} ${_COPTS.
${_P}} \
381 ${XSRCS.
${_P}:@.SRC.@
${.ALLSRC
:M
*.c
:M
*${.SRC.
}}@
:O
:u
} ${XOBJS.
${_P}} \
382 ${_LDADD.
${_P}} -L
${_GCC_LIBGCCDIR} -L
${DESTDIR}/usr
/lib
384 ${_CCLINK.
${_P}} ${_LDFLAGS.
${_P}} ${_LDSTATIC.
${_P}} -o
${.TARGET
} ${_PROGLDOPTS} \
385 -MD
--combine
${_CPPFLAGS.
${_P}} ${_COPTS.
${_P}}
386 ${XSRCS.
${_P}:@.SRC.@
${.ALLSRC
:M
*.c
:M
*${.SRC.
}}@
:O
:u
} ${XOBJS.
${_P}} \
388 .
endif # defined(DESTDIR)
389 .if defined
(CTFMERGE
)
390 ${CTFMERGE} ${CTFMFLAGS} -o
${.TARGET
} ${OBJS.
${_P}}
392 .if defined
(PAXCTL_FLAGS.
${_P})
393 ${PAXCTL} ${PAXCTL_FLAGS.
${_P}} ${.TARGET
}
395 .if
${MKSTRIPIDENT} != "no"
396 ${OBJCOPY} -R .ident
${.TARGET
}
401 .
include "${_P}.d" # include -MD depend for program.
405 ${OBJS.
${_P}} ${LOBJS.
${_P}}: ${DPSRCS}
407 ${_P}: .gdbinit
${LIBCRT0} ${OBJS.
${_P}} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${_DPADD.
${_P}}
411 ${_LDFLAGS.
${_P}} ${_LDSTATIC.
${_P}} -o
${.TARGET
} \
412 ${OBJS.
${_P}} ${_LDADD.
${_P}} \
414 .if defined
(CTFMERGE
)
415 ${CTFMERGE} ${CTFMFLAGS} -o
${.TARGET
} ${OBJS.
${_P}}
417 .if defined
(PAXCTL_FLAGS.
${_P})
418 ${PAXCTL} ${PAXCTL_FLAGS.
${_P}} ${.TARGET
}
420 .if
${MKSTRIPIDENT} != "no"
421 ${OBJCOPY} -R .ident
${.TARGET
}
423 .
endif # !commands(${_P})
426 ${_P}.ro
: ${OBJS.
${_P}} ${_DPADD.
${_P}}
428 ${CC} ${LDFLAGS} -nostdlib
-r
-Wl
,-dc
-o
${.TARGET
} ${OBJS.
${_P}}
430 .if defined
(_PROGDEBUG.
${_P})
431 ${_PROGDEBUG.
${_P}}: ${_P}
433 ( ${OBJCOPY} --only-keep-debug
${_P} ${_PROGDEBUG.
${_P}} \
434 && ${OBJCOPY} --strip-debug
-p
-R .gnu_debuglink \
435 --add-gnu-debuglink
=${_PROGDEBUG.
${_P}} ${_P} \
436 ) ||
(rm -f
${_PROGDEBUG.
${_P}}; false
)
439 .
endif # defined(OBJS.${_P}) && !empty(OBJS.${_P}) # }
441 .if
!defined
(MAN.
${_P})
443 .
endif # !defined(MAN.${_P})
444 .if
!empty
(_APPEND_MANS
:M
[Yy
][Ee
][Ss
])
448 realall
: ${_P} ${_PROGDEBUG.
${_P}}
450 CLEANFILES
+= ${_P} ${_PROGDEBUG.
${_P}}
452 .if defined
(OBJS.
${_P}) && !empty
(OBJS.
${_P})
453 CLEANFILES
+= ${OBJS.
${_P}} ${LOBJS.
${_P}}
456 _PROG_INSTALL
+= proginstall-
${_P}
458 .if
!target
(proginstall-
${_P}) # {
459 proginstall-
${_P}:: ${DESTDIR}${BINDIR.
${_P}}/${PROGNAME.
${_P}} \
460 ${_PROGDEBUG.
${_P}:D
${DESTDIR}${DEBUGDIR}${BINDIR.
${_P}}/${_PROGDEBUG.
${_P}}}
461 .PRECIOUS
: ${DESTDIR}${BINDIR.
${_P}}/${PROGNAME.
${_P}} \
462 ${_PROGDEBUG.
${_P}:D
${DESTDIR}${DEBUGDIR}${BINDIR.
${_P}}/${_PROGDEBUG.
${_P}}}
464 .if
${MKUPDATE} == "no"
465 .if defined
(_RUMPINSTALL.
${_P})
466 ${DESTDIR}${BINDIR.
${_P}}/${PROGNAME.
${_P}}! ${_P} __progrumpinstall
468 ${DESTDIR}${BINDIR.
${_P}}/${PROGNAME.
${_P}}! ${_P} __proginstall
470 .if
!defined
(BUILD
) && !make
(all) && !make
(${_P})
471 ${DESTDIR}${BINDIR.
${_P}}/${PROGNAME.
${_P}}! .MADE
473 .if defined
(_PROGDEBUG.
${_P})
474 ${DESTDIR}${DEBUGDIR}${BINDIR.
${_P}}/${_PROGDEBUG.
${_P}}! ${_PROGDEBUG.
${_P}} __progdebuginstall
475 .if
!defined
(BUILD
) && !make
(all) && !make
(${_P})
476 ${DESTDIR}${DEBUGDIR}${BINDIR.
${_P}}/${_PROGDEBUG.
${_P}}! .MADE
478 .
endif # define(_PROGDEBUG.${_P})
479 .
else # MKUPDATE != no
480 .if defined
(_RUMPINSTALL.
${_P})
481 ${DESTDIR}${BINDIR.
${_P}}/${PROGNAME.
${_P}}: ${_P} __progrumpinstall
483 ${DESTDIR}${BINDIR.
${_P}}/${PROGNAME.
${_P}}: ${_P} __proginstall
485 .if
!defined
(BUILD
) && !make
(all) && !make
(${_P})
486 ${DESTDIR}${BINDIR.
${_P}}/${PROGNAME.
${_P}}: .MADE
488 .if defined
(_PROGDEBUG.
${_P})
489 ${DESTDIR}${DEBUGDIR}${BINDIR.
${_P}}/${_PROGDEBUG.
${_P}}: ${_PROGDEBUG.
${_P}} __progdebuginstall
490 .if
!defined
(BUILD
) && !make
(all) && !make
(${_P})
491 ${DESTDIR}${DEBUGDIR}${BINDIR.
${_P}}/${_PROGDEBUG.
${_P}}: .MADE
493 .
endif # defined(_PROGDEBUG.${_P})
494 .
endif # MKUPDATE != no
496 .
endif # !target(proginstall-${_P}) # }
499 lint-
${_P}: ${LOBJS.
${_P}}
500 .if defined
(LOBJS.
${_P}) && !empty
(LOBJS.
${_P})
501 ${LINT} ${LINTFLAGS} ${_LDFLAGS.
${_P}:C
/-L
[ ]*/-L
/Wg
:M-L
*} ${LOBJS.
${_P}} ${_LDADD.
${_P}}
504 .endfor
# _P in ${PROGS} ${PROGS_CXX} # }
506 .if defined
(OBJS
) && !empty
(OBJS
) && \
507 (empty
(PROGS
) && empty
(PROGS_CXX
))
508 CLEANFILES
+= ${OBJS} ${LOBJS}
511 .if
!target
(proginstall
)
512 proginstall
:: ${_PROG_INSTALL}
519 .if defined
(SCRIPTS
) && !target
(scriptsinstall
) # {
520 SCRIPTSDIR?
=${BINDIR}
521 SCRIPTSOWN?
=${BINOWN}
522 SCRIPTSGRP?
=${BINGRP}
523 SCRIPTSMODE?
=${BINMODE}
525 scriptsinstall
:: ${SCRIPTS
:@S@
${DESTDIR}${SCRIPTSDIR_
${S}:U
${SCRIPTSDIR}}/${SCRIPTSNAME_
${S}:U
${SCRIPTSNAME
:U
${S
:T
:R
}}}@
}
526 .PRECIOUS
: ${SCRIPTS
:@S@
${DESTDIR}${SCRIPTSDIR_
${S}:U
${SCRIPTSDIR}}/${SCRIPTSNAME_
${S}:U
${SCRIPTSNAME
:U
${S
:T
:R
}}}@
}
528 __scriptinstall
: .USE
531 -o
${SCRIPTSOWN_
${.ALLSRC
:T
}:U
${SCRIPTSOWN}} \
532 -g
${SCRIPTSGRP_
${.ALLSRC
:T
}:U
${SCRIPTSGRP}} \
533 -m
${SCRIPTSMODE_
${.ALLSRC
:T
}:U
${SCRIPTSMODE}} \
534 ${.ALLSRC
} ${.TARGET
}
536 .for S in
${SCRIPTS
:O
:u
}
537 .if
${MKUPDATE} == "no"
538 ${DESTDIR}${SCRIPTSDIR_
${S}:U
${SCRIPTSDIR}}/${SCRIPTSNAME_
${S}:U
${SCRIPTSNAME
:U
${S
:T
:R
}}}! ${S} __scriptinstall
539 .if
!defined
(BUILD
) && !make
(all) && !make
(${S})
540 ${DESTDIR}${SCRIPTSDIR_
${S}:U
${SCRIPTSDIR}}/${SCRIPTSNAME_
${S}:U
${SCRIPTSNAME
:U
${S
:T
:R
}}}! .MADE
543 ${DESTDIR}${SCRIPTSDIR_
${S}:U
${SCRIPTSDIR}}/${SCRIPTSNAME_
${S}:U
${SCRIPTSNAME
:U
${S
:T
:R
}}}: ${S} __scriptinstall
544 .if
!defined
(BUILD
) && !make
(all) && !make
(${S})
545 ${DESTDIR}${SCRIPTSDIR_
${S}:U
${SCRIPTSDIR}}/${SCRIPTSNAME_
${S}:U
${SCRIPTSNAME
:U
${S
:T
:R
}}}: .MADE
551 .if
!target
(scriptsinstall
)
554 .PHONY
: scriptsinstall
556 ##### Pull in related .mk logic
559 LINKSMODE?
= ${BINMODE}
560 .
include <bsd.man.mk
>
561 .
include <bsd.nls.mk
>
562 .
include <bsd.files.mk
>
563 .
include <bsd.inc.mk
>
564 .
include <bsd.links.mk
>
565 .
include <bsd.sys.mk
>
566 .
include <bsd.dep.mk
>
567 .
include <bsd.clang-analyze.mk
>
568 .
include <bsd.
clean.mk
>
570 ${TARGETS}: # ensure existence