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