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