Home | History | Annotate | Line # | Download | only in mk
bsd.lib.mk revision 1.405.2.2
      1  1.405.2.2  perseant #	$NetBSD: bsd.lib.mk,v 1.405.2.2 2025/08/02 05:55:18 perseant Exp $
      2       1.92     mikel #	@(#)bsd.lib.mk	8.3 (Berkeley) 4/22/94
      3        1.1       cgd 
      4      1.188        tv .include <bsd.init.mk>
      5      1.207   thorpej .include <bsd.shlib.mk>
      6      1.219   thorpej .include <bsd.gcc.mk>
      7      1.380     kamil .include <bsd.sanitizer.mk>
      8      1.376     kamil 
      9      1.227     lukem # Pull in <bsd.sys.mk> here so we can override its .c.o rule
     10      1.227     lukem .include <bsd.sys.mk>
     11       1.97   mycroft 
     12      1.282     lukem LIBISMODULE?=	no
     13      1.281     lukem LIBISPRIVATE?=	no
     14      1.291       mrg LIBISCXX?=	no
     15      1.281     lukem 
     16      1.282     lukem .if ${LIBISMODULE} != "no"
     17      1.330  christos _LIB_PREFIX?=	# empty
     18      1.282     lukem MKDEBUGLIB:=	no
     19      1.400  christos MKPROFILE:=	no
     20      1.399  christos MKPICINSTALL:=	no
     21      1.400  christos MAKESTATICLIB?=	no
     22      1.400  christos MAKELINKLIB?=	yes
     23      1.388  christos _LINTINSTALL?=	no
     24      1.330  christos .else
     25      1.330  christos _LIB_PREFIX?=	lib
     26      1.282     lukem .endif
     27      1.282     lukem 
     28      1.281     lukem .if ${LIBISPRIVATE} != "no"
     29      1.280     lukem MKDEBUGLIB:=	no
     30      1.400  christos MKPROFILE:=	no
     31      1.290      cube MKPICINSTALL:=	no
     32      1.290      cube . if defined(NOSTATICLIB) && ${MKPICLIB} != "no"
     33      1.400  christos MAKESTATICLIB?=	no
     34      1.383  christos . elif ${LIBISPRIVATE} != "pic"
     35      1.280     lukem MKPIC:=		no
     36      1.290      cube . endif
     37      1.400  christos MAKELINKLIB?=	no
     38      1.388  christos _LINTINSTALL?=	no
     39      1.280     lukem .endif
     40      1.280     lukem 
     41      1.388  christos _LINTINSTALL?=	${MKLINT}
     42      1.400  christos LINKINSTALL?=	${MAKELINKLIB}
     43      1.400  christos MAKELINKLIB?=	${MKLINKLIB}
     44      1.400  christos MAKESTATICLIB?=	${MKSTATICLIB}
     45      1.388  christos 
     46      1.188        tv ##### Basic targets
     47      1.246     lukem .PHONY:		checkver libinstall
     48      1.143       erh realinstall:	checkver libinstall
     49      1.232       erh 
     50      1.232       erh ##### LIB specific flags.
     51      1.287  christos # XXX: This is needed for programs that link with .a libraries
     52      1.287  christos # Perhaps a more correct solution is to always generate _pic.a
     53      1.287  christos # files or always have a shared library.
     54      1.371  christos # Another fix is to provide rcrt0.o like OpenBSD does and
     55      1.371  christos # do relocations for static PIE.
     56      1.366  christos .if defined(MKPIE) && (${MKPIE} != "no") && !defined(NOPIE)
     57      1.366  christos CFLAGS+=        ${PIE_CFLAGS}
     58      1.366  christos AFLAGS+=        ${PIE_AFLAGS}
     59      1.366  christos .endif
     60  1.405.2.2  perseant # The -fPIC is needed for libraries that include other libraries
     61  1.405.2.2  perseant # The order matters here, PIC needs to be last
     62  1.405.2.2  perseant .if ${LIBISPRIVATE} == "pic" && ${MKPIC} != "no"
     63  1.405.2.2  perseant CFLAGS+=        -fPIC
     64  1.405.2.2  perseant AFLAGS+=        -fPIC
     65  1.405.2.2  perseant .endif
     66        1.1       cgd 
     67      1.387       ryo PGFLAGS+=	-pg
     68      1.378  christos .if ${MKPIC} != "no"
     69      1.378  christos PGFLAGS+=	-fPIC
     70      1.378  christos .endif
     71      1.378  christos 
     72      1.256     lukem ##### Libraries that this may depend upon.
     73      1.256     lukem .if defined(LIBDPLIBS) && ${MKPIC} != "no"				# {
     74  1.405.2.2  perseant .  for _lib _dir in ${LIBDPLIBS}
     75  1.405.2.2  perseant .    if !defined(LIBDO.${_lib})
     76      1.303  christos LIBDO.${_lib}!=	cd "${_dir}" && ${PRINTOBJDIR}
     77      1.256     lukem .MAKEOVERRIDES+=LIBDO.${_lib}
     78  1.405.2.2  perseant .    endif
     79  1.405.2.2  perseant .    if ${LIBDO.${_lib}} == "_external"
     80      1.325     pooka LDADD+=		-l${_lib}
     81  1.405.2.2  perseant .    else
     82      1.256     lukem LDADD+=		-L${LIBDO.${_lib}} -l${_lib}
     83  1.405.2.2  perseant .      if exists(${LIBDO.${_lib}}/lib${_lib}_pic.a)
     84      1.391  christos DPADD+=         ${LIBDO.${_lib}}/lib${_lib}_pic.a
     85  1.405.2.2  perseant .      elif exists(${LIBDO.${_lib}}/lib${_lib}.so)
     86      1.391  christos DPADD+=         ${LIBDO.${_lib}}/lib${_lib}.so
     87  1.405.2.2  perseant .      else
     88      1.391  christos DPADD+=         ${LIBDO.${_lib}}/lib${_lib}.a
     89  1.405.2.2  perseant .      endif
     90  1.405.2.2  perseant .    endif
     91  1.405.2.2  perseant .  endfor
     92      1.256     lukem .endif									# }
     93      1.256     lukem 
     94      1.188        tv ##### Build and install rules
     95      1.356       erh MKDEP_SUFFIXES?=	.o .po .pico .go .ln .d
     96      1.292     pooka 
     97      1.252     lukem .if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE})		# {
     98      1.154    simonb SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
     99      1.154    simonb SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
    100      1.171  christos SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
    101      1.143       erh 
    102      1.295        he DPADD+=	${SHLIB_VERSION_FILE}
    103      1.295        he 
    104      1.143       erh # Check for higher installed library versions.
    105      1.145       erh .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
    106      1.201     lukem 	exists(${NETBSDSRCDIR}/lib/checkver)
    107      1.143       erh checkver:
    108      1.303  christos 	@(cd "${.CURDIR}" && \
    109      1.289       apb 	    HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \
    110      1.239     lukem 	    ${HOST_SH} ${NETBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
    111      1.327  christos 		    -d ${_DEST.OBJ} ${LIB})
    112      1.173  christos .endif
    113      1.252     lukem .endif									# }
    114      1.173  christos 
    115      1.173  christos .if !target(checkver)
    116      1.143       erh checkver:
    117      1.143       erh .endif
    118      1.173  christos 
    119      1.169   thorpej print-shlib-major:
    120      1.185        tv .if defined(SHLIB_MAJOR) && ${MKPIC} != "no"
    121      1.169   thorpej 	@echo ${SHLIB_MAJOR}
    122      1.173  christos .else
    123      1.173  christos 	@false
    124      1.173  christos .endif
    125      1.169   thorpej 
    126      1.169   thorpej print-shlib-minor:
    127      1.185        tv .if defined(SHLIB_MINOR) && ${MKPIC} != "no"
    128      1.169   thorpej 	@echo ${SHLIB_MINOR}
    129      1.173  christos .else
    130      1.173  christos 	@false
    131      1.173  christos .endif
    132      1.171  christos 
    133      1.171  christos print-shlib-teeny:
    134      1.185        tv .if defined(SHLIB_TEENY) && ${MKPIC} != "no"
    135      1.171  christos 	@echo ${SHLIB_TEENY}
    136      1.143       erh .else
    137      1.169   thorpej 	@false
    138      1.173  christos .endif
    139      1.169   thorpej 
    140      1.383  christos .if ${LIBISPRIVATE} == "no"
    141      1.252     lukem .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR)				# {
    142      1.173  christos .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
    143      1.173  christos .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
    144      1.173  christos SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
    145      1.173  christos .else
    146      1.173  christos SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
    147      1.173  christos .endif
    148      1.173  christos .else
    149      1.173  christos SHLIB_FULLVERSION=${SHLIB_MAJOR}
    150      1.173  christos .endif
    151      1.252     lukem .endif									# }
    152      1.383  christos .endif
    153        1.1       cgd 
    154      1.101   mycroft # add additional suffixes not exported.
    155      1.101   mycroft # .po is used for profiling object files.
    156      1.304     njoly # .pico is used for PIC object files.
    157      1.304     njoly .SUFFIXES: .out .a .ln .pico .po .go .o .s .S .c .cc .cpp .cxx .C .m .F .f .r .y .l .cl .p .h
    158      1.118     lukem .SUFFIXES: .sh .m4 .m
    159       1.82     mikel 
    160       1.86  jonathan 
    161       1.86  jonathan # Set PICFLAGS to cc flags for producing position-independent code,
    162      1.338     joerg # if not already set.
    163       1.86  jonathan 
    164      1.164    simonb # Data-driven table using make variables to control how shared libraries
    165       1.86  jonathan # are built for different platforms and object formats.
    166      1.302       abs # SHLIB_MAJOR, SHLIB_MINOR, SHLIB_TEENY: Major, minor, and teeny version
    167      1.302       abs #			numbers of shared library
    168      1.164    simonb # SHLIB_SOVERSION:	version number to be compiled into a shared library
    169      1.385    andvar #			via -soname. Usually ${SHLIB_MAJOR} on ELF.
    170      1.173  christos #			NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
    171      1.173  christos #			[.${SHLIB_TEENY}]]
    172      1.164    simonb # SHLIB_SHFLAGS:	Flags to tell ${LD} to emit shared library.
    173      1.123  jonathan #			with ELF, also set shared-lib version for ld.so.
    174      1.123  jonathan # SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
    175      1.123  jonathan # SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
    176       1.86  jonathan 
    177      1.338     joerg PICFLAGS ?= -fPIC
    178      1.160    simonb 
    179      1.205      yamt .if ${MKPICLIB} != "no"
    180      1.377     kamil CSHLIBFLAGS+= ${PICFLAGS} ${SANITIZERFLAGS} ${LIBCSANITIZERFLAGS}
    181      1.205      yamt .endif
    182      1.205      yamt 
    183      1.205      yamt .if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
    184      1.205      yamt MKSHLIBOBJS= yes
    185      1.205      yamt .else
    186      1.205      yamt MKSHLIBOBJS= no
    187      1.205      yamt .endif
    188      1.205      yamt 
    189      1.390       mrg # Avoid adding "-g" if we already have a "-g*" option.
    190      1.390       mrg .if (${MKDEBUG:Uno} != "no" && !defined(NODEBUG)) && \
    191      1.390       mrg     (!defined(CFLAGS) || empty(CFLAGS:M-g*)) && \
    192      1.390       mrg     (!defined(CXXFLAGS) || empty(CXXFLAGS:M-g*))
    193      1.335  riastrad # We only add -g to the shared library objects
    194      1.335  riastrad # because we don't currently split .a archives.
    195      1.335  riastrad CSHLIBFLAGS+=	-g
    196      1.383  christos .if ${LIBISPRIVATE} != "no"
    197      1.335  riastrad CFLAGS+=	-g
    198      1.335  riastrad .endif
    199      1.335  riastrad .endif
    200      1.335  riastrad 
    201      1.123  jonathan # Platform-independent linker flags for ELF shared libraries
    202      1.182       mrg SHLIB_SOVERSION=	${SHLIB_MAJOR}
    203      1.327  christos SHLIB_SHFLAGS=		-Wl,-soname,${_LIB}.so.${SHLIB_SOVERSION}
    204      1.375     kamil SHLIB_SHFLAGS+=		${SANITIZERFLAGS}
    205      1.354     pooka .if !defined(SHLIB_WARNTEXTREL) || ${SHLIB_WARNTEXTREL} != "no"
    206      1.272  christos SHLIB_SHFLAGS+=		-Wl,--warn-shared-textrel
    207      1.354     pooka .endif
    208      1.337     pooka .if !defined(SHLIB_MKMAP) || ${SHLIB_MKMAP} != "no"
    209      1.336      matt SHLIB_SHFLAGS+=		-Wl,-Map=${_LIB}.so.${SHLIB_SOVERSION}.map
    210      1.337     pooka .endif
    211      1.336      matt CLEANFILES+=		${_LIB}.so.${SHLIB_SOVERSION}.map
    212      1.322  christos SHLIB_LDSTARTFILE?=	${_GCC_CRTI} ${_GCC_CRTBEGINS}
    213      1.322  christos SHLIB_LDENDFILE?=	${_GCC_CRTENDS} ${_GCC_CRTN}
    214       1.86  jonathan 
    215       1.82     mikel CFLAGS+=	${COPTS}
    216      1.267       mrg OBJCFLAGS+=	${OBJCOPTS}
    217      1.257    simonb AFLAGS+=	${COPTS}
    218      1.179  dmcmahil FFLAGS+=	${FOPTS}
    219        1.1       cgd 
    220      1.305    darran .if defined(CTFCONVERT)
    221      1.305    darran .if defined(CFLAGS) && !empty(CFLAGS:M*-g*)
    222      1.305    darran CTFFLAGS+=	-g
    223      1.367       mrg .if defined(HAVE_GCC)
    224      1.348  christos #CFLAGS+=	-gdwarf-2
    225      1.347  christos .endif
    226      1.305    darran .endif
    227      1.305    darran .endif
    228      1.305    darran 
    229      1.333  christos LIBSTRIPAOBJS=	yes
    230      1.333  christos .if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
    231      1.333  christos LIBSTRIPCOBJS=	yes
    232      1.333  christos .endif
    233      1.333  christos .if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
    234      1.333  christos LIBSTRIPOBJCOBJS=	yes
    235      1.333  christos .endif
    236      1.333  christos .if !defined(FFLAGS) || empty(FFLAGS:M*-g*)
    237      1.333  christos LIBSTRIPFOBJS=	yes
    238      1.333  christos .endif
    239      1.392  riastrad .if !defined(CSHLIBFLAGS) || empty(CSHLIBFLAGS:M*-g*)
    240      1.333  christos LIBSTRIPSHLIBOBJS=	yes
    241      1.333  christos .endif
    242      1.333  christos 
    243        1.1       cgd .c.o:
    244      1.238     lukem 	${_MKTARGET_COMPILE}
    245      1.384  christos 	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    246      1.384  christos 	${CTFCONVERT_RUN}
    247      1.333  christos .if defined(LIBSTRIPCOBJS)
    248      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    249      1.153  christos .endif
    250        1.1       cgd 
    251        1.1       cgd .c.po:
    252      1.238     lukem 	${_MKTARGET_COMPILE}
    253      1.384  christos 	${COMPILE.c} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${PGFLAGS} ${.IMPSRC} ${OBJECT_TARGET}
    254      1.384  christos 	${CTFCONVERT_RUN}
    255      1.333  christos .if defined(LIBSTRIPCOBJS)
    256      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    257      1.153  christos .endif
    258       1.17   mycroft 
    259      1.266  christos .c.go:
    260      1.266  christos 	${_MKTARGET_COMPILE}
    261      1.266  christos 	${COMPILE.c} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
    262      1.266  christos 
    263      1.304     njoly .c.pico:
    264      1.238     lukem 	${_MKTARGET_COMPILE}
    265      1.263       dsl 	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
    266      1.333  christos .if defined(LIBSTRIPSHLIBOBJS)
    267      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    268      1.153  christos .endif
    269       1.27        pk 
    270      1.223     lukem .cc.o .cpp.o .cxx.o .C.o:
    271      1.238     lukem 	${_MKTARGET_COMPILE}
    272      1.263       dsl 	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    273      1.333  christos .if defined(LIBSTRIPCOBJS)
    274      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    275      1.153  christos .endif
    276       1.17   mycroft 
    277      1.266  christos .cc.po .cpp.po .cxx.po .C.po:
    278      1.238     lukem 	${_MKTARGET_COMPILE}
    279      1.378  christos 	${COMPILE.cc} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${PGFLAGS} ${.IMPSRC} -o ${.TARGET}
    280      1.333  christos .if defined(LIBSTRIPCOBJS)
    281      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    282      1.153  christos .endif
    283       1.28       cgd 
    284      1.266  christos .cc.go .cpp.go .cxx.go .C.go:
    285      1.266  christos 	${_MKTARGET_COMPILE}
    286      1.266  christos 	${COMPILE.cc} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
    287      1.266  christos 
    288      1.304     njoly .cc.pico .cpp.pico .cxx.pico .C.pico:
    289      1.238     lukem 	${_MKTARGET_COMPILE}
    290      1.263       dsl 	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
    291      1.333  christos .if defined(LIBSTRIPSHLIBOBJS)
    292      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    293      1.153  christos .endif
    294      1.118     lukem 
    295      1.179  dmcmahil .f.o:
    296      1.238     lukem 	${_MKTARGET_COMPILE}
    297      1.384  christos 	${COMPILE.f} ${.IMPSRC} ${OBJECT_TARGET}
    298      1.384  christos 	${CTFCONVERT_RUN}
    299      1.333  christos .if defined(LIBSTRIPFOBJS)
    300      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    301      1.179  dmcmahil .endif
    302      1.179  dmcmahil 
    303      1.179  dmcmahil .f.po:
    304      1.238     lukem 	${_MKTARGET_COMPILE}
    305      1.384  christos 	${COMPILE.f} ${PROFFLAGS} ${PGFLAGS} ${.IMPSRC} ${OBJECT_TARGET}
    306      1.384  christos 	${CTFCONVERT_RUN}
    307      1.333  christos .if defined(LIBSTRIPFOBJS)
    308      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    309      1.179  dmcmahil .endif
    310      1.179  dmcmahil 
    311      1.266  christos .f.go:
    312      1.266  christos 	${_MKTARGET_COMPILE}
    313      1.266  christos 	${COMPILE.f} ${DEBUGFLAGS} -g ${.IMPSRC} -o ${.TARGET}
    314      1.266  christos 
    315      1.304     njoly .f.pico:
    316      1.238     lukem 	${_MKTARGET_COMPILE}
    317      1.338     joerg 	${COMPILE.f} ${PICFLAGS} ${.IMPSRC} -o ${.TARGET}
    318      1.333  christos .if defined(LIBSTRIPFOBJS)
    319      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    320      1.179  dmcmahil .endif
    321      1.179  dmcmahil 
    322      1.179  dmcmahil .f.ln:
    323      1.238     lukem 	${_MKTARGET_COMPILE}
    324      1.217       wiz 	@echo Skipping lint for Fortran libraries.
    325      1.179  dmcmahil 
    326      1.118     lukem .m.o:
    327      1.238     lukem 	${_MKTARGET_COMPILE}
    328      1.384  christos 	${COMPILE.m} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    329      1.384  christos 	${CTFCONVERT_RUN}
    330      1.333  christos .if defined(LIBSTRIPOBJCOBJS)
    331      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    332      1.153  christos .endif
    333      1.118     lukem 
    334      1.118     lukem .m.po:
    335      1.238     lukem 	${_MKTARGET_COMPILE}
    336      1.384  christos 	${COMPILE.m} ${PROFFLAGS} ${PGFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    337      1.384  christos 	${CTFCONVERT_RUN}
    338      1.333  christos .if defined(LIBSTRIPOBJCOBJS)
    339      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    340      1.153  christos .endif
    341      1.118     lukem 
    342      1.266  christos .m.go:
    343      1.266  christos 	${_MKTARGET_COMPILE}
    344      1.267       mrg 	${COMPILE.m} ${DEBUGFLAGS} -g ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    345      1.333  christos .if defined(LIBSTRIPOBJCOBJS)
    346      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    347      1.266  christos .endif
    348      1.266  christos 
    349      1.304     njoly .m.pico:
    350      1.238     lukem 	${_MKTARGET_COMPILE}
    351      1.267       mrg 	${COMPILE.m} ${CSHLIBFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    352      1.333  christos .if defined(LIBSTRIPOBJCOBJS)
    353      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    354      1.153  christos .endif
    355        1.1       cgd 
    356      1.251     lukem .s.o:
    357      1.238     lukem 	${_MKTARGET_COMPILE}
    358      1.384  christos 	${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    359      1.384  christos 	${CTFCONVERT_RUN}
    360      1.333  christos .if defined(LIBSTRIPAOBJS)
    361      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    362      1.333  christos .endif
    363        1.1       cgd 
    364      1.251     lukem .S.o:
    365      1.251     lukem 	${_MKTARGET_COMPILE}
    366      1.384  christos 	${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    367      1.384  christos 	${CTFCONVERT_RUN}
    368      1.333  christos .if defined(LIBSTRIPAOBJS)
    369      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    370      1.333  christos .endif
    371      1.251     lukem 
    372      1.251     lukem .s.po:
    373      1.251     lukem 	${_MKTARGET_COMPILE}
    374      1.384  christos 	${COMPILE.s} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    375      1.384  christos 	${CTFCONVERT_RUN}
    376      1.333  christos .if defined(LIBSTRIPAOBJS)
    377      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    378      1.333  christos .endif
    379      1.251     lukem 
    380      1.251     lukem .S.po:
    381      1.238     lukem 	${_MKTARGET_COMPILE}
    382      1.384  christos 	${COMPILE.S} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
    383      1.384  christos 	${CTFCONVERT_RUN}
    384      1.333  christos .if defined(LIBSTRIPAOBJS)
    385      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    386      1.333  christos .endif
    387        1.1       cgd 
    388      1.266  christos .s.go:
    389      1.266  christos 	${_MKTARGET_COMPILE}
    390      1.266  christos 	${COMPILE.s} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    391      1.266  christos 
    392      1.266  christos .S.go:
    393      1.266  christos 	${_MKTARGET_COMPILE}
    394      1.266  christos 	${COMPILE.S} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    395      1.266  christos 
    396      1.304     njoly .s.pico:
    397      1.251     lukem 	${_MKTARGET_COMPILE}
    398      1.338     joerg 	${COMPILE.s} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    399      1.333  christos .if defined(LIBSTRIPAOBJS)
    400      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    401      1.333  christos .endif
    402      1.251     lukem 
    403      1.304     njoly .S.pico:
    404      1.238     lukem 	${_MKTARGET_COMPILE}
    405      1.338     joerg 	${COMPILE.S} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
    406      1.333  christos .if defined(LIBSTRIPAOBJS)
    407      1.320  christos 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
    408      1.333  christos .endif
    409       1.27        pk 
    410      1.327  christos # Declare a few variables to make our life easier later.
    411      1.327  christos _LIB:=${_LIB_PREFIX}${LIB}
    412      1.327  christos _LIB.a:=${_LIB}.a
    413      1.327  christos _LIB_p.a:=${_LIB}_p.a
    414      1.327  christos _LIB_g.a:=${_LIB}_g.a
    415      1.327  christos _LIB_pic.a:=${_LIB}_pic.a
    416      1.327  christos _LIB.ln:=llib-l${LIB}.ln
    417      1.327  christos 
    418      1.327  christos .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    419      1.327  christos _LIB.so:=${_LIB}.so
    420      1.327  christos _LIB.so.major:=${_LIB}.so.${SHLIB_MAJOR}
    421      1.327  christos _LIB.so.full:=${_LIB}.so.${SHLIB_FULLVERSION}
    422      1.358       mrg _LIB.so.link:=${_LIB}.so.${SHLIB_FULLVERSION}.link
    423      1.364  christos .if ${MKDEBUG:Uno} != "no" && !defined(NODEBUG)
    424      1.327  christos _LIB.so.debug:=${_LIB.so.full}.debug
    425      1.327  christos .endif
    426      1.327  christos .endif
    427      1.327  christos 
    428      1.327  christos _DEST.LIB:=${DESTDIR}${LIBDIR}
    429      1.327  christos _DEST.OBJ:=${DESTDIR}${_LIBSODIR}
    430      1.327  christos _DEST.LINT:=${DESTDIR}${LINTLIBDIR}
    431      1.327  christos _DEST.DEBUG:=${DESTDIR}${DEBUGDIR}${LIBDIR}
    432      1.334  christos _DEST.ODEBUG:=${DESTDIR}${DEBUGDIR}${_LIBSODIR}
    433      1.327  christos 
    434      1.402  christos .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
    435      1.401  christos     || ${MAKELINKLIB} != "no" || ${MAKESTATICLIB} != "no"
    436      1.402  christos _BUILDSTATICLIB=yes
    437      1.402  christos .else
    438      1.402  christos _BUILDSTATICLIB=no
    439      1.402  christos .endif
    440      1.401  christos 
    441      1.252     lukem .if defined(LIB)							# {
    442      1.402  christos .if ${_BUILDSTATICLIB} != "no"
    443      1.327  christos _LIBS=${_LIB.a}
    444      1.130        tv .else
    445      1.130        tv _LIBS=
    446      1.130        tv .endif
    447       1.58       cgd 
    448      1.167      matt OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
    449      1.158  christos 
    450      1.255   thorpej STOBJS+=${OBJS}
    451      1.255   thorpej 
    452      1.280     lukem LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
    453      1.280     lukem 
    454      1.281     lukem .if ${LIBISPRIVATE} != "no"
    455      1.252     lukem # No installation is required
    456      1.252     lukem libinstall::
    457      1.306     lukem .endif
    458      1.252     lukem 
    459      1.268     lukem .if ${MKDEBUGLIB} != "no"
    460      1.327  christos _LIBS+=${_LIB_g.a}
    461      1.266  christos GOBJS+=${OBJS:.o=.go}
    462      1.266  christos DEBUGFLAGS?=-DDEBUG
    463      1.266  christos .endif
    464      1.266  christos 
    465      1.149     lukem .if ${MKPROFILE} != "no"
    466      1.327  christos _LIBS+=${_LIB_p.a}
    467      1.167      matt POBJS+=${OBJS:.o=.po}
    468      1.262  christos PROFFLAGS?=-DGPROF -DPROF
    469        1.1       cgd .endif
    470        1.1       cgd 
    471      1.252     lukem .if ${MKPIC} != "no"							# {
    472      1.160    simonb .if ${MKPICLIB} == "no"
    473      1.205      yamt .if ${MKSHLIBOBJS} != "no"
    474      1.205      yamt # make _pic.a, which isn't really pic,
    475      1.205      yamt # since it's needed for making shared lib.
    476      1.205      yamt # but don't install it.
    477      1.327  christos SOLIB=${_LIB_pic.a}
    478      1.304     njoly SOBJS+=${OBJS:.o=.pico}
    479      1.205      yamt .else
    480      1.327  christos SOLIB=${_LIB.a}
    481      1.205      yamt .endif
    482      1.160    simonb .else
    483      1.327  christos SOLIB=${_LIB_pic.a}
    484      1.160    simonb _LIBS+=${SOLIB}
    485      1.304     njoly SOBJS+=${OBJS:.o=.pico}
    486      1.160    simonb .endif
    487      1.171  christos .if defined(SHLIB_FULLVERSION)
    488      1.327  christos _LIBS+=${_LIB.so.full}
    489       1.27        pk .endif
    490      1.252     lukem .endif									# }
    491       1.27        pk 
    492      1.279     lukem .if ${MKLINT} != "no" && !empty(LOBJS)
    493      1.327  christos _LIBS+=${_LIB.ln}
    494      1.215  christos .endif
    495       1.27        pk 
    496      1.234     lukem ALLOBJS=
    497      1.402  christos .if ${_BUILDSTATICLIB} != "no"
    498      1.255   thorpej ALLOBJS+=${STOBJS}
    499      1.179  dmcmahil .endif
    500      1.234     lukem ALLOBJS+=${POBJS} ${SOBJS}
    501      1.279     lukem .if ${MKLINT} != "no" && !empty(LOBJS)
    502      1.179  dmcmahil ALLOBJS+=${LOBJS}
    503      1.216  christos .endif
    504      1.252     lukem .else	# !defined(LIB)							# } {
    505      1.216  christos LOBJS=
    506      1.216  christos SOBJS=
    507      1.252     lukem .endif	# !defined(LIB)							# }
    508      1.186        tv 
    509      1.254     lukem _YLSRCS=	${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
    510      1.253  christos 
    511      1.253  christos .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
    512      1.158  christos 
    513      1.327  christos realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.so.debug}
    514        1.1       cgd 
    515      1.296     perry .if ${MKARZERO} == "yes"
    516      1.296     perry _ARFL=crsD
    517      1.297     perry _ARRANFL=sD
    518      1.296     perry _INSTRANLIB=
    519      1.296     perry .else
    520      1.296     perry _ARFL=crs
    521      1.297     perry _ARRANFL=s
    522      1.296     perry _INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
    523      1.296     perry .endif
    524      1.296     perry 
    525      1.293     pooka # If you change this, please consider reflecting the change in
    526      1.293     pooka # the override in sys/rump/Makefile.rump.
    527      1.243       rtr .if !target(__archivebuild)
    528       1.90  christos __archivebuild: .USE
    529      1.238     lukem 	${_MKTARGET_BUILD}
    530      1.373  christos 	@rm -f ${.TARGET}
    531      1.389  christos 	${AR} ${_ARFL} ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT})
    532      1.243       rtr .endif
    533       1.89  christos 
    534      1.243       rtr .if !target(__archiveinstall)
    535       1.89  christos __archiveinstall: .USE
    536      1.238     lukem 	${_MKTARGET_INSTALL}
    537      1.198     lukem 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    538      1.296     perry 	    ${_INSTRANLIB} ${.ALLSRC} ${.TARGET}
    539      1.243       rtr .endif
    540       1.89  christos 
    541      1.197   mycroft __archivesymlinkpic: .USE
    542      1.238     lukem 	${_MKTARGET_INSTALL}
    543      1.264     jwise 	${INSTALL_SYMLINK} ${.ALLSRC} ${.TARGET}
    544      1.197   mycroft 
    545      1.373  christos .if !target(__buildstdlib)
    546      1.373  christos __buildstdlib: .USE
    547      1.373  christos 	@echo building standard ${.TARGET:T:S/.o//:S/lib//} library
    548      1.373  christos 	@rm -f ${.TARGET}
    549      1.389  christos 	@${LINK.c:S/-nostdinc//} -nostdlib ${LDFLAGS} -Wno-unused-command-line-argument -r -o ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT})
    550      1.373  christos .endif
    551      1.373  christos 
    552      1.373  christos .if !target(__buildproflib)
    553      1.373  christos __buildproflib: .USE
    554      1.373  christos 	@echo building profiled ${.TARGET:T:S/.o//:S/lib//} library
    555      1.373  christos 	${_MKTARGET_BUILD}
    556      1.373  christos 	@rm -f ${.TARGET}
    557      1.389  christos 	@${LINK.c:S/-nostdinc//} -nostdlib ${LDFLAGS} -r -o ${.TARGET} $$(NM=${NM} ${LORDER} ${.ALLSRC:M*po} | ${TSORT})
    558      1.373  christos .endif
    559      1.373  christos 
    560      1.253  christos DPSRCS+=	${_YLSRCS}
    561      1.253  christos CLEANFILES+=	${_YLSRCS}
    562      1.230     lukem 
    563      1.362  uebayasi ${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
    564      1.103   mycroft 
    565      1.362  uebayasi ${_LIB.a}:: ${STOBJS} __archivebuild
    566        1.1       cgd 
    567      1.362  uebayasi ${_LIB_p.a}:: ${POBJS} __archivebuild
    568        1.1       cgd 
    569      1.362  uebayasi ${_LIB_pic.a}:: ${SOBJS} __archivebuild
    570       1.27        pk 
    571      1.362  uebayasi ${_LIB_g.a}:: ${GOBJS} __archivebuild
    572      1.266  christos 
    573      1.235     lukem 
    574      1.235     lukem _LIBLDOPTS=
    575      1.235     lukem .if ${SHLIBDIR} != "/usr/lib"
    576      1.324     joerg _LIBLDOPTS+=	-Wl,-rpath,${SHLIBDIR} \
    577      1.324     joerg 		-L=${SHLIBDIR}
    578      1.324     joerg .elif ${SHLIBINSTALLDIR} != "/usr/lib"
    579      1.324     joerg _LIBLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
    580      1.324     joerg 		-L=${SHLIBINSTALLDIR}
    581      1.235     lukem .endif
    582      1.394     lukem .if ${MKSTRIPSYM} != "no"
    583      1.369     ozaki _LIBLDOPTS+=	-Wl,-x
    584      1.369     ozaki .else
    585      1.369     ozaki _LIBLDOPTS+=	-Wl,-X
    586      1.369     ozaki .endif
    587      1.235     lukem 
    588      1.277  christos # gcc -shared now adds -lc automatically. For libraries other than libc and
    589      1.277  christos # libgcc* we add as a dependency the installed shared libc. For libc and
    590      1.277  christos # libgcc* we avoid adding libc as a dependency by using -nostdlib. Note that
    591      1.277  christos # -Xl,-nostdlib is not enough because we want to tell the compiler-driver not
    592      1.277  christos # to add standard libraries, not the linker.
    593      1.276  christos .if !defined(LIB)
    594      1.312      matt .if !empty(LIBC_SO)
    595      1.274  christos DPLIBC ?= ${DESTDIR}${LIBC_SO}
    596      1.312      matt .endif
    597      1.276  christos .else
    598      1.278    simonb .if ${LIB} != "c" && ${LIB:Mgcc*} == ""
    599      1.312      matt .if !empty(LIBC_SO)
    600      1.276  christos DPLIBC ?= ${DESTDIR}${LIBC_SO}
    601      1.312      matt .endif
    602      1.277  christos .else
    603      1.278    simonb LDLIBC ?= -nodefaultlibs
    604      1.341     joerg .if ${HAVE_LIBGCC} == "yes" && ${LIB} == "c"
    605      1.318       mrg LDADD+= -lgcc
    606      1.278    simonb .endif
    607      1.276  christos .endif
    608      1.274  christos .endif
    609      1.274  christos 
    610      1.291       mrg .if ${LIBISCXX} != "no"
    611      1.291       mrg LIBCC:=	${CXX}
    612      1.339     joerg . if ${MKLIBCXX} == "yes"
    613      1.339     joerg LIBDPLIBS+=     c++	${.CURDIR}/../../../../../external/bsd/libc++/lib
    614      1.339     joerg . else
    615      1.346       mrg LIBDPLIBS+=     stdc++	${.CURDIR}/../../../../../external/gpl3/${EXTERNAL_GCC_SUBDIR}/lib/libstdc++-v3
    616      1.339     joerg . endif
    617      1.291       mrg .else
    618      1.291       mrg LIBCC:=	${CC}
    619      1.291       mrg .endif
    620      1.291       mrg 
    621  1.405.2.1  perseant # VERSION_MAP
    622  1.405.2.1  perseant #
    623  1.405.2.1  perseant #	Path to an ld version script to use when linking the library.
    624  1.405.2.1  perseant #	Resolved from .PATH like a target prerequisite.
    625  1.405.2.1  perseant #
    626  1.405.2.1  perseant #	Implemented by adding -Wl,--version-script=${${VERSION_MAP}:P}
    627  1.405.2.1  perseant #	to LDFLAGS, and by adding ${VERSION_MAP} to DPADD to make it a
    628  1.405.2.1  perseant #	target prerequisite so :P works.
    629  1.405.2.1  perseant #
    630  1.405.2.1  perseant .if !empty(VERSION_MAP)
    631  1.405.2.1  perseant DPADD+=			${VERSION_MAP}
    632  1.405.2.1  perseant LDFLAGS+=		-Wl,--version-script=${${VERSION_MAP}:P}
    633  1.405.2.1  perseant .endif
    634  1.405.2.1  perseant 
    635      1.327  christos _LDADD.${_LIB}=	${LDADD} ${LDADD.${_LIB}}
    636      1.327  christos _LDFLAGS.${_LIB}=	${LDFLAGS} ${LDFLAGS.${_LIB}}
    637      1.300  uebayasi 
    638      1.358       mrg _MAINLIBDEPS=	${SOLIB} ${DPADD} ${DPLIBC} \
    639      1.358       mrg 		${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
    640      1.358       mrg 
    641      1.358       mrg .if defined(_LIB.so.debug)
    642      1.358       mrg ${_LIB.so.debug}: ${_LIB.so.link}
    643      1.358       mrg 	${_MKTARGET_CREATE}
    644      1.403       mrg 	( ${OBJCOPY} --only-keep-debug --compress-debug-sections \
    645      1.403       mrg 	    ${_LIB.so.link} ${_LIB.so.debug} \
    646      1.358       mrg 	) || (rm -f ${.TARGET}; false)
    647      1.358       mrg ${_LIB.so.full}: ${_LIB.so.link} ${_LIB.so.debug}
    648      1.358       mrg 	${_MKTARGET_CREATE}
    649      1.358       mrg 	(  ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
    650      1.403       mrg 	    --add-gnu-debuglink=${_LIB.so.debug} \
    651      1.403       mrg 	    ${_LIB.so.link} ${_LIB.so.full}.tmp && \
    652      1.403       mrg 	    ${MV} ${_LIB.so.full}.tmp ${_LIB.so.full} \
    653      1.358       mrg 	) || (rm -f ${.TARGET}; false)
    654      1.358       mrg ${_LIB.so.link}: ${_MAINLIBDEPS}
    655      1.358       mrg .else # aka no MKDEBUG
    656      1.358       mrg ${_LIB.so.full}: ${_MAINLIBDEPS}
    657      1.358       mrg .endif
    658      1.238     lukem 	${_MKTARGET_BUILD}
    659      1.327  christos 	rm -f ${.TARGET}
    660      1.369     ozaki 	${LIBCC} ${LDLIBC} -shared ${SHLIB_SHFLAGS} \
    661      1.370       chs 	    ${_LDFLAGS.${_LIB}} -o ${.TARGET}.tmp ${_LIBLDOPTS} \
    662      1.327  christos 	    -Wl,--whole-archive ${SOLIB} \
    663      1.328      matt 	    -Wl,--no-whole-archive ${_LDADD.${_LIB}}
    664      1.370       chs .if ${MKSTRIPIDENT} != "no"
    665      1.370       chs 	${OBJCOPY} -R .ident ${.TARGET}.tmp
    666      1.370       chs .endif
    667      1.379  christos 	${MV} ${.TARGET}.tmp ${.TARGET}
    668      1.196     lukem #  We don't use INSTALL_SYMLINK here because this is just
    669      1.196     lukem #  happening inside the build directory/objdir. XXX Why does
    670      1.196     lukem #  this spend so much effort on libraries that aren't live??? XXX
    671      1.358       mrg #  XXX Also creates dead symlinks until the .full rule runs
    672      1.358       mrg #  above and creates the main link
    673      1.284     lukem .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
    674      1.284     lukem     "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
    675      1.327  christos 	${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so.major}.tmp
    676      1.379  christos 	${MV} ${_LIB.so.major}.tmp ${_LIB.so.major}
    677      1.283     lukem .endif
    678      1.327  christos 	${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so}.tmp
    679      1.379  christos 	${MV} ${_LIB.so}.tmp ${_LIB.so}
    680       1.35        pk 
    681      1.395  riastrad # If there's a file listing expected symbols, fail if the diff from it
    682      1.395  riastrad # to the actual symbols is nonempty, and show the diff in that case.
    683      1.405  riastrad .if exists(${.CURDIR}/${LIB}.${LIBC_MACHINE_ARCH:U${MACHINE_ARCH}}.expsym)
    684      1.405  riastrad LIB_EXPSYM?=	${LIB}.${LIBC_MACHINE_ARCH:U${MACHINE_ARCH}}.expsym
    685      1.405  riastrad .elif exists(${.CURDIR}/${LIB}.${LIBC_MACHINE_CPU:U${MACHINE_CPU}}.expsym)
    686      1.405  riastrad LIB_EXPSYM?=	${LIB}.${LIBC_MACHINE_CPU:U${MACHINE_CPU}}.expsym
    687      1.395  riastrad .elif exists(${.CURDIR}/${LIB}.expsym)
    688      1.395  riastrad LIB_EXPSYM?=	${LIB}.expsym
    689      1.395  riastrad .endif
    690      1.395  riastrad 
    691  1.405.2.2  perseant # If we don't have a version map enumerating the exact symbols
    692  1.405.2.2  perseant # exported, skip various machine-dependent crud that the linker
    693  1.405.2.2  perseant # automatically exports (even though it appears to be unnecessary, as
    694  1.405.2.2  perseant # demonstrated by libraries with version scripts which don't export
    695  1.405.2.2  perseant # these symbols).
    696  1.405.2.2  perseant #
    697  1.405.2.2  perseant # This list has been gathered empirically -- I'm not sure it's written
    698  1.405.2.2  perseant # down anywhere and I'm not sure there's any way to ask the linker to
    699  1.405.2.2  perseant # simply not export the symbols.
    700  1.405.2.2  perseant .if !empty(VERSION_MAP)
    701  1.405.2.2  perseant _EXPSYM_PIPE_GREP=	# empty
    702  1.405.2.2  perseant .else
    703  1.405.2.2  perseant _EXPSYM_PIPE_GREP=	| grep -Fvx ${_EXPSYM_IGNORE:@_s_@-e ${_s_:Q}@}
    704  1.405.2.2  perseant _EXPSYM_IGNORE+=		_end
    705  1.405.2.2  perseant _EXPSYM_IGNORE+=		_fini
    706  1.405.2.2  perseant _EXPSYM_IGNORE+=		_init
    707  1.405.2.2  perseant _EXPSYM_IGNORE.aarch64+=	__bss_end__
    708  1.405.2.2  perseant _EXPSYM_IGNORE.aarch64+=	__bss_start__
    709  1.405.2.2  perseant _EXPSYM_IGNORE.aarch64+=	__end__
    710  1.405.2.2  perseant _EXPSYM_IGNORE.aarch64+=	_bss_end__
    711  1.405.2.2  perseant _EXPSYM_IGNORE.hppa+=		_GLOBAL_OFFSET_TABLE_
    712  1.405.2.2  perseant _EXPSYM_IGNORE.powerpc64+=	._fini
    713  1.405.2.2  perseant _EXPSYM_IGNORE.powerpc64+=	._init
    714  1.405.2.2  perseant _EXPSYM_IGNORE.sh3+=		___ctors
    715  1.405.2.2  perseant _EXPSYM_IGNORE.sh3+=		___ctors_end
    716  1.405.2.2  perseant _EXPSYM_IGNORE.sh3+=		___dtors
    717  1.405.2.2  perseant _EXPSYM_IGNORE.sh3+=		___dtors_end
    718  1.405.2.2  perseant _EXPSYM_IGNORE+=		${_EXPSYM_IGNORE.${MACHINE_ARCH}}
    719  1.405.2.2  perseant .  if ${MACHINE_ARCH} != ${MACHINE_CPU}
    720  1.405.2.2  perseant _EXPSYM_IGNORE+=		${_EXPSYM_IGNORE.${MACHINE_CPU}}
    721  1.405.2.2  perseant .  endif
    722  1.405.2.2  perseant .endif
    723  1.405.2.2  perseant 
    724      1.397  riastrad .if !empty(LIB_EXPSYM) && ${MKPIC} != "no"
    725      1.395  riastrad realall: ${_LIB.so.full}.diffsym
    726      1.395  riastrad ${_LIB.so.full}.diffsym: ${LIB_EXPSYM} ${_LIB.so.full}.actsym
    727      1.395  riastrad 	${_MKTARGET_CREATE}
    728      1.395  riastrad 	if diff -u ${.ALLSRC} >${.TARGET}.tmp; then \
    729      1.395  riastrad 		${MV} ${.TARGET}.tmp ${.TARGET}; \
    730      1.395  riastrad 	else \
    731      1.395  riastrad 		ret=$$?; \
    732      1.395  riastrad 		cat ${.TARGET}.tmp; \
    733      1.395  riastrad 		echo ${_LIB.so.full}: error: \
    734      1.395  riastrad 			actual symbols differ from expected symbols >&2; \
    735      1.395  riastrad 		exit $$ret; \
    736      1.395  riastrad 	fi
    737      1.395  riastrad ${_LIB.so.full}.actsym: ${_LIB.so.full}
    738      1.395  riastrad 	${_MKTARGET_CREATE}
    739      1.395  riastrad 	${NM} --dynamic --extern-only --defined-only --with-symbol-versions \
    740      1.396  riastrad 		${.ALLSRC} \
    741  1.405.2.2  perseant 	| cut -d' ' -f3	${_EXPSYM_PIPE_GREP} | LC_ALL=C sort -u >${.TARGET}.tmp
    742      1.395  riastrad 	${MV} ${.TARGET}.tmp ${.TARGET}
    743      1.395  riastrad CLEANFILES+=	${_LIB.so.full}.actsym
    744      1.395  riastrad CLEANFILES+=	${_LIB.so.full}.actsym.tmp
    745      1.395  riastrad CLEANFILES+=	${_LIB.so.full}.diffsym
    746      1.395  riastrad CLEANFILES+=	${_LIB.so.full}.diffsym.tmp
    747      1.395  riastrad update-symbols: .PHONY
    748      1.395  riastrad update-symbols: ${_LIB.so.full}.actsym
    749  1.405.2.2  perseant 	@if [ -f ${${LIB_EXPSYM}:P:Q} ] && \
    750  1.405.2.2  perseant 	    [ -n "`comm -23 ${${LIB_EXPSYM}:P:Q} ${.ALLSRC:Q}`" ]; then \
    751  1.405.2.2  perseant 		echo 'WARNING: Symbols deleted, major bump required!' >&2; \
    752  1.405.2.2  perseant 	elif [ -f ${${LIB_EXPSYM}:P:Q} ] && \
    753  1.405.2.2  perseant 	    [ -n "`comm -13 ${${LIB_EXPSYM}:P:Q} ${.ALLSRC:Q}`" ]; then \
    754  1.405.2.2  perseant 		echo 'WARNING: Symbols added, minor bump required!' >&2; \
    755  1.405.2.2  perseant 	fi
    756  1.405.2.2  perseant 	cp ${.ALLSRC} ${defined(NETBSDSRCDIR_RW):?${${LIB_EXPSYM}:P:C,^${NETBSDSRCDIR}/,${NETBSDSRCDIR_RW}/,}:${${LIB_EXPSYM}:P}}
    757      1.395  riastrad .endif
    758      1.395  riastrad 
    759      1.252     lukem .if !empty(LOBJS)							# {
    760      1.103   mycroft LLIBS?=		-lc
    761      1.327  christos ${_LIB.ln}: ${LOBJS}
    762      1.238     lukem 	${_MKTARGET_COMPILE}
    763      1.327  christos 	rm -f ${.TARGET}
    764      1.206   thorpej .if defined(DESTDIR)
    765      1.228     lukem 	${LINT} -C${LIB} ${.ALLSRC} -L${DESTDIR}/usr/libdata ${LLIBS}
    766      1.206   thorpej .else
    767      1.228     lukem 	${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
    768      1.206   thorpej .endif
    769      1.252     lukem .endif									# }
    770        1.1       cgd 
    771  1.405.2.2  perseant # Only intended to be invoked manually, not as part of dependall.
    772      1.280     lukem lint: ${LOBJS}
    773      1.280     lukem .if defined(LOBJS) && !empty(LOBJS)
    774  1.405.2.2  perseant 	${LINT} ${LINTFLAGS} -Cmanual-lint ${LOBJS}
    775      1.280     lukem .endif
    776      1.280     lukem 
    777      1.327  christos 
    778      1.317       apb # If the number of entries in CLEANFILES is too large, then the
    779      1.317       apb # commands in bsd.clean.mk encounter errors like "exec(/bin/sh)
    780      1.317       apb # failed (Argument list too long)".  Avoid that by splitting the
    781      1.317       apb # files to clean into several lists using different variable names.
    782      1.317       apb # __cleanuse is an internal target in bsd.clean.mk; the way we
    783      1.317       apb # use it here mimics the way it's used by the clean target in
    784      1.317       apb # bsd.clean.mk.
    785      1.317       apb #
    786      1.317       apb clean: libclean1 libclean2 libclean3 libclean4 libclean5
    787      1.317       apb libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1
    788      1.317       apb libclean2: .PHONY .MADE __cleanuse LIBCLEANFILES2
    789      1.317       apb libclean3: .PHONY .MADE __cleanuse LIBCLEANFILES3
    790      1.317       apb libclean4: .PHONY .MADE __cleanuse LIBCLEANFILES4
    791      1.317       apb libclean5: .PHONY .MADE __cleanuse LIBCLEANFILES5
    792      1.316       apb CLEANFILES+= a.out [Ee]rrs mklog core *.core
    793      1.327  christos LIBCLEANFILES1+= ${_LIB.a}   ${STOBJS} ${STOBJS:=.tmp}
    794      1.327  christos LIBCLEANFILES2+= ${_LIB_p.a} ${POBJS}  ${POBJS:=.tmp}
    795      1.327  christos LIBCLEANFILES3+= ${_LIB_g.a} ${GOBJS}  ${GOBJS:=.tmp}
    796      1.327  christos LIBCLEANFILES4+= ${_LIB_pic.a}
    797      1.327  christos .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    798      1.327  christos LIBCLEANFILES4+= ${_LIB.so}.* ${_LIB.so} ${_LIB.so.debug}
    799      1.327  christos .endif
    800      1.317       apb LIBCLEANFILES4+= ${SOBJS} ${SOBJS:=.tmp}
    801  1.405.2.2  perseant LIBCLEANFILES5+= ${_LIB.ln} ${LOBJS} llib-lmanual-lint.ln
    802      1.252     lukem 
    803      1.252     lukem .if !target(libinstall)							# {
    804      1.148     lukem # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
    805      1.139        tv libinstall::
    806      1.139        tv 
    807      1.400  christos .if ${MAKELINKLIB} != "no" && ${MAKESTATICLIB} != "no" && ${LINKINSTALL} != "no"
    808      1.327  christos libinstall:: ${_DEST.LIB}/${_LIB.a}
    809      1.327  christos .PRECIOUS: ${_DEST.LIB}/${_LIB.a}
    810      1.197   mycroft 
    811      1.269       dbj .if ${MKUPDATE} == "no"
    812      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
    813      1.327  christos ${_DEST.LIB}/${_LIB.a}! .MADE
    814       1.89  christos .endif
    815      1.327  christos ${_DEST.LIB}/${_LIB.a}! ${_LIB.a} __archiveinstall
    816      1.197   mycroft .else
    817      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB.a})
    818      1.327  christos ${_DEST.LIB}/${_LIB.a}: .MADE
    819       1.89  christos .endif
    820      1.327  christos ${_DEST.LIB}/${_LIB.a}: ${_LIB.a} __archiveinstall
    821      1.130        tv .endif
    822      1.197   mycroft .endif
    823       1.89  christos 
    824      1.149     lukem .if ${MKPROFILE} != "no"
    825      1.327  christos libinstall:: ${_DEST.LIB}/${_LIB_p.a}
    826      1.327  christos .PRECIOUS: ${_DEST.LIB}/${_LIB_p.a}
    827      1.197   mycroft 
    828      1.269       dbj .if ${MKUPDATE} == "no"
    829      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
    830      1.327  christos ${_DEST.LIB}/${_LIB_p.a}! .MADE
    831       1.32        pk .endif
    832      1.327  christos ${_DEST.LIB}/${_LIB_p.a}! ${_LIB_p.a} __archiveinstall
    833      1.197   mycroft .else
    834      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
    835      1.327  christos ${_DEST.LIB}/${_LIB_p.a}: .MADE
    836       1.89  christos .endif
    837      1.327  christos ${_DEST.LIB}/${_LIB_p.a}: ${_LIB_p.a} __archiveinstall
    838       1.89  christos .endif
    839      1.197   mycroft .endif
    840       1.89  christos 
    841      1.268     lukem .if ${MKDEBUGLIB} != "no"
    842      1.327  christos libinstall:: ${_DEST.LIB}/${_LIB_g.a}
    843      1.327  christos .PRECIOUS: ${_DEST.LIB}/${_LIB_g.a}
    844      1.266  christos 
    845      1.269       dbj .if ${MKUPDATE} == "no"
    846      1.329       spz .if !defined(BUILD) && !make(all) && !make(${_LIB_g.a})
    847      1.327  christos ${_DEST.LIB}/${_LIB_g.a}! .MADE
    848      1.266  christos .endif
    849      1.327  christos ${_DEST.LIB}/${_LIB_g.a}! ${_LIB_g.a} __archiveinstall
    850      1.266  christos .else
    851      1.327  christos .if !defined(BUILD) && !make(all) && !make(${LIB_g.a})
    852      1.327  christos ${_DEST.LIB}/${_LIB_g.a}: .MADE
    853      1.266  christos .endif
    854      1.327  christos ${_DEST.LIB}/${_LIB_g.a}: ${_LIB_g.a} __archiveinstall
    855      1.266  christos .endif
    856      1.266  christos .endif
    857      1.266  christos 
    858      1.149     lukem .if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
    859      1.327  christos libinstall:: ${_DEST.LIB}/${_LIB_pic.a}
    860      1.327  christos .PRECIOUS: ${_DEST.LIB}/${_LIB_pic.a}
    861      1.197   mycroft 
    862      1.269       dbj .if ${MKUPDATE} == "no"
    863      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
    864      1.327  christos ${_DEST.LIB}/${_LIB_pic.a}! .MADE
    865       1.89  christos .endif
    866      1.197   mycroft .if ${MKPICLIB} == "no"
    867      1.331  nakayama ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB.a} __archivesymlinkpic
    868      1.197   mycroft .else
    869      1.327  christos ${_DEST.LIB}/${_LIB_pic.a}! ${_LIB_pic.a} __archiveinstall
    870      1.197   mycroft .endif
    871      1.197   mycroft .else
    872      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
    873      1.327  christos ${_DEST.LIB}/${_LIB_pic.a}: .MADE
    874       1.33        pk .endif
    875      1.160    simonb .if ${MKPICLIB} == "no"
    876      1.331  nakayama ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB.a} __archivesymlinkpic
    877      1.160    simonb .else
    878      1.327  christos ${_DEST.LIB}/${_LIB_pic.a}: ${_LIB_pic.a} __archiveinstall
    879      1.160    simonb .endif
    880       1.89  christos .endif
    881      1.197   mycroft .endif
    882       1.89  christos 
    883      1.171  christos .if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
    884      1.282     lukem 
    885      1.327  christos libinstall:: ${_DEST.OBJ}/${_LIB.so.full}
    886      1.327  christos .PRECIOUS: ${_DEST.OBJ}/${_LIB.so.full}
    887      1.197   mycroft 
    888      1.269       dbj .if ${MKUPDATE} == "no"
    889      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
    890      1.327  christos ${_DEST.OBJ}/${_LIB.so.full}! .MADE
    891       1.89  christos .endif
    892      1.327  christos ${_DEST.OBJ}/${_LIB.so.full}! ${_LIB.so.full}
    893      1.197   mycroft .else
    894      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
    895      1.327  christos ${_DEST.OBJ}/${_LIB.so.full}: .MADE
    896       1.89  christos .endif
    897      1.327  christos ${_DEST.OBJ}/${_LIB.so.full}: ${_LIB.so.full}
    898      1.197   mycroft .endif
    899      1.238     lukem 	${_MKTARGET_INSTALL}
    900      1.188        tv 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    901      1.327  christos 	    ${.ALLSRC} ${.TARGET}
    902      1.195     lukem .if ${_LIBSODIR} != ${LIBDIR}
    903      1.327  christos 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    904      1.392  riastrad 	    ${_DEST.LIB}/${_LIB.so.full}
    905      1.195     lukem .endif
    906      1.284     lukem .if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
    907      1.284     lukem     "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
    908      1.327  christos 	${INSTALL_SYMLINK} ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so.major}
    909      1.195     lukem .if ${_LIBSODIR} != ${LIBDIR}
    910      1.327  christos 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    911      1.327  christos 	    ${_DEST.LIB}/${_LIB.so.major}
    912      1.195     lukem .endif
    913      1.284     lukem .endif
    914      1.400  christos .if ${MAKELINKLIB} != "no" && ${LINKINSTALL} != "no"
    915      1.327  christos 	${INSTALL_SYMLINK}  ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so}
    916      1.195     lukem .if ${_LIBSODIR} != ${LIBDIR}
    917      1.327  christos 	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
    918      1.327  christos 	    ${_DEST.LIB}/${_LIB.so}
    919      1.195     lukem .endif
    920       1.83       cgd .endif
    921       1.12       cgd .endif
    922       1.89  christos 
    923      1.327  christos .if defined(_LIB.so.debug)
    924      1.327  christos libinstall:: ${_DEST.DEBUG}/${_LIB.so.debug}
    925      1.327  christos .PRECIOUS: ${_DEST.DEBUG}/${_LIB.so.debug}
    926      1.307     lukem 
    927      1.327  christos ${_DEST.DEBUG}/${_LIB.so.debug}: ${_LIB.so.debug}
    928      1.307     lukem 	${_MKTARGET_INSTALL}
    929      1.307     lukem 	${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
    930      1.327  christos 	    ${.ALLSRC} ${.TARGET}
    931      1.334  christos .if ${_LIBSODIR} != ${LIBDIR}
    932      1.334  christos 	${INSTALL_SYMLINK} -l r ${_DEST.DEBUG}/${_LIB.so.debug} \
    933      1.392  riastrad 	    ${_DEST.ODEBUG}/${_LIB.so.debug}
    934      1.334  christos .endif
    935      1.307     lukem .endif
    936      1.307     lukem 
    937      1.388  christos .if ${_LINTINSTALL} != "no" && !empty(LOBJS)
    938      1.327  christos libinstall:: ${_DEST.LINT}/${_LIB.ln}
    939      1.327  christos .PRECIOUS: ${_DEST.LINT}/${_LIB.ln}
    940      1.197   mycroft 
    941      1.269       dbj .if ${MKUPDATE} == "no"
    942      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
    943      1.327  christos ${_DEST.LINT}/${_LIB.ln}! .MADE
    944       1.89  christos .endif
    945      1.327  christos ${_DEST.LINT}/${_LIB.ln}! ${_LIB.ln}
    946      1.197   mycroft .else
    947      1.327  christos .if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
    948      1.327  christos ${_DEST.LINT}/${_LIB.ln}: .MADE
    949       1.89  christos .endif
    950      1.327  christos ${_DEST.LINT}/${_LIB.ln}: ${_LIB.ln}
    951      1.197   mycroft .endif
    952      1.238     lukem 	${_MKTARGET_INSTALL}
    953      1.188        tv 	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
    954      1.327  christos 		${.ALLSRC} ${_DEST.LINT}
    955       1.58       cgd .endif
    956      1.252     lukem .endif	# !target(libinstall)						# }
    957        1.1       cgd 
    958      1.188        tv ##### Pull in related .mk logic
    959      1.298       apb LINKSOWN?= ${LIBOWN}
    960      1.298       apb LINKSGRP?= ${LIBGRP}
    961      1.298       apb LINKSMODE?= ${LIBMODE}
    962        1.1       cgd .include <bsd.man.mk>
    963       1.57       jtc .include <bsd.nls.mk>
    964       1.91  christos .include <bsd.files.mk>
    965       1.89  christos .include <bsd.inc.mk>
    966      1.109       cjs .include <bsd.links.mk>
    967       1.24   mycroft .include <bsd.dep.mk>
    968      1.315     joerg .include <bsd.clang-analyze.mk>
    969      1.316       apb .include <bsd.clean.mk>
    970      1.117   mycroft 
    971      1.188        tv ${TARGETS}:	# ensure existence
    972