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