1125902b6SBryan Drewery# $FreeBSD$ 2125902b6SBryan Drewery 3125902b6SBryan Drewery# Setup variables for the linker. 4125902b6SBryan Drewery# 5125902b6SBryan Drewery# LINKER_TYPE is the major type of linker. Currently binutils and lld support 6125902b6SBryan Drewery# automatic detection. 7125902b6SBryan Drewery# 8125902b6SBryan Drewery# LINKER_VERSION is a numeric constant equal to: 9125902b6SBryan Drewery# major * 10000 + minor * 100 + tiny 10125902b6SBryan Drewery# It too can be overridden on the command line. 11125902b6SBryan Drewery# 12*08154765SBryan Drewery# These variables with an X_ prefix will also be provided if XLD is set. 13*08154765SBryan Drewery# 14125902b6SBryan Drewery# This file may be included multiple times, but only has effect the first time. 15125902b6SBryan Drewery# 16125902b6SBryan Drewery 17125902b6SBryan Drewery.if !target(__<bsd.linker.mk>__) 18125902b6SBryan Drewery__<bsd.linker.mk>__: 19125902b6SBryan Drewery 20*08154765SBryan Drewery.for ld X_ in LD $${_empty_var_} XLD X_ 21*08154765SBryan Drewery.if ${ld} == "LD" || !empty(XLD) 22*08154765SBryan Drewery.if ${ld} == "LD" || (${ld} == "XLD" && ${XLD} != ${LD}) 23*08154765SBryan Drewery 24*08154765SBryan Drewery_ld_version!= ${${ld}} --version 2>/dev/null | head -n 1 || echo none 25125902b6SBryan Drewery.if ${_ld_version} == "none" 26*08154765SBryan Drewery.error Unable to determine linker type from ${ld}=${${ld}} 27125902b6SBryan Drewery.endif 28125902b6SBryan Drewery.if ${_ld_version:[1..2]} == "GNU ld" 29*08154765SBryan Drewery${X_}LINKER_TYPE= binutils 30125902b6SBryan Drewery_v= ${_ld_version:[3]} 31125902b6SBryan Drewery.elif ${_ld_version:[1]} == "LLD" 32*08154765SBryan Drewery${X_}LINKER_TYPE= lld 33125902b6SBryan Drewery_v= ${_ld_version:[2]} 34125902b6SBryan Drewery.else 35*08154765SBryan Drewery.error Unknown linker from ${ld}=${${ld}}: ${_ld_version} 36125902b6SBryan Drewery.endif 37*08154765SBryan Drewery${X_}LINKER_VERSION!= echo "${_v:M[1-9].[0-9]*}" | \ 38*08154765SBryan Drewery awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}' 39*08154765SBryan Drewery.undef _ld_version 40*08154765SBryan Drewery.undef _v 41*08154765SBryan Drewery.endif # ${ld} == "LD" || (${ld} == "XLD" && ${XLD} != ${LD}) 42*08154765SBryan Drewery 43*08154765SBryan Drewery.endif # ${ld} == "LD" || !empty(XLD) 44*08154765SBryan Drewery.endfor # .for ld in LD XLD 45*08154765SBryan Drewery 46125902b6SBryan Drewery 47125902b6SBryan Drewery.endif # !target(__<bsd.linker.mk>__) 48