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