Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.324.2.3
      1 #	$NetBSD: bsd.lib.mk,v 1.324.2.3 2013/06/23 06:28:54 tls 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 # Pull in <bsd.sys.mk> here so we can override its .c.o rule
      8 .include <bsd.sys.mk>
      9 
     10 LIBISMODULE?=	no
     11 LIBISPRIVATE?=	no
     12 LIBISCXX?=	no
     13 
     14 .if ${LIBISMODULE} != "no"
     15 _LIB_PREFIX?=	# empty
     16 MKDEBUGLIB:=	no
     17 MKLINT:=	no
     18 MKPICINSTALL:=	no
     19 MKPROFILE:=	no
     20 MKSTATICLIB:=	no
     21 .else
     22 _LIB_PREFIX?=	lib
     23 .endif
     24 
     25 .if ${LIBISPRIVATE} != "no"
     26 MKDEBUGLIB:=	no
     27 MKLINT:=	no
     28 MKPICINSTALL:=	no
     29 . if defined(NOSTATICLIB) && ${MKPICLIB} != "no"
     30 MKSTATICLIB:=	no
     31 . else
     32 MKPIC:=		no
     33 . endif
     34 MKPROFILE:=	no
     35 .endif
     36 
     37 ##### Basic targets
     38 .PHONY:		checkver libinstall
     39 realinstall:	checkver libinstall
     40 
     41 ##### LIB specific flags.
     42 # XXX: This is needed for programs that link with .a libraries
     43 # Perhaps a more correct solution is to always generate _pic.a
     44 # files or always have a shared library.
     45 .if defined(MKPIE) && (${MKPIE} != "no")
     46 CFLAGS+=        ${PIE_CFLAGS}
     47 AFLAGS+=        ${PIE_AFLAGS}
     48 .endif
     49 
     50 ##### Libraries that this may depend upon.
     51 .if defined(LIBDPLIBS) && ${MKPIC} != "no"				# {
     52 .for _lib _dir in ${LIBDPLIBS}
     53 .if !defined(LIBDO.${_lib})
     54 LIBDO.${_lib}!=	cd "${_dir}" && ${PRINTOBJDIR}
     55 .MAKEOVERRIDES+=LIBDO.${_lib}
     56 .endif
     57 .if ${LIBDO.${_lib}} == "_external"
     58 LDADD+=		-l${_lib}
     59 .else
     60 LDADD+=		-L${LIBDO.${_lib}} -l${_lib}
     61 DPADD+=		${LIBDO.${_lib}}/lib${_lib}.so	# Don't use _LIB_PREFIX
     62 .endif
     63 .endfor
     64 .endif									# }
     65 
     66 ##### Build and install rules
     67 MKDEP_SUFFIXES?=	.o .po .pico .go .ln
     68 
     69 .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE})		# {
     70 SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
     71 SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
     72 SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
     73 
     74 DPADD+=	${SHLIB_VERSION_FILE}
     75 
     76 # Check for higher installed library versions.
     77 .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
     78 	exists(${NETBSDSRCDIR}/lib/checkver)
     79 checkver:
     80 	@(cd "${.CURDIR}" && \
     81 	    HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \
     82 	    ${HOST_SH} ${NETBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
     83 		    -d ${_DEST.OBJ} ${LIB})
     84 .endif
     85 .endif									# }
     86 
     87 .if !target(checkver)
     88 checkver:
     89 .endif
     90 
     91 print-shlib-major:
     92 .if defined(SHLIB_MAJOR) && ${MKPIC} != "no"
     93 	@echo ${SHLIB_MAJOR}
     94 .else
     95 	@false
     96 .endif
     97 
     98 print-shlib-minor:
     99 .if defined(SHLIB_MINOR) && ${MKPIC} != "no"
    100 	@echo ${SHLIB_MINOR}
    101 .else
    102 	@false
    103 .endif
    104 
    105 print-shlib-teeny:
    106 .if defined(SHLIB_TEENY) && ${MKPIC} != "no"
    107 	@echo ${SHLIB_TEENY}
    108 .else
    109 	@false
    110 .endif
    111 
    112 .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR)				# {
    113 .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
    114 .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
    115 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
    116 .else
    117 SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
    118 .endif
    119 .else
    120 SHLIB_FULLVERSION=${SHLIB_MAJOR}
    121 .endif
    122 .endif									# }
    123 
    124 # add additional suffixes not exported.
    125 # .po is used for profiling object files.
    126 # .pico is used for PIC object files.
    127 .SUFFIXES: .out .a .ln .pico .po .go .o .s .S .c .cc .cpp .cxx .C .m .F .f .r .y .l .cl .p .h
    128 .SUFFIXES: .sh .m4 .m
    129 
    130 
    131 # Set PICFLAGS to cc flags for producing position-independent code,
    132 # if not already set.  Includes -DPIC, if required.
    133 
    134 # Data-driven table using make variables to control how shared libraries
    135 # are built for different platforms and object formats.
    136 # SHLIB_MAJOR, SHLIB_MINOR, SHLIB_TEENY: Major, minor, and teeny version
    137 #			numbers of shared library
    138 # SHLIB_SOVERSION:	version number to be compiled into a shared library
    139 #			via -soname. Usualy ${SHLIB_MAJOR} on ELF.
    140 #			NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
    141 #			[.${SHLIB_TEENY}]]
    142 # SHLIB_SHFLAGS:	Flags to tell ${LD} to emit shared library.
    143 #			with ELF, also set shared-lib version for ld.so.
    144 # SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
    145 # SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
    146 # FPICFLAGS:		flags for ${FC} to compile .[fF] files to .pico objects.
    147 # CPPPICFLAGS:		flags for ${CPP} to preprocess .[sS] files for ${AS}
    148 # CPICFLAGS:		flags for ${CC} to compile .[cC] files to pic objects.
    149 # CSHLIBFLAGS:		flags for ${CC} to compile .[cC] files to .pico objects.
    150 #			(usually includes ${CPICFLAGS})
    151 # CAPICFLAGS:		flags for ${CC} to compiling .[Ss] files
    152 #		 	(usually just ${CPPPICFLAGS} ${CPICFLAGS})
    153 # APICFLAGS:		flags for ${AS} to assemble .[sS] to .pico objects.
    154 
    155 .if ${MACHINE_ARCH} == "alpha"						# {
    156 
    157 FPICFLAGS ?= -fPIC
    158 CPICFLAGS ?= -fPIC -DPIC
    159 CPPPICFLAGS?= -DPIC
    160 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
    161 APICFLAGS ?=
    162 
    163 .elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") 	# } {
    164 
    165 # If you use -fPIC you need to define BIGPIC to turn on 32-bit
    166 # relocations in asm code
    167 FPICFLAGS ?= -fPIC
    168 CPICFLAGS ?= -fPIC -DPIC
    169 CPPPICFLAGS?= -DPIC -DBIGPIC
    170 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
    171 APICFLAGS ?= -KPIC
    172 
    173 .else									# } {
    174 
    175 # Platform-independent flags for NetBSD shared libraries
    176 SHLIB_SOVERSION=${SHLIB_FULLVERSION}
    177 SHLIB_SHFLAGS=
    178 FPICFLAGS ?= -fPIC
    179 CPICFLAGS?= -fPIC -DPIC
    180 CPPPICFLAGS?= -DPIC
    181 CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
    182 APICFLAGS?= -k
    183 
    184 .endif									# }
    185 
    186 .if ${MKPICLIB} != "no"
    187 CSHLIBFLAGS+= ${CPICFLAGS}
    188 .endif
    189 
    190 .if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
    191 MKSHLIBOBJS= yes
    192 .else
    193 MKSHLIBOBJS= no
    194 .endif
    195 
    196 .if (defined(MKDEBUG) && (${MKDEBUG} != "no")) || \
    197     (defined(CFLAGS) && !empty(CFLAGS:M*-g*))
    198 # We only add -g to the shared library objects
    199 # because we don't currently split .a archives.
    200 CSHLIBFLAGS+=	-g
    201 .if ${LIBISPRIVATE} == "yes"
    202 CFLAGS+=	-g
    203 .endif
    204 .endif
    205 
    206 # Platform-independent linker flags for ELF shared libraries
    207 SHLIB_SOVERSION=	${SHLIB_MAJOR}
    208 SHLIB_SHFLAGS=		-Wl,-soname,${_LIB}.so.${SHLIB_SOVERSION}
    209 SHLIB_SHFLAGS+=		-Wl,--warn-shared-textrel
    210 SHLIB_LDSTARTFILE?=	${_GCC_CRTI} ${_GCC_CRTBEGINS}
    211 SHLIB_LDENDFILE?=	${_GCC_CRTENDS} ${_GCC_CRTN}
    212 
    213 CFLAGS+=	${COPTS}
    214 OBJCFLAGS+=	${OBJCOPTS}
    215 AFLAGS+=	${COPTS}
    216 FFLAGS+=	${FOPTS}
    217 
    218 .if defined(CTFCONVERT)
    219 .if defined(CFLAGS) && !empty(CFLAGS:M*-g*)
    220 CTFFLAGS+=	-g
    221 .endif
    222 .endif
    223 
    224 LIBSTRIPAOBJS=	yes
    225 .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
    226 LIBSTRIPCOBJS=	yes
    227 .endif
    228 .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
    229 LIBSTRIPOBJCOBJS=	yes
    230 .endif
    231 .if !defined(FFLAGS) || empty(FFLAGS:M*-g*)
    232 LIBSTRIPFOBJS=	yes
    233 .endif
    234 .if !defined(CSHLIBFLAGS) || empty(CSHLIBFLAGS:M*-g*) 
    235 LIBSTRIPSHLIBOBJS=	yes
    236 .endif
    237 
    238 .c.o:
    239 	${_MKTARGET_COMPILE}
    240 	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    241 .if defined(CTFCONVERT)
    242 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    243 .endif
    244 .if defined(LIBSTRIPCOBJS)
    245 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    246 .endif
    247 
    248 .c.po:
    249 	${_MKTARGET_COMPILE}
    250 	${COMPILE.c} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
    251 .if defined(CTFCONVERT)
    252 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    253 .endif
    254 .if defined(LIBSTRIPCOBJS)
    255 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    256 .endif
    257 
    258 .c.go:
    259 	${_MKTARGET_COMPILE}
    260 	${COMPILE.c} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
    261 
    262 .c.pico:
    263 	${_MKTARGET_COMPILE}
    264 	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
    265 .if defined(LIBSTRIPSHLIBOBJS)
    266 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    267 .endif
    268 
    269 .cc.o .cpp.o .cxx.o .C.o:
    270 	${_MKTARGET_COMPILE}
    271 	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    272 .if defined(LIBSTRIPCOBJS)
    273 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    274 .endif
    275 
    276 .cc.po .cpp.po .cxx.po .C.po:
    277 	${_MKTARGET_COMPILE}
    278 	${COMPILE.cc} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
    279 .if defined(LIBSTRIPCOBJS)
    280 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    281 .endif
    282 
    283 .cc.go .cpp.go .cxx.go .C.go:
    284 	${_MKTARGET_COMPILE}
    285 	${COMPILE.cc} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
    286 
    287 .cc.pico .cpp.pico .cxx.pico .C.pico:
    288 	${_MKTARGET_COMPILE}
    289 	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
    290 .if defined(LIBSTRIPSHLIBOBJS)
    291 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    292 .endif
    293 
    294 .f.o:
    295 	${_MKTARGET_COMPILE}
    296 	${COMPILE.f} ${.IMPSRC} -o ${.TARGET}
    297 .if defined(CTFCONVERT)
    298 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    299 .endif
    300 .if defined(LIBSTRIPFOBJS)
    301 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    302 .endif
    303 
    304 .f.po:
    305 	${_MKTARGET_COMPILE}
    306 	${COMPILE.f} ${PROFFLAGS} -pg ${.IMPSRC} -o ${.TARGET}
    307 .if defined(CTFCONVERT)
    308 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    309 .endif
    310 .if defined(LIBSTRIPFOBJS)
    311 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    312 .endif
    313 
    314 .f.go:
    315 	${_MKTARGET_COMPILE}
    316 	${COMPILE.f} ${DEBUGFLAGS} -g ${.IMPSRC} -o ${.TARGET}
    317 
    318 .f.pico:
    319 	${_MKTARGET_COMPILE}
    320 	${COMPILE.f} ${FPICFLAGS} ${.IMPSRC} -o ${.TARGET}
    321 .if defined(LIBSTRIPFOBJS)
    322 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    323 .endif
    324 
    325 .f.ln:
    326 	${_MKTARGET_COMPILE}
    327 	@echo Skipping lint for Fortran libraries.
    328 
    329 .m.o:
    330 	${_MKTARGET_COMPILE}
    331 	${COMPILE.m} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    332 .if defined(CTFCONVERT)
    333 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    334 .endif
    335 .if defined(LIBSTRIPOBJCOBJS)
    336 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    337 .endif
    338 
    339 .m.po:
    340 	${_MKTARGET_COMPILE}
    341 	${COMPILE.m} ${PROFFLAGS} -pg ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    342 .if defined(CTFCONVERT)
    343 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    344 .endif
    345 .if defined(LIBSTRIPOBJCOBJS)
    346 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    347 .endif
    348 
    349 .m.go:
    350 	${_MKTARGET_COMPILE}
    351 	${COMPILE.m} ${DEBUGFLAGS} -g ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    352 .if defined(LIBSTRIPOBJCOBJS)
    353 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    354 .endif
    355 
    356 .m.pico:
    357 	${_MKTARGET_COMPILE}
    358 	${COMPILE.m} ${CSHLIBFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    359 .if defined(LIBSTRIPOBJCOBJS)
    360 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    361 .endif
    362 
    363 .s.o:
    364 	${_MKTARGET_COMPILE}
    365 	${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    366 .if defined(CTFCONVERT)
    367 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    368 .endif
    369 .if defined(LIBSTRIPAOBJS)
    370 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    371 .endif
    372 
    373 .S.o:
    374 	${_MKTARGET_COMPILE}
    375 	${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    376 .if defined(CTFCONVERT)
    377 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    378 .endif
    379 .if defined(LIBSTRIPAOBJS)
    380 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    381 .endif
    382 
    383 .s.po:
    384 	${_MKTARGET_COMPILE}
    385 	${COMPILE.s} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    386 .if defined(CTFCONVERT)
    387 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    388 .endif
    389 .if defined(LIBSTRIPAOBJS)
    390 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    391 .endif
    392 
    393 .S.po:
    394 	${_MKTARGET_COMPILE}
    395 	${COMPILE.S} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    396 .if defined(CTFCONVERT)
    397 	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    398 .endif
    399 .if defined(LIBSTRIPAOBJS)
    400 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    401 .endif
    402 
    403 .s.go:
    404 	${_MKTARGET_COMPILE}
    405 	${COMPILE.s} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    406 
    407 .S.go:
    408 	${_MKTARGET_COMPILE}
    409 	${COMPILE.S} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    410 
    411 .s.pico:
    412 	${_MKTARGET_COMPILE}
    413 	${COMPILE.s} ${CAPICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    414 .if defined(LIBSTRIPAOBJS)
    415 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    416 .endif
    417 
    418 .S.pico:
    419 	${_MKTARGET_COMPILE}
    420 	${COMPILE.S} ${CAPICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    421 .if defined(LIBSTRIPAOBJS)
    422 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    423 .endif
    424 
    425 # Declare a few variables to make our life easier later.
    426 _LIB:=${_LIB_PREFIX}${LIB}
    427 _LIB.a:=${_LIB}.a
    428 _LIB_p.a:=${_LIB}_p.a
    429 _LIB_g.a:=${_LIB}_g.a
    430 _LIB_pic.a:=${_LIB}_pic.a
    431 _LIB.ln:=llib-l${LIB}.ln
    432 
    433 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    434 _LIB.so:=${_LIB}.so
    435 _LIB.so.major:=${_LIB}.so.${SHLIB_MAJOR}
    436 _LIB.so.full:=${_LIB}.so.${SHLIB_FULLVERSION}
    437 .if ${MKDEBUG} != "no"
    438 _LIB.so.debug:=${_LIB.so.full}.debug
    439 .endif
    440 .endif
    441 
    442 _DEST.LIB:=${DESTDIR}${LIBDIR}
    443 _DEST.OBJ:=${DESTDIR}${_LIBSODIR}
    444 _DEST.LINT:=${DESTDIR}${LINTLIBDIR}
    445 _DEST.DEBUG:=${DESTDIR}${DEBUGDIR}${LIBDIR}
    446 _DEST.ODEBUG:=${DESTDIR}${DEBUGDIR}${_LIBSODIR}
    447 
    448 .if defined(LIB)							# {
    449 .if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
    450 	|| ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
    451 _LIBS=${_LIB.a}
    452 .else
    453 _LIBS=
    454 .endif
    455 
    456 .if ${LIBISPRIVATE} != "no" \
    457    && (defined(USE_COMBINE) && ${USE_COMBINE} == "yes" \
    458    && !defined(NOCOMBINE))						# {
    459 .for f in ${SRCS:N*.h:N*.sh:C/\.[yl]$/.c/g}
    460 COMBINEFLAGS.${LIB}.$f := ${CPPFLAGS.$f:D1} ${CPUFLAGS.$f:D2} ${COPTS.$f:D3} ${OBJCOPTS.$f:D4} ${CXXFLAGS.$f:D5}
    461 .if empty(COMBINEFLAGS.${LIB}.${f}) && !defined(NOCOMBINE.$f)
    462 COMBINESRCS+=	${f}
    463 NODPSRCS+=	${f}
    464 .else
    465 OBJS+=  	${f:R:S/$/.o/}
    466 .endif
    467 .endfor
    468 
    469 .if !empty(COMBINESRCS)
    470 OBJS+=		${_LIB}_combine.o
    471 ${_LIB}_combine.o: ${COMBINESRCS}
    472 	${_MKTARGET_COMPILE}
    473 	${COMPILE.c} -MD --combine ${.ALLSRC} -o ${.TARGET}
    474 .if defined(LIBSTRIPOBJS)
    475 	${OBJCOPY} -x ${.TARGET}
    476 .endif
    477 
    478 CLEANFILES+=	${_LIB}_combine.d
    479 
    480 .if exists("${_LIB}_combine.d")
    481 .include "${_LIB}_combine.d"
    482 .endif
    483 .endif   # empty(XSRCS.${LIB})
    484 .else							# } {
    485 OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
    486 .endif							# }
    487 
    488 STOBJS+=${OBJS}
    489 
    490 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
    491 
    492 .if ${LIBISPRIVATE} != "no"
    493 # No installation is required
    494 libinstall::
    495 .endif
    496 
    497 .if ${MKDEBUGLIB} != "no"
    498 _LIBS+=${_LIB_g.a}
    499 GOBJS+=${OBJS:.o=.go}
    500 DEBUGFLAGS?=-DDEBUG
    501 .endif
    502 
    503 .if ${MKPROFILE} != "no"
    504 _LIBS+=${_LIB_p.a}
    505 POBJS+=${OBJS:.o=.po}
    506 PROFFLAGS?=-DGPROF -DPROF
    507 .endif
    508 
    509 .if ${MKPIC} != "no"							# {
    510 .if ${MKPICLIB} == "no"
    511 .if ${MKSHLIBOBJS} != "no"
    512 # make _pic.a, which isn't really pic,
    513 # since it's needed for making shared lib.
    514 # but don't install it.
    515 SOLIB=${_LIB_pic.a}
    516 SOBJS+=${OBJS:.o=.pico}
    517 .else
    518 SOLIB=${_LIB.a}
    519 .endif
    520 .else
    521 SOLIB=${_LIB_pic.a}
    522 _LIBS+=${SOLIB}
    523 SOBJS+=${OBJS:.o=.pico}
    524 .endif
    525 .if defined(SHLIB_FULLVERSION)
    526 _LIBS+=${_LIB.so.full}
    527 .endif
    528 .endif									# }
    529 
    530 .if ${MKLINT} != "no" && !empty(LOBJS)
    531 _LIBS+=${_LIB.ln}
    532 .endif
    533 
    534 ALLOBJS=
    535 .if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
    536 	|| ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
    537 ALLOBJS+=${STOBJS}
    538 .endif
    539 ALLOBJS+=${POBJS} ${SOBJS}
    540 .if ${MKLINT} != "no" && !empty(LOBJS)
    541 ALLOBJS+=${LOBJS}
    542 .endif
    543 .else	# !defined(LIB)							# } {
    544 LOBJS=
    545 SOBJS=
    546 .endif	# !defined(LIB)							# }
    547 
    548 _YLSRCS=	${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
    549 
    550 .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
    551 
    552 realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.so.debug}
    553 
    554 MKARZERO?=no
    555 
    556 .if ${MKARZERO} == "yes"
    557 _ARFL=crsD
    558 _ARRANFL=sD
    559 _INSTRANLIB=
    560 .else
    561 _ARFL=crs
    562 _ARRANFL=s
    563 _INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
    564 .endif
    565 
    566 # If you change this, please consider reflecting the change in
    567 # the override in sys/rump/Makefile.rump.
    568 .if !target(__archivebuild)
    569 __archivebuild: .USE
    570 	${_MKTARGET_BUILD}
    571 	rm -f ${.TARGET}
    572 	${AR} ${_ARFL} ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
    573 .endif
    574 
    575 .if !target(__archiveinstall)
    576 __archiveinstall: .USE
    577 	${_MKTARGET_INSTALL}
    578 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    579 	    ${_INSTRANLIB} ${.ALLSRC} ${.TARGET}
    580 .endif
    581 
    582 __archivesymlinkpic: .USE
    583 	${_MKTARGET_INSTALL}
    584 	${INSTALL_SYMLINK} ${.ALLSRC} ${.TARGET}
    585 
    586 DPSRCS+=	${_YLSRCS}
    587 CLEANFILES+=	${_YLSRCS}
    588 
    589 ${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
    590 
    591 ${_LIB.a}:: ${STOBJS} __archivebuild
    592 
    593 ${_LIB_p.a}:: ${POBJS} __archivebuild
    594 
    595 ${_LIB_pic.a}:: ${SOBJS} __archivebuild
    596 
    597 ${_LIB_g.a}:: ${GOBJS} __archivebuild
    598 
    599 
    600 _LIBLDOPTS=
    601 .if ${SHLIBDIR} != "/usr/lib"
    602 _LIBLDOPTS+=	-Wl,-rpath,${SHLIBDIR} \
    603 		-L=${SHLIBDIR}
    604 .elif ${SHLIBINSTALLDIR} != "/usr/lib"
    605 _LIBLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
    606 		-L=${SHLIBINSTALLDIR}
    607 .endif
    608 
    609 # gcc -shared now adds -lc automatically. For libraries other than libc and
    610 # libgcc* we add as a dependency the installed shared libc. For libc and
    611 # libgcc* we avoid adding libc as a dependency by using -nostdlib. Note that
    612 # -Xl,-nostdlib is not enough because we want to tell the compiler-driver not
    613 # to add standard libraries, not the linker.
    614 .if !defined(LIB)
    615 .if !empty(LIBC_SO)
    616 DPLIBC ?= ${DESTDIR}${LIBC_SO}
    617 .endif
    618 .else
    619 .if ${LIB} != "c" && ${LIB:Mgcc*} == ""
    620 .if !empty(LIBC_SO)
    621 DPLIBC ?= ${DESTDIR}${LIBC_SO}
    622 .endif
    623 .else
    624 LDLIBC ?= -nodefaultlibs
    625 .if ${LIB} == "c"
    626 LDADD+= -lgcc
    627 .endif
    628 .endif
    629 .endif
    630 
    631 .if ${LIBISCXX} != "no"
    632 LIBCC:=	${CXX}
    633 .else
    634 LIBCC:=	${CC}
    635 .endif
    636 
    637 _LDADD.${_LIB}=	${LDADD} ${LDADD.${_LIB}}
    638 _LDFLAGS.${_LIB}=	${LDFLAGS} ${LDFLAGS.${_LIB}}
    639 
    640 ${_LIB.so.full}: ${SOLIB} ${DPADD} ${DPLIBC} \
    641     ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    642 	${_MKTARGET_BUILD}
    643 	rm -f ${.TARGET}
    644 	${LIBCC} ${LDLIBC} -Wl,-x -shared ${SHLIB_SHFLAGS} \
    645 	    ${_LDFLAGS.${_LIB}} -o ${.TARGET} ${_LIBLDOPTS} \
    646 	    -Wl,--whole-archive ${SOLIB} \
    647 	    -Wl,--no-whole-archive ${_LDADD.${_LIB}}
    648 #  We don't use INSTALL_SYMLINK here because this is just
    649 #  happening inside the build directory/objdir. XXX Why does
    650 #  this spend so much effort on libraries that aren't live??? XXX
    651 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
    652     "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
    653 	${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so.major}.tmp
    654 	mv -f ${_LIB.so.major}.tmp ${_LIB.so.major}
    655 .endif
    656 	${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so}.tmp
    657 	mv -f ${_LIB.so}.tmp ${_LIB.so}
    658 .if ${MKSTRIPIDENT} != "no"
    659 	${OBJCOPY} -R .ident ${.TARGET}
    660 .endif
    661 
    662 .if defined(_LIB.so.debug)
    663 ${_LIB.so.debug}: ${_LIB.so.full}
    664 	${_MKTARGET_CREATE}
    665 	(  ${OBJCOPY} --only-keep-debug ${_LIB.so.full} ${_LIB.so.debug} \
    666 	&& ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
    667 		--add-gnu-debuglink=${_LIB.so.debug} ${_LIB.so.full} \
    668 	) || (rm -f ${.TARGET}; false)
    669 .endif
    670 
    671 .if !empty(LOBJS)							# {
    672 LLIBS?=		-lc
    673 ${_LIB.ln}: ${LOBJS}
    674 	${_MKTARGET_COMPILE}
    675 	rm -f ${.TARGET}
    676 .if defined(DESTDIR)
    677 	${LINT} -C${LIB} ${.ALLSRC} -L${DESTDIR}/usr/libdata ${LLIBS}
    678 .else
    679 	${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
    680 .endif
    681 .endif									# }
    682 
    683 lint: ${LOBJS}
    684 .if defined(LOBJS) && !empty(LOBJS)
    685 	${LINT} ${LINTFLAGS} ${LOBJS}
    686 .endif
    687 
    688 
    689 # If the number of entries in CLEANFILES is too large, then the
    690 # commands in bsd.clean.mk encounter errors like "exec(/bin/sh)
    691 # failed (Argument list too long)".  Avoid that by splitting the
    692 # files to clean into several lists using different variable names.
    693 # __cleanuse is an internal target in bsd.clean.mk; the way we
    694 # use it here mimics the way it's used by the clean target in
    695 # bsd.clean.mk.
    696 #
    697 clean: libclean1 libclean2 libclean3 libclean4 libclean5
    698 libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1
    699 libclean2: .PHONY .MADE __cleanuse LIBCLEANFILES2
    700 libclean3: .PHONY .MADE __cleanuse LIBCLEANFILES3
    701 libclean4: .PHONY .MADE __cleanuse LIBCLEANFILES4
    702 libclean5: .PHONY .MADE __cleanuse LIBCLEANFILES5
    703 CLEANFILES+= a.out [Ee]rrs mklog core *.core
    704 LIBCLEANFILES1+= ${_LIB.a}   ${STOBJS} ${STOBJS:=.tmp}
    705 LIBCLEANFILES2+= ${_LIB_p.a} ${POBJS}  ${POBJS:=.tmp}
    706 LIBCLEANFILES3+= ${_LIB_g.a} ${GOBJS}  ${GOBJS:=.tmp}
    707 LIBCLEANFILES4+= ${_LIB_pic.a}
    708 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    709 LIBCLEANFILES4+= ${_LIB.so}.* ${_LIB.so} ${_LIB.so.debug}
    710 .endif
    711 LIBCLEANFILES4+= ${SOBJS} ${SOBJS:=.tmp}
    712 LIBCLEANFILES5+= ${_LIB.ln} ${LOBJS}
    713 
    714 .if !target(libinstall)							# {
    715 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
    716 libinstall::
    717 
    718 .if ${MKLINKLIB} != "no" && ${MKSTATICLIB} != "no"
    719 libinstall:: ${_DEST.LIB}/${_LIB.a}
    720 .PRECIOUS: ${_DEST.LIB}/${_LIB.a}
    721 
    722 .if ${MKUPDATE} == "no"
    723 .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
    724 ${_DEST.LIB}/${_LIB.a}! .MADE
    725 .endif
    726 ${_DEST.LIB}/${_LIB.a}! ${_LIB.a} __archiveinstall
    727 .else
    728 .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
    729 ${_DEST.LIB}/${_LIB.a}: .MADE
    730 .endif
    731 ${_DEST.LIB}/${_LIB.a}: ${_LIB.a} __archiveinstall
    732 .endif
    733 .endif
    734 
    735 .if ${MKPROFILE} != "no"
    736 libinstall:: ${_DEST.LIB}/${_LIB_p.a}
    737 .PRECIOUS: ${_DEST.LIB}/${_LIB_p.a}
    738 
    739 .if ${MKUPDATE} == "no"
    740 .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
    741 ${_DEST.LIB}/${_LIB_p.a}! .MADE
    742 .endif
    743 ${_DEST.LIB}/${_LIB_p.a}! ${_LIB_p.a} __archiveinstall
    744 .else
    745 .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
    746 ${_DEST.LIB}/${_LIB_p.a}: .MADE
    747 .endif
    748 ${_DEST.LIB}/${_LIB_p.a}: ${_LIB_p.a} __archiveinstall
    749 .endif
    750 .endif
    751 
    752 .if ${MKDEBUGLIB} != "no"
    753 libinstall:: ${_DEST.LIB}/${_LIB_g.a}
    754 .PRECIOUS: ${_DEST.LIB}/${_LIB_g.a}
    755 
    756 .if ${MKUPDATE} == "no"
    757 .if !defined(BUILD) && !make(all) && !make(${_LIB_g.a})
    758 ${_DEST.LIB}/${_LIB_g.a}! .MADE
    759 .endif
    760 ${_DEST.LIB}/${_LIB_g.a}! ${_LIB_g.a} __archiveinstall
    761 .else
    762 .if !defined(BUILD) && !make(all) && !make(${LIB_g.a})
    763 ${_DEST.LIB}/${_LIB_g.a}: .MADE
    764 .endif
    765 ${_DEST.LIB}/${_LIB_g.a}: ${_LIB_g.a} __archiveinstall
    766 .endif
    767 .endif
    768 
    769 .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
    770 libinstall:: ${_DEST.LIB}/${_LIB_pic.a}
    771 .PRECIOUS: ${_DEST.LIB}/${_LIB_pic.a}
    772 
    773 .if ${MKUPDATE} == "no"
    774 .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
    775 ${_DEST.LIB}/${_LIB_pic.a}! .MADE
    776 .endif
    777 .if ${MKPICLIB} == "no"
    778 ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB.a} __archivesymlinkpic
    779 .else
    780 ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB_pic.a} __archiveinstall
    781 .endif
    782 .else
    783 .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
    784 ${_DEST.LIB}/${_LIB_pic.a}: .MADE
    785 .endif
    786 .if ${MKPICLIB} == "no"
    787 ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB.a} __archivesymlinkpic
    788 .else
    789 ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB_pic.a} __archiveinstall
    790 .endif
    791 .endif
    792 .endif
    793 
    794 .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    795 
    796 libinstall:: ${_DEST.OBJ}/${_LIB.so.full}
    797 .PRECIOUS: ${_DEST.OBJ}/${_LIB.so.full}
    798 
    799 .if ${MKUPDATE} == "no"
    800 .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
    801 ${_DEST.OBJ}/${_LIB.so.full}! .MADE
    802 .endif
    803 ${_DEST.OBJ}/${_LIB.so.full}! ${_LIB.so.full}
    804 .else
    805 .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
    806 ${_DEST.OBJ}/${_LIB.so.full}: .MADE
    807 .endif
    808 ${_DEST.OBJ}/${_LIB.so.full}: ${_LIB.so.full}
    809 .endif
    810 	${_MKTARGET_INSTALL}
    811 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    812 	    ${.ALLSRC} ${.TARGET}
    813 .if ${_LIBSODIR} != ${LIBDIR}
    814 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    815 	    ${_DEST.LIB}/${_LIB.so.full} 
    816 .endif
    817 .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
    818     "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
    819 	${INSTALL_SYMLINK} ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so.major}
    820 .if ${_LIBSODIR} != ${LIBDIR}
    821 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    822 	    ${_DEST.LIB}/${_LIB.so.major}
    823 .endif
    824 .endif
    825 .if ${MKLINKLIB} != "no"
    826 	${INSTALL_SYMLINK}  ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so}
    827 .if ${_LIBSODIR} != ${LIBDIR}
    828 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    829 	    ${_DEST.LIB}/${_LIB.so}
    830 .endif
    831 .endif
    832 .endif
    833 
    834 .if defined(_LIB.so.debug)
    835 libinstall:: ${_DEST.DEBUG}/${_LIB.so.debug}
    836 .PRECIOUS: ${_DEST.DEBUG}/${_LIB.so.debug}
    837 
    838 ${_DEST.DEBUG}/${_LIB.so.debug}: ${_LIB.so.debug}
    839 	${_MKTARGET_INSTALL}
    840 	${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
    841 	    ${.ALLSRC} ${.TARGET}
    842 .if ${_LIBSODIR} != ${LIBDIR}
    843 	${INSTALL_SYMLINK} -l r ${_DEST.DEBUG}/${_LIB.so.debug} \
    844 	    ${_DEST.ODEBUG}/${_LIB.so.debug} 
    845 .endif
    846 .endif
    847 
    848 .if ${MKLINT} != "no" && !empty(LOBJS)
    849 libinstall:: ${_DEST.LINT}/${_LIB.ln}
    850 .PRECIOUS: ${_DEST.LINT}/${_LIB.ln}
    851 
    852 .if ${MKUPDATE} == "no"
    853 .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
    854 ${_DEST.LINT}/${_LIB.ln}! .MADE
    855 .endif
    856 ${_DEST.LINT}/${_LIB.ln}! ${_LIB.ln}
    857 .else
    858 .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
    859 ${_DEST.LINT}/${_LIB.ln}: .MADE
    860 .endif
    861 ${_DEST.LINT}/${_LIB.ln}: ${_LIB.ln}
    862 .endif
    863 	${_MKTARGET_INSTALL}
    864 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    865 		${.ALLSRC} ${_DEST.LINT}
    866 .endif
    867 .endif	# !target(libinstall)						# }
    868 
    869 ##### Pull in related .mk logic
    870 LINKSOWN?= ${LIBOWN}
    871 LINKSGRP?= ${LIBGRP}
    872 LINKSMODE?= ${LIBMODE}
    873 .include <bsd.man.mk>
    874 .include <bsd.nls.mk>
    875 .include <bsd.files.mk>
    876 .include <bsd.inc.mk>
    877 .include <bsd.links.mk>
    878 .include <bsd.dep.mk>
    879 .include <bsd.clang-analyze.mk>
    880 .include <bsd.clean.mk>
    881 
    882 ${TARGETS}:	# ensure existence
    883