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