Home | History | Annotate | Line # | Download | only in mk
      1 #	$NetBSD: bsd.lib.mk,v 1.427 2026/01/21 17:57:27 christos Exp $
      2 #	@(#)bsd.lib.mk	8.3 (Berkeley) 4/22/94
      3 
      4 .include <bsd.init.mk>
      5 .include <bsd.shlib.mk>
      6 .include <bsd.gcc.mk>
      7 .include <bsd.sanitizer.mk>
      8 
      9 # Pull in <bsd.sys.mk> here so we can override its .c.o rule
     10 .include <bsd.sys.mk>
     11 
     12 LIBISMODULE?=	no
     13 LIBISPRIVATE?=	no
     14 LIBISCXX?=	no
     15 
     16 .if ${LIBISMODULE} != "no"
     17 _LIB_PREFIX?=	# empty
     18 MKDEBUGLIB:=	no
     19 MKPROFILE:=	no
     20 MKPICINSTALL:=	no
     21 MAKESTATICLIB?=	no
     22 MAKELINKLIB?=	yes
     23 _LINTINSTALL?=	no
     24 .else
     25 _LIB_PREFIX?=	lib
     26 .endif
     27 
     28 .if ${LIBISPRIVATE} != "no"
     29 MKDEBUGLIB:=	no
     30 MKPROFILE:=	no
     31 MKPICINSTALL:=	no
     32 . if defined(NOSTATICLIB) && ${MKPICLIB} != "no"
     33 MAKESTATICLIB?=	no
     34 . elif ${LIBISPRIVATE} != "pic"
     35 MKPIC:=		no
     36 . endif
     37 MAKELINKLIB?=	no
     38 _LINTINSTALL?=	no
     39 .endif
     40 
     41 _LINTINSTALL?=	${MKLINT}
     42 LINKINSTALL?=	${MAKELINKLIB}
     43 MAKELINKLIB?=	${MKLINKLIB}
     44 MAKESTATICLIB?=	${MKSTATICLIB}
     45 
     46 ##### Basic targets
     47 .PHONY:		checkver libinstall
     48 realinstall:	checkver libinstall
     49 
     50 ##### LIB specific flags.
     51 # XXX: This is needed for programs that link with .a libraries
     52 # Perhaps a more correct solution is to always generate _pic.a
     53 # files or always have a shared library.
     54 # Another fix is to provide rcrt0.o like OpenBSD does and
     55 # do relocations for static PIE.
     56 .if defined(MKPIE) && (${MKPIE} != "no") && !defined(NOPIE)
     57 CFLAGS+=        ${PIE_CFLAGS}
     58 AFLAGS+=        ${PIE_AFLAGS}
     59 .endif
     60 # The -fPIC is needed for libraries that include other libraries
     61 # The order matters here, PIC needs to be last
     62 .if ${LIBISPRIVATE} == "pic" && ${MKPIC} != "no"
     63 CFLAGS+=        -fPIC
     64 AFLAGS+=        -fPIC
     65 .endif
     66 
     67 PGFLAGS+=	-pg
     68 .if ${MKPIC} != "no"
     69 PGFLAGS+=	-fPIC
     70 .endif
     71 
     72 ##### Libraries that this may depend upon.
     73 .if defined(LIBDPLIBS) && ${MKPIC} != "no"				# {
     74 .  for _lib _dir in ${LIBDPLIBS}
     75 .    if !defined(LIBDO.${_lib})
     76 LIBDO.${_lib}!=	cd "${_dir}" && ${PRINTOBJDIR}
     77 .MAKEOVERRIDES+=LIBDO.${_lib}
     78 .    endif
     79 .    if ${LIBDO.${_lib}} == "_external"
     80 LDADD+=		-l${_lib}
     81 .    else
     82 LDADD+=		-L${LIBDO.${_lib}} -l${_lib}
     83 .      if exists(${LIBDO.${_lib}}/lib${_lib}_pic.a)
     84 DPADD+=         ${LIBDO.${_lib}}/lib${_lib}_pic.a
     85 .      elif exists(${LIBDO.${_lib}}/lib${_lib}.so)
     86 DPADD+=         ${LIBDO.${_lib}}/lib${_lib}.so
     87 .      else
     88 DPADD+=         ${LIBDO.${_lib}}/lib${_lib}.a
     89 .      endif
     90 .    endif
     91 .  endfor
     92 .endif									# }
     93 
     94 ##### Build and install rules
     95 MKDEP_SUFFIXES?=	.o .po .pico .go .ln .d
     96 
     97 .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE})		# {
     98 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
     99 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
    100 SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
    101 
    102 DPADD+=	${SHLIB_VERSION_FILE}
    103 
    104 # Check for higher installed library versions.
    105 .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
    106 	exists(${NETBSDSRCDIR}/lib/checkver)
    107 checkver:
    108 	@(cd "${.CURDIR}" && \
    109 	    HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \
    110 	    ${HOST_SH} ${NETBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
    111 		    -d ${_DEST.OBJ} ${LIB})
    112 .endif
    113 .endif									# }
    114 
    115 .if !target(checkver)
    116 checkver:
    117 .endif
    118 
    119 print-shlib-major:
    120 .if defined(SHLIB_MAJOR) && ${MKPIC} != "no"
    121 	@echo ${SHLIB_MAJOR}
    122 .else
    123 	@false
    124 .endif
    125 
    126 print-shlib-minor:
    127 .if defined(SHLIB_MINOR) && ${MKPIC} != "no"
    128 	@echo ${SHLIB_MINOR}
    129 .else
    130 	@false
    131 .endif
    132 
    133 print-shlib-teeny:
    134 .if defined(SHLIB_TEENY) && ${MKPIC} != "no"
    135 	@echo ${SHLIB_TEENY}
    136 .else
    137 	@false
    138 .endif
    139 
    140 .if ${LIBISPRIVATE} == "no"
    141 .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR)				# {
    142 .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
    143 .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
    144 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
    145 .else
    146 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
    147 .endif
    148 .else
    149 SHLIB_FULLVERSION=${SHLIB_MAJOR}
    150 .endif
    151 .endif									# }
    152 .endif
    153 
    154 # add additional suffixes not exported.
    155 # .po is used for profiling object files.
    156 # .pico is used for PIC object files.
    157 .SUFFIXES: .out .a .ln .pico .po .go .o .s .S .c .cc .cpp .cxx .C .m .r .y .l .cl .p .h
    158 .SUFFIXES: .sh .m4 .m
    159 .SUFFIXES: ${_FORTRAN_SUFFIXES_NOCPP} ${_FORTRAN_SUFFIXES_CPP}
    160 
    161 # Set PICFLAGS to cc flags for producing position-independent code,
    162 # if not already set.
    163 
    164 # Data-driven table using make variables to control how shared libraries
    165 # are built for different platforms and object formats.
    166 # SHLIB_MAJOR, SHLIB_MINOR, SHLIB_TEENY: Major, minor, and teeny version
    167 #			numbers of shared library
    168 # SHLIB_SOVERSION:	version number to be compiled into a shared library
    169 #			via -soname. Usually ${SHLIB_MAJOR} on ELF.
    170 #			NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
    171 #			[.${SHLIB_TEENY}]]
    172 # SHLIB_SHFLAGS:	Flags to tell ${LD} to emit shared library.
    173 #			with ELF, also set shared-lib version for ld.so.
    174 # SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
    175 # SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
    176 
    177 PICFLAGS ?= -fPIC
    178 
    179 .if ${MKPICLIB} != "no"
    180 CSHLIBFLAGS+= ${PICFLAGS}
    181 .endif
    182 
    183 # Building all static libraries with sanitizer flags allows them to be
    184 # successfully linked into instrumented dynamic binaries, as well as
    185 # private libraries linked directly into executables.
    186 CFLAGS+=	${SANITIZERFLAGS} ${LIBCSANITIZERFLAGS}
    187 
    188 .if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
    189 MKSHLIBOBJS= yes
    190 .else
    191 MKSHLIBOBJS= no
    192 .endif
    193 
    194 # Avoid adding "-g" if we already have a "-g*" option.
    195 .if (${MKDEBUG:Uno} != "no" && !defined(NODEBUG)) && \
    196     (!defined(CFLAGS) || empty(CFLAGS:M-g*)) && \
    197     (!defined(CXXFLAGS) || empty(CXXFLAGS:M-g*))
    198 # Only add -g to the shared library objects because as there's no facility
    199 # to separate the debuginfo like shared libraries, except for private the
    200 # libraries that are linked into executables only.
    201 CSHLIBFLAGS+=	-g
    202 .if ${LIBISPRIVATE} != "no"
    203 CFLAGS+=	-g
    204 .endif
    205 .endif
    206 
    207 # Platform-independent linker flags for ELF shared libraries
    208 SHLIB_SOVERSION=	${SHLIB_MAJOR}
    209 SHLIB_SHFLAGS=		-Wl,-soname,${_LIB}.so.${SHLIB_SOVERSION}
    210 SHLIB_SHFLAGS+=		${SANITIZERFLAGS}
    211 .if !defined(SHLIB_WARNTEXTREL) || ${SHLIB_WARNTEXTREL} != "no"
    212 SHLIB_SHFLAGS+=		-Wl,--warn-shared-textrel
    213 .endif
    214 .if !defined(SHLIB_MKMAP) || ${SHLIB_MKMAP} != "no"
    215 SHLIB_SHFLAGS+=		-Wl,-Map=${_LIB}.so.${SHLIB_SOVERSION}.map
    216 .endif
    217 CLEANFILES+=		${_LIB}.so.${SHLIB_SOVERSION}.map
    218 SHLIB_LDSTARTFILE?=	${_GCC_CRTI} ${_GCC_CRTBEGINS}
    219 SHLIB_LDENDFILE?=	${_GCC_CRTENDS} ${_GCC_CRTN}
    220 
    221 CFLAGS+=	${COPTS}
    222 OBJCFLAGS+=	${OBJCOPTS}
    223 AFLAGS+=	${COPTS}
    224 FFLAGS+=	${FOPTS}
    225 
    226 .if defined(CTFCONVERT)
    227 .if defined(CFLAGS) && !empty(CFLAGS:M*-g*)
    228 CTFFLAGS+=	-g
    229 .if defined(HAVE_GCC)
    230 #CFLAGS+=	-gdwarf-2
    231 .endif
    232 .endif
    233 .endif
    234 
    235 LIBSTRIPAOBJS=	yes
    236 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
    237 LIBSTRIPCOBJS=	yes
    238 .endif
    239 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
    240 LIBSTRIPOBJCOBJS=	yes
    241 .endif
    242 .if !defined(FFLAGS) || empty(FFLAGS:M*-g*)
    243 LIBSTRIPFOBJS=	yes
    244 .endif
    245 .if !defined(CSHLIBFLAGS) || empty(CSHLIBFLAGS:M*-g*)
    246 LIBSTRIPSHLIBOBJS=	yes
    247 .endif
    248 
    249 .c.o:
    250 	${_MKTARGET_COMPILE}
    251 	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    252 	${CTFCONVERT_RUN}
    253 .if defined(LIBSTRIPCOBJS)
    254 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    255 .endif
    256 
    257 .c.po:
    258 	${_MKTARGET_COMPILE}
    259 	${COMPILE.c} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${PGFLAGS} ${.IMPSRC} ${OBJECT_TARGET}
    260 	${CTFCONVERT_RUN}
    261 .if defined(LIBSTRIPCOBJS)
    262 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    263 .endif
    264 
    265 .c.go:
    266 	${_MKTARGET_COMPILE}
    267 	${COMPILE.c} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
    268 
    269 .c.pico:
    270 	${_MKTARGET_COMPILE}
    271 	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${CSHLIBFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    272 .if defined(LIBSTRIPSHLIBOBJS)
    273 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    274 .endif
    275 
    276 .cc.o .cpp.o .cxx.o .C.o:
    277 	${_MKTARGET_COMPILE}
    278 	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    279 .if defined(LIBSTRIPCOBJS)
    280 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    281 .endif
    282 
    283 .cc.po .cpp.po .cxx.po .C.po:
    284 	${_MKTARGET_COMPILE}
    285 	${COMPILE.cc} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${PGFLAGS} ${.IMPSRC} -o ${.TARGET}
    286 .if defined(LIBSTRIPCOBJS)
    287 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    288 .endif
    289 
    290 .cc.go .cpp.go .cxx.go .C.go:
    291 	${_MKTARGET_COMPILE}
    292 	${COMPILE.cc} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
    293 
    294 .cc.pico .cpp.pico .cxx.pico .C.pico:
    295 	${_MKTARGET_COMPILE}
    296 	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${CSHLIBFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    297 .if defined(LIBSTRIPSHLIBOBJS)
    298 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    299 .endif
    300 
    301 ${_FORTRAN_SUFFIXES_NOCPP:=.o}:
    302 	${_MKTARGET_COMPILE}
    303 	${COMPILE.f} ${FOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    304 	${CTFCONVERT_RUN}
    305 .if defined(LIBSTRIPFOBJS)
    306 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    307 .endif
    308 
    309 ${_FORTRAN_SUFFIXES_NOCPP:=.po}:
    310 	${_MKTARGET_COMPILE}
    311 	${COMPILE.f} ${PROFFLAGS} ${FOPTS.${.IMPSRC:T}} ${PGFLAGS} ${.IMPSRC} ${OBJECT_TARGET}
    312 	${CTFCONVERT_RUN}
    313 .if defined(LIBSTRIPFOBJS)
    314 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    315 .endif
    316 
    317 ${_FORTRAN_SUFFIXES_NOCPP:=.go}:
    318 	${_MKTARGET_COMPILE}
    319 	${COMPILE.f} ${DEBUGFLAGS} ${FOPTS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
    320 
    321 ${_FORTRAN_SUFFIXES_NOCPP:=.pico}:
    322 	${_MKTARGET_COMPILE}
    323 	${COMPILE.f} ${FOPTS.${.IMPSRC:T}} ${PICFLAGS} ${.IMPSRC} -o ${.TARGET}
    324 .if defined(LIBSTRIPFOBJS)
    325 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    326 .endif
    327 
    328 ${_FORTRAN_SUFFIXES_NOCPP:=.ln}:
    329 	${_MKTARGET_COMPILE}
    330 	@echo Skipping lint for Fortran libraries.
    331 
    332 ${_FORTRAN_SUFFIXES_CPP:=.o}:
    333 	${_MKTARGET_COMPILE}
    334 	${COMPILE.F} ${FOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    335 	${CTFCONVERT_RUN}
    336 .if defined(LIBSTRIPFOBJS)
    337 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    338 .endif
    339 
    340 ${_FORTRAN_SUFFIXES_CPP:=.po}:
    341 	${_MKTARGET_COMPILE}
    342 	${COMPILE.F} ${PROFFLAGS} ${FOPTS.${.IMPSRC:T}} ${PGFLAGS} ${.IMPSRC} ${OBJECT_TARGET}
    343 	${CTFCONVERT_RUN}
    344 .if defined(LIBSTRIPFOBJS)
    345 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    346 .endif
    347 
    348 ${_FORTRAN_SUFFIXES_CPP:=.go}:
    349 	${_MKTARGET_COMPILE}
    350 	${COMPILE.F} ${DEBUGFLAGS} ${FOPTS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
    351 
    352 ${_FORTRAN_SUFFIXES_CPP:=.pico}:
    353 	${_MKTARGET_COMPILE}
    354 	${COMPILE.F} ${FOPTS.${.IMPSRC:T}} ${PICFLAGS} ${.IMPSRC} -o ${.TARGET}
    355 .if defined(LIBSTRIPFOBJS)
    356 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    357 .endif
    358 
    359 ${_FORTRAN_SUFFIXES_CPP:=.ln}:
    360 	${_MKTARGET_COMPILE}
    361 	@echo Skipping lint for Fortran libraries.
    362 
    363 .m.o:
    364 	${_MKTARGET_COMPILE}
    365 	${COMPILE.m} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    366 	${CTFCONVERT_RUN}
    367 .if defined(LIBSTRIPOBJCOBJS)
    368 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    369 .endif
    370 
    371 .m.po:
    372 	${_MKTARGET_COMPILE}
    373 	${COMPILE.m} ${PROFFLAGS} ${PGFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    374 	${CTFCONVERT_RUN}
    375 .if defined(LIBSTRIPOBJCOBJS)
    376 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    377 .endif
    378 
    379 .m.go:
    380 	${_MKTARGET_COMPILE}
    381 	${COMPILE.m} ${DEBUGFLAGS} -g ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    382 .if defined(LIBSTRIPOBJCOBJS)
    383 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    384 .endif
    385 
    386 .m.pico:
    387 	${_MKTARGET_COMPILE}
    388 	${COMPILE.m} ${CSHLIBFLAGS} ${CSHLIBFLAGS.${.IMPSRC:T}} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    389 .if defined(LIBSTRIPOBJCOBJS)
    390 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    391 .endif
    392 
    393 .s.o:
    394 	${_MKTARGET_COMPILE}
    395 	${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    396 	${CTFCONVERT_RUN}
    397 .if defined(LIBSTRIPAOBJS)
    398 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    399 .endif
    400 
    401 .S.o:
    402 	${_MKTARGET_COMPILE}
    403 	${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    404 	${CTFCONVERT_RUN}
    405 .if defined(LIBSTRIPAOBJS)
    406 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    407 .endif
    408 
    409 .s.po:
    410 	${_MKTARGET_COMPILE}
    411 	${COMPILE.s} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    412 	${CTFCONVERT_RUN}
    413 .if defined(LIBSTRIPAOBJS)
    414 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    415 .endif
    416 
    417 .S.po:
    418 	${_MKTARGET_COMPILE}
    419 	${COMPILE.S} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    420 	${CTFCONVERT_RUN}
    421 .if defined(LIBSTRIPAOBJS)
    422 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    423 .endif
    424 
    425 .s.go:
    426 	${_MKTARGET_COMPILE}
    427 	${COMPILE.s} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    428 
    429 .S.go:
    430 	${_MKTARGET_COMPILE}
    431 	${COMPILE.S} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    432 
    433 .s.pico:
    434 	${_MKTARGET_COMPILE}
    435 	${COMPILE.s} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    436 .if defined(LIBSTRIPAOBJS)
    437 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    438 .endif
    439 
    440 .S.pico:
    441 	${_MKTARGET_COMPILE}
    442 	${COMPILE.S} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    443 .if defined(LIBSTRIPAOBJS)
    444 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    445 .endif
    446 
    447 # Declare a few variables to make our life easier later.
    448 _LIB:=${_LIB_PREFIX}${LIB}
    449 _LIB.a:=${_LIB}.a
    450 _LIB_p.a:=${_LIB}_p.a
    451 _LIB_g.a:=${_LIB}_g.a
    452 _LIB_pic.a:=${_LIB}_pic.a
    453 _LIB.ln:=llib-l${LIB}.ln
    454 
    455 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    456 _LIB.so:=${_LIB}.so
    457 _LIB.so.major:=${_LIB}.so.${SHLIB_MAJOR}
    458 _LIB.so.full:=${_LIB}.so.${SHLIB_FULLVERSION}
    459 _LIB.so.link:=${_LIB}.so.${SHLIB_FULLVERSION}.link
    460 .if ${MKDEBUG:Uno} != "no" && !defined(NODEBUG)
    461 _LIB.so.debug:=${_LIB.so.full}.debug
    462 .endif
    463 .endif
    464 
    465 LIBSUBDIR?=		# empty
    466 _LIBSLASHSUBDIR=	${"${LIBSUBDIR}" == "":?:/${LIBSUBDIR}}
    467 
    468 _DEST.LIB:=${DESTDIR}${LIBDIR}${_LIBSLASHSUBDIR}
    469 _DEST.OBJ:=${DESTDIR}${_LIBSODIR}${_LIBSLASHSUBDIR}
    470 _DEST.LINT:=${DESTDIR}${LINTLIBDIR}${_LIBSLASHSUBDIR}
    471 _DEST.DEBUG:=${DESTDIR}${DEBUGDIR}${LIBDIR}${_LIBSLASHSUBDIR}
    472 _DEST.ODEBUG:=${DESTDIR}${DEBUGDIR}${_LIBSODIR}${_LIBSLASHSUBDIR}
    473 
    474 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
    475     || ${MAKELINKLIB} != "no" || ${MAKESTATICLIB} != "no"
    476 _BUILDSTATICLIB=yes
    477 .else
    478 _BUILDSTATICLIB=no
    479 .endif
    480 
    481 .if defined(LIB)							# {
    482 .if ${_BUILDSTATICLIB} != "no"
    483 _LIBS=${_LIB.a}
    484 .else
    485 _LIBS=
    486 .endif
    487 
    488 OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
    489 
    490 STOBJS+=${OBJS}
    491 
    492 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
    493 
    494 .if ${LIBISPRIVATE} != "no"
    495 # No installation is required
    496 libinstall::
    497 .endif
    498 
    499 .if ${MKDEBUGLIB} != "no" && ${MAKELINKLIB} != "no"
    500 _LIBS+=${_LIB_g.a}
    501 GOBJS+=${OBJS:.o=.go}
    502 DEBUGFLAGS?=-DDEBUG
    503 .endif
    504 
    505 .if ${MKPROFILE} != "no" && ${MAKELINKLIB} != "no"
    506 _LIBS+=${_LIB_p.a}
    507 POBJS+=${OBJS:.o=.po}
    508 PROFFLAGS?=-DGPROF -DPROF
    509 .endif
    510 
    511 .if ${MKPIC} != "no"							# {
    512 .if ${MKPICLIB} == "no"
    513 .if ${MKSHLIBOBJS} != "no"
    514 # make _pic.a, which isn't really pic,
    515 # since it's needed for making shared lib.
    516 # but don't install it.
    517 SOLIB=${_LIB_pic.a}
    518 SOBJS+=${OBJS:.o=.pico}
    519 .else
    520 SOLIB=${_LIB.a}
    521 .endif
    522 .else
    523 SOLIB=${_LIB_pic.a}
    524 _LIBS+=${SOLIB}
    525 SOBJS+=${OBJS:.o=.pico}
    526 .endif
    527 .if defined(SHLIB_FULLVERSION)
    528 _LIBS+=${_LIB.so.full}
    529 .endif
    530 .endif									# }
    531 
    532 .if ${MKLINT} != "no" && !empty(LOBJS)
    533 _LIBS+=${_LIB.ln}
    534 .endif
    535 
    536 ALLOBJS=
    537 .if ${_BUILDSTATICLIB} != "no"
    538 ALLOBJS+=${STOBJS}
    539 .endif
    540 ALLOBJS+=${POBJS} ${SOBJS}
    541 .if ${MKLINT} != "no" && !empty(LOBJS)
    542 ALLOBJS+=${LOBJS}
    543 .endif
    544 .else	# !defined(LIB)							# } {
    545 LOBJS=
    546 SOBJS=
    547 .endif	# !defined(LIB)							# }
    548 
    549 _YLSRCS=	${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
    550 
    551 .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
    552 
    553 realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.so.debug}
    554 
    555 .if ${MKARZERO} == "yes"
    556 _ARFL=crsD
    557 _ARRANFL=sD
    558 _INSTRANLIB=
    559 .else
    560 _ARFL=crs
    561 _ARRANFL=s
    562 _INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
    563 .endif
    564 
    565 # If you change this, please consider reflecting the change in
    566 # the override in sys/rump/Makefile.rump.
    567 .if !target(__archivebuild)
    568 __archivebuild: .USE
    569 	${_MKTARGET_BUILD}
    570 	@rm -f ${.TARGET}
    571 	${AR} ${_ARFL} ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT})
    572 .endif
    573 
    574 .if !target(__archiveinstall)
    575 __archiveinstall: .USE
    576 	${_MKTARGET_INSTALL}
    577 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    578 	    ${_INSTRANLIB} ${.ALLSRC} ${.TARGET}
    579 .endif
    580 
    581 __archivesymlinkpic: .USE
    582 	${_MKTARGET_INSTALL}
    583 	${INSTALL_SYMLINK} ${.ALLSRC} ${.TARGET}
    584 
    585 .if !target(__buildstdlib)
    586 __buildstdlib: .USE
    587 	@echo building standard ${.TARGET:T:S/.o//:S/lib//} library
    588 	@rm -f ${.TARGET}
    589 	@${LINK.c:S/-nostdinc//} -nostdlib ${LDFLAGS} -Wno-unused-command-line-argument -r -o ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT})
    590 .endif
    591 
    592 .if !target(__buildproflib)
    593 __buildproflib: .USE
    594 	@echo building profiled ${.TARGET:T:S/.o//:S/lib//} library
    595 	${_MKTARGET_BUILD}
    596 	@rm -f ${.TARGET}
    597 	@${LINK.c:S/-nostdinc//} -nostdlib ${LDFLAGS} -r -o ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*po} | ${TSORT})
    598 .endif
    599 
    600 DPSRCS+=	${_YLSRCS}
    601 CLEANFILES+=	${_YLSRCS}
    602 
    603 ${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
    604 
    605 ${_LIB.a}:: ${STOBJS} __archivebuild
    606 
    607 ${_LIB_p.a}:: ${POBJS} __archivebuild
    608 
    609 ${_LIB_pic.a}:: ${SOBJS} __archivebuild
    610 
    611 ${_LIB_g.a}:: ${GOBJS} __archivebuild
    612 
    613 
    614 _LIBLDOPTS=
    615 .if ${SHLIBDIR} != "/usr/lib"
    616 _LIBLDOPTS+=	-Wl,-rpath,${SHLIBDIR} \
    617 		-L=${SHLIBDIR}
    618 .elif ${SHLIBINSTALLDIR} != "/usr/lib"
    619 _LIBLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
    620 		-L=${SHLIBINSTALLDIR}
    621 .endif
    622 .if ${MKSTRIPSYM} != "no"
    623 _LIBLDOPTS+=	-Wl,-x
    624 .else
    625 _LIBLDOPTS+=	-Wl,-X
    626 .endif
    627 
    628 # XXX Provisional -- we should get this out of LIBDPLIBS for each
    629 # specific dependency so we can write the directory in one place where
    630 # the library is defined, and not copy and paste it everywhere the
    631 # library is used.
    632 #
    633 # XXX BEWARE: This should only be used by libraries that are private,
    634 # to link against libraries that are private.  If you are tempted to
    635 # use this in a library that we expose for applications to link
    636 # against, you need to find another way -- you can't link a library
    637 # against private dependencies without transitively exposing them to
    638 # applications.
    639 .for _subdir_ in ${LIBDPSUBDIRS:U}
    640 _LIBLDOPTS+=	-Wl,-rpath,${SHLIBDIR}/${_subdir_} \
    641 		-L=${SHLIBDIR}/${_subdir_}
    642 .endfor
    643 
    644 # gcc -shared now adds -lc automatically. For libraries other than libc and
    645 # libgcc* we add as a dependency the installed shared libc. For libc and
    646 # libgcc* we avoid adding libc as a dependency by using -nostdlib. Note that
    647 # -Xl,-nostdlib is not enough because we want to tell the compiler-driver not
    648 # to add standard libraries, not the linker.
    649 .if !defined(LIB)
    650 .if !empty(LIBC_SO)
    651 DPLIBC ?= ${DESTDIR}${LIBC_SO}
    652 .endif
    653 .else
    654 .if ${LIB} != "c" && ${LIB:Mgcc*} == ""
    655 .if !empty(LIBC_SO)
    656 DPLIBC ?= ${DESTDIR}${LIBC_SO}
    657 .endif
    658 .else
    659 LDLIBC ?= -nodefaultlibs
    660 .if ${HAVE_LIBGCC} == "yes" && ${LIB} == "c"
    661 LDADD+= -lgcc
    662 .endif
    663 .endif
    664 .endif
    665 
    666 .if ${LIBISCXX} != "no"
    667 LIBCC:=	${CXX}
    668 . if ${MKLIBCXX} == "yes"
    669 LIBDPLIBS+=     c++	${.CURDIR}/../../../../../external/bsd/libc++/lib
    670 . else
    671 LIBDPLIBS+=     stdc++	${.CURDIR}/../../../../../external/gpl3/${EXTERNAL_GCC_SUBDIR}/lib/libstdc++-v3
    672 . endif
    673 .else
    674 LIBCC:=	${CC}
    675 .endif
    676 
    677 # VERSION_MAP
    678 #
    679 #	Path to an ld version script to use when linking the library.
    680 #	Resolved from .PATH like a target prerequisite.
    681 #
    682 #	Implemented by adding -Wl,--version-script=${${VERSION_MAP}:P}
    683 #	to LDFLAGS, and by adding ${VERSION_MAP} to DPADD to make it a
    684 #	target prerequisite so :P works.
    685 #
    686 .if !empty(VERSION_MAP)
    687 DPADD+=			${VERSION_MAP}
    688 LDFLAGS+=		-Wl,--version-script=${${VERSION_MAP}:P}
    689 .endif
    690 
    691 _LDADD.${_LIB}=	${LDADD} ${LDADD.${_LIB}}
    692 _LDFLAGS.${_LIB}=	${LDFLAGS} ${LDFLAGS.${_LIB}}
    693 
    694 _MAINLIBDEPS=	${SOLIB} ${DPADD} ${DPLIBC} \
    695 		${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    696 
    697 .if defined(_LIB.so.debug)
    698 ${_LIB.so.debug}: ${_LIB.so.link}
    699 	${_MKTARGET_CREATE}
    700 	( ${OBJCOPY} --only-keep-debug --compress-debug-sections \
    701 	    ${_LIB.so.link} ${_LIB.so.debug} \
    702 	) || (rm -f ${.TARGET}; false)
    703 ${_LIB.so.full}: ${_LIB.so.link} ${_LIB.so.debug}
    704 	${_MKTARGET_CREATE}
    705 	(  ${OBJCOPY} --strip-debug -R .gnu_debuglink \
    706 	    --add-gnu-debuglink=${_LIB.so.debug} \
    707 	    ${_LIB.so.link} ${_LIB.so.full}.tmp && \
    708 	    ${MV} ${_LIB.so.full}.tmp ${_LIB.so.full} \
    709 	) || (rm -f ${.TARGET}; false)
    710 ${_LIB.so.link}: ${_MAINLIBDEPS}
    711 .else # aka no MKDEBUG
    712 ${_LIB.so.full}: ${_MAINLIBDEPS}
    713 .endif
    714 	${_MKTARGET_BUILD}
    715 	rm -f ${.TARGET}
    716 	${LIBCC} ${LDLIBC} -shared ${SHLIB_SHFLAGS} \
    717 	    ${_LDFLAGS.${_LIB}} -o ${.TARGET}.tmp ${_LIBLDOPTS} \
    718 	    -Wl,--whole-archive ${SOLIB} \
    719 	    -Wl,--no-whole-archive ${_LDADD.${_LIB}}
    720 .if ${MKSTRIPIDENT} != "no"
    721 	${OBJCOPY} -R .ident ${.TARGET}.tmp
    722 .endif
    723 	${MV} ${.TARGET}.tmp ${.TARGET}
    724 #  We don't use INSTALL_SYMLINK here because this is just
    725 #  happening inside the build directory/objdir. XXX Why does
    726 #  this spend so much effort on libraries that aren't live??? XXX
    727 #  XXX Also creates dead symlinks until the .full rule runs
    728 #  above and creates the main link
    729 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
    730     "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
    731 	${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so.major}.tmp
    732 	${MV} ${_LIB.so.major}.tmp ${_LIB.so.major}
    733 .endif
    734 	${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so}.tmp
    735 	${MV} ${_LIB.so}.tmp ${_LIB.so}
    736 
    737 # If there's a file listing expected symbols, fail if the diff from it
    738 # to the actual symbols is nonempty, and show the diff in that case.
    739 .if exists(${.CURDIR}/${LIB}.${LIBC_MACHINE_ARCH:U${MACHINE_ARCH}}.expsym)
    740 LIB_EXPSYM?=	${LIB}.${LIBC_MACHINE_ARCH:U${MACHINE_ARCH}}.expsym
    741 .elif exists(${.CURDIR}/${LIB}.${LIBC_MACHINE_CPU:U${MACHINE_CPU}}.expsym)
    742 LIB_EXPSYM?=	${LIB}.${LIBC_MACHINE_CPU:U${MACHINE_CPU}}.expsym
    743 .elif exists(${.CURDIR}/${LIB}.expsym)
    744 LIB_EXPSYM?=	${LIB}.expsym
    745 .endif
    746 
    747 # If we don't have a version map enumerating the exact symbols
    748 # exported, skip various machine-dependent crud that the linker
    749 # automatically exports (even though it appears to be unnecessary, as
    750 # demonstrated by libraries with version scripts which don't export
    751 # these symbols).
    752 #
    753 # This list has been gathered empirically -- I'm not sure it's written
    754 # down anywhere and I'm not sure there's any way to ask the linker to
    755 # simply not export the symbols.
    756 .if !empty(VERSION_MAP)
    757 _EXPSYM_PIPE_GREP=	# empty
    758 .else
    759 _EXPSYM_PIPE_GREP=	| grep -Fvx ${_EXPSYM_IGNORE:@_s_@-e ${_s_:Q}@}
    760 _EXPSYM_IGNORE+=		_end
    761 _EXPSYM_IGNORE+=		_fini
    762 _EXPSYM_IGNORE+=		_init
    763 _EXPSYM_IGNORE.aarch64+=	__bss_end__
    764 _EXPSYM_IGNORE.aarch64+=	__bss_start__
    765 _EXPSYM_IGNORE.aarch64+=	__end__
    766 _EXPSYM_IGNORE.aarch64+=	_bss_end__
    767 _EXPSYM_IGNORE.hppa+=		_GLOBAL_OFFSET_TABLE_
    768 _EXPSYM_IGNORE.powerpc64+=	._fini
    769 _EXPSYM_IGNORE.powerpc64+=	._init
    770 _EXPSYM_IGNORE.sh3+=		___ctors
    771 _EXPSYM_IGNORE.sh3+=		___ctors_end
    772 _EXPSYM_IGNORE.sh3+=		___dtors
    773 _EXPSYM_IGNORE.sh3+=		___dtors_end
    774 _EXPSYM_IGNORE+=		${_EXPSYM_IGNORE.${MACHINE_ARCH}}
    775 .  if ${MACHINE_ARCH} != ${MACHINE_CPU}
    776 _EXPSYM_IGNORE+=		${_EXPSYM_IGNORE.${MACHINE_CPU}}
    777 .  endif
    778 .endif
    779 
    780 .if !empty(LIB_EXPSYM) && ${MKPIC} != "no"
    781 realall: ${_LIB.so.full}.diffsym
    782 ${_LIB.so.full}.diffsym: ${LIB_EXPSYM} ${_LIB.so.full}.actsym
    783 	${_MKTARGET_CREATE}
    784 	@if diff -u ${.ALLSRC} >${.TARGET}.tmp; then \
    785 		${MV} ${.TARGET}.tmp ${.TARGET}; \
    786 	else \
    787 		ret=$$?; \
    788 		cat ${.TARGET}.tmp; \
    789 		echo ${_LIB.so.full}: error: \
    790 			actual symbols differ from expected symbols >&2; \
    791 		exit $$ret; \
    792 	fi
    793 ${_LIB.so.full}.actsym: ${_LIB.so.full}
    794 	${_MKTARGET_CREATE}
    795 	${NM} --dynamic --extern-only --defined-only --with-symbol-versions \
    796 		${.ALLSRC} \
    797 	| cut -d' ' -f3	${_EXPSYM_PIPE_GREP} | LC_ALL=C sort -u >${.TARGET}.tmp
    798 	${MV} ${.TARGET}.tmp ${.TARGET}
    799 CLEANFILES+=	${_LIB.so.full}.actsym
    800 CLEANFILES+=	${_LIB.so.full}.actsym.tmp
    801 CLEANFILES+=	${_LIB.so.full}.diffsym
    802 CLEANFILES+=	${_LIB.so.full}.diffsym.tmp
    803 update-symbols: .PHONY
    804 update-symbols: ${_LIB.so.full}.actsym
    805 	@if [ -f ${${LIB_EXPSYM}:P:Q} ] && \
    806 	    [ -n "`comm -23 ${${LIB_EXPSYM}:P:Q} ${.ALLSRC:Q}`" ]; then \
    807 		echo 'WARNING: Symbols deleted, major bump required!' >&2; \
    808 	elif [ -f ${${LIB_EXPSYM}:P:Q} ] && \
    809 	    [ -n "`comm -13 ${${LIB_EXPSYM}:P:Q} ${.ALLSRC:Q}`" ]; then \
    810 		echo 'WARNING: Symbols added, minor bump required!' >&2; \
    811 	fi
    812 	cp ${.ALLSRC} ${defined(NETBSDSRCDIR_RW):?${${LIB_EXPSYM}:P:C,^${NETBSDSRCDIR}/,${NETBSDSRCDIR_RW}/,}:${${LIB_EXPSYM}:P}}
    813 .endif
    814 
    815 .if !empty(LOBJS)							# {
    816 LLIBS?=		-lc
    817 ${_LIB.ln}: ${LOBJS}
    818 	${_MKTARGET_COMPILE}
    819 	rm -f ${.TARGET}
    820 .if defined(DESTDIR)
    821 	${LINT} -C${LIB} ${.ALLSRC} -L${DESTDIR}/usr/libdata ${LLIBS}
    822 .else
    823 	${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
    824 .endif
    825 .endif									# }
    826 
    827 # Only intended to be invoked manually, not as part of dependall.
    828 lint: ${LOBJS}
    829 .if defined(LOBJS) && !empty(LOBJS)
    830 	${LINT} ${LINTFLAGS} -Cmanual-lint ${LOBJS}
    831 .endif
    832 
    833 
    834 # If the number of entries in CLEANFILES is too large, then the
    835 # commands in bsd.clean.mk encounter errors like "exec(/bin/sh)
    836 # failed (Argument list too long)".  Avoid that by splitting the
    837 # files to clean into several lists using different variable names.
    838 # __cleanuse is an internal target in bsd.clean.mk; the way we
    839 # use it here mimics the way it's used by the clean target in
    840 # bsd.clean.mk.
    841 #
    842 clean: libclean1 libclean2 libclean3 libclean4 libclean5
    843 libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1
    844 libclean2: .PHONY .MADE __cleanuse LIBCLEANFILES2
    845 libclean3: .PHONY .MADE __cleanuse LIBCLEANFILES3
    846 libclean4: .PHONY .MADE __cleanuse LIBCLEANFILES4
    847 libclean5: .PHONY .MADE __cleanuse LIBCLEANFILES5
    848 CLEANFILES+= a.out [Ee]rrs mklog core *.core
    849 LIBCLEANFILES1+= ${_LIB.a}   ${STOBJS} ${STOBJS:=.tmp}
    850 LIBCLEANFILES2+= ${_LIB_p.a} ${POBJS}  ${POBJS:=.tmp}
    851 LIBCLEANFILES3+= ${_LIB_g.a} ${GOBJS}  ${GOBJS:=.tmp}
    852 LIBCLEANFILES4+= ${_LIB_pic.a}
    853 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    854 LIBCLEANFILES4+= ${_LIB.so}.* ${_LIB.so} ${_LIB.so.debug}
    855 .endif
    856 LIBCLEANFILES4+= ${SOBJS} ${SOBJS:=.tmp}
    857 LIBCLEANFILES5+= ${_LIB.ln} ${LOBJS} llib-lmanual-lint.ln
    858 
    859 .if !target(libinstall)							# {
    860 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
    861 libinstall::
    862 
    863 .if ${MAKELINKLIB} != "no" && ${MAKESTATICLIB} != "no" && ${LINKINSTALL} != "no"
    864 libinstall:: ${_DEST.LIB}/${_LIB.a}
    865 .PRECIOUS: ${_DEST.LIB}/${_LIB.a}
    866 
    867 .if ${MKUPDATE} == "no"
    868 .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
    869 ${_DEST.LIB}/${_LIB.a}! .MADE
    870 .endif
    871 ${_DEST.LIB}/${_LIB.a}! ${_LIB.a} __archiveinstall
    872 .else
    873 .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
    874 ${_DEST.LIB}/${_LIB.a}: .MADE
    875 .endif
    876 ${_DEST.LIB}/${_LIB.a}: ${_LIB.a} __archiveinstall
    877 .endif
    878 .endif
    879 
    880 .if ${MKPROFILE} != "no" && ${MAKELINKLIB} != "no"
    881 libinstall:: ${_DEST.LIB}/${_LIB_p.a}
    882 .PRECIOUS: ${_DEST.LIB}/${_LIB_p.a}
    883 
    884 .if ${MKUPDATE} == "no"
    885 .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
    886 ${_DEST.LIB}/${_LIB_p.a}! .MADE
    887 .endif
    888 ${_DEST.LIB}/${_LIB_p.a}! ${_LIB_p.a} __archiveinstall
    889 .else
    890 .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
    891 ${_DEST.LIB}/${_LIB_p.a}: .MADE
    892 .endif
    893 ${_DEST.LIB}/${_LIB_p.a}: ${_LIB_p.a} __archiveinstall
    894 .endif
    895 .endif
    896 
    897 .if ${MKDEBUGLIB} != "no" && ${MAKELINKLIB} != "no"
    898 libinstall:: ${_DEST.LIB}/${_LIB_g.a}
    899 .PRECIOUS: ${_DEST.LIB}/${_LIB_g.a}
    900 
    901 .if ${MKUPDATE} == "no"
    902 .if !defined(BUILD) && !make(all) && !make(${_LIB_g.a})
    903 ${_DEST.LIB}/${_LIB_g.a}! .MADE
    904 .endif
    905 ${_DEST.LIB}/${_LIB_g.a}! ${_LIB_g.a} __archiveinstall
    906 .else
    907 .if !defined(BUILD) && !make(all) && !make(${LIB_g.a})
    908 ${_DEST.LIB}/${_LIB_g.a}: .MADE
    909 .endif
    910 ${_DEST.LIB}/${_LIB_g.a}: ${_LIB_g.a} __archiveinstall
    911 .endif
    912 .endif
    913 
    914 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no" && !defined(NOPICINSTALL)
    915 libinstall:: ${_DEST.LIB}/${_LIB_pic.a}
    916 .PRECIOUS: ${_DEST.LIB}/${_LIB_pic.a}
    917 
    918 .if ${MKUPDATE} == "no"
    919 .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
    920 ${_DEST.LIB}/${_LIB_pic.a}! .MADE
    921 .endif
    922 .if ${MKPICLIB} == "no"
    923 ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB.a} __archivesymlinkpic
    924 .else
    925 ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB_pic.a} __archiveinstall
    926 .endif
    927 .else
    928 .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
    929 ${_DEST.LIB}/${_LIB_pic.a}: .MADE
    930 .endif
    931 .if ${MKPICLIB} == "no"
    932 ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB.a} __archivesymlinkpic
    933 .else
    934 ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB_pic.a} __archiveinstall
    935 .endif
    936 .endif
    937 .endif
    938 
    939 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    940 
    941 libinstall:: ${_DEST.OBJ}/${_LIB.so.full}
    942 .PRECIOUS: ${_DEST.OBJ}/${_LIB.so.full}
    943 
    944 .if ${MKUPDATE} == "no"
    945 .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
    946 ${_DEST.OBJ}/${_LIB.so.full}! .MADE
    947 .endif
    948 ${_DEST.OBJ}/${_LIB.so.full}! ${_LIB.so.full}
    949 .else
    950 .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
    951 ${_DEST.OBJ}/${_LIB.so.full}: .MADE
    952 .endif
    953 ${_DEST.OBJ}/${_LIB.so.full}: ${_LIB.so.full}
    954 .endif
    955 	${_MKTARGET_INSTALL}
    956 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    957 	    ${.ALLSRC} ${.TARGET}
    958 .if ${_LIBSODIR} != ${LIBDIR}
    959 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    960 	    ${_DEST.LIB}/${_LIB.so.full}
    961 .endif
    962 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
    963     "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
    964 	${INSTALL_SYMLINK} ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so.major}
    965 .if ${_LIBSODIR} != ${LIBDIR}
    966 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    967 	    ${_DEST.LIB}/${_LIB.so.major}
    968 .endif
    969 .endif
    970 .if ${MAKELINKLIB} != "no" && ${LINKINSTALL} != "no"
    971 	${INSTALL_SYMLINK}  ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so}
    972 .if ${_LIBSODIR} != ${LIBDIR}
    973 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    974 	    ${_DEST.LIB}/${_LIB.so}
    975 .endif
    976 .endif
    977 .endif
    978 
    979 .if defined(_LIB.so.debug)
    980 libinstall:: ${_DEST.DEBUG}/${_LIB.so.debug}
    981 .PRECIOUS: ${_DEST.DEBUG}/${_LIB.so.debug}
    982 
    983 ${_DEST.DEBUG}/${_LIB.so.debug}: ${_LIB.so.debug}
    984 	${_MKTARGET_INSTALL}
    985 	${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
    986 	    ${.ALLSRC} ${.TARGET}
    987 .if ${_LIBSODIR} != ${LIBDIR}
    988 	${INSTALL_SYMLINK} -l r ${_DEST.DEBUG}/${_LIB.so.debug} \
    989 	    ${_DEST.ODEBUG}/${_LIB.so.debug}
    990 .endif
    991 .endif
    992 
    993 .if ${_LINTINSTALL} != "no" && !empty(LOBJS)
    994 libinstall:: ${_DEST.LINT}/${_LIB.ln}
    995 .PRECIOUS: ${_DEST.LINT}/${_LIB.ln}
    996 
    997 .if ${MKUPDATE} == "no"
    998 .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
    999 ${_DEST.LINT}/${_LIB.ln}! .MADE
   1000 .endif
   1001 ${_DEST.LINT}/${_LIB.ln}! ${_LIB.ln}
   1002 .else
   1003 .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
   1004 ${_DEST.LINT}/${_LIB.ln}: .MADE
   1005 .endif
   1006 ${_DEST.LINT}/${_LIB.ln}: ${_LIB.ln}
   1007 .endif
   1008 	${_MKTARGET_INSTALL}
   1009 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
   1010 		${.ALLSRC} ${_DEST.LINT}
   1011 .endif
   1012 .endif	# !target(libinstall)						# }
   1013 
   1014 ##### Pull in related .mk logic
   1015 LINKSOWN?= ${LIBOWN}
   1016 LINKSGRP?= ${LIBGRP}
   1017 LINKSMODE?= ${LIBMODE}
   1018 .include <bsd.man.mk>
   1019 .include <bsd.nls.mk>
   1020 .include <bsd.files.mk>
   1021 .include <bsd.inc.mk>
   1022 .include <bsd.links.mk>
   1023 .include <bsd.dep.mk>
   1024 .include <bsd.clang-analyze.mk>
   1025 .include <bsd.clean.mk>
   1026 
   1027 ${TARGETS}:	# ensure existence
   1028