1#-*- tab-width: 4; -*- 2# ex:ts=4 3# 4# gcc.mk - Support for smarter USE_GCC usage. 5# 6# 7# To request the use of a current version of GCC, specify USE_GCC=yes in 8# your port/system configuration. This is the preferred use of USE_GCC. 9# It uses the canonical version of GCC defined in default-versions.mk. 10# 11# If your port needs a specific version of GCC, you can instead specify 12# that using USE_GCC=X (where X is the version of GCC). 13# 14# Optionally comma-separated arguments follow the version specifier. 15# Currently we support: 16# build ... which adds GCC as a build dependency (BUILD_DEPENDS) only. 17# 18# If no arguments are specified, GCC is added as both a build dependency 19# and a run time dependency. 20# 21# 22# Examples: 23# USE_GCC= yes # port requires a current version of GCC 24# # as defined in bsd.default-versions.mk. 25# USE_GCC= 12 # port requires GCC 12. 26# USE_GCC= yes:build # port requires a current version of GCC at 27# # build time only. 28# USE_GCC= 12:build # port requires GCC 12 at build time only. 29# 30# If you are wondering what your port exactly does, use "make test-gcc" 31# to see some debugging. 32 33GCC_Include_MAINTAINER= ports@MidnightBSD.org 34 35# All GCC versions supported by this framework. 36# 37# When updating this, keep Mk/bsd.default-versions.mk in sync. 38GCCVERSIONS= 4.8 11 12 13 14 15 39 40# No configurable parts below this. #################################### 41# 42 43# Split arguments 44.if defined(USE_GCC) 45__USE_GCC:= ${USE_GCC:C/\:.*//} 46_USE_GCC_ARGS:= ${USE_GCC:C/^[^\:]*(\:|\$)//:S/,/ /g} 47USE_GCC= ${__USE_GCC} 48.endif 49 50.if ${_USE_GCC_ARGS:Mbuild} 51_USE_GCC_ARGS:= ${_USE_GCC_ARGS:Nbuild} 52.else 53_USE_GCC_RUN_DEPENDS= yes 54.endif 55 56.if !empty(_USE_GCC_ARGS) 57IGNORE= bad target specification in USE_GCC; only "build" is supported 58.endif 59 60.if defined(USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING) 61 62# Handle USE_GCC=yes. 63. if ${USE_GCC} == yes 64USE_GCC= ${GCC_DEFAULT} 65. endif 66 67_USE_GCC:= ${USE_GCC} 68 69# See whether we have the specific version requested installed already 70# and save that into _GCC_FOUND. In parallel, check if USE_GCC refers 71# to a valid version to begin with. 72. for v in ${GCCVERSIONS} 73. if ${_USE_GCC} == ${v} 74_GCCVERSION_OKAY= true 75. if exists(${LOCALBASE}/bin/gcc${v:S/.//}) 76_GCC_FOUND:= ${_USE_GCC} 77. endif 78. endif 79. endfor 80 81. if !defined(_GCCVERSION_OKAY) 82IGNORE= Unknown version of GCC specified (USE_GCC=${USE_GCC}) 83. endif 84 85# A concrete version has been selected. Set proper ports dependencies, 86# CC, CXX, CPP, and flags. 87V:= ${_USE_GCC:S/.//} 88. if ${V} == 15 89_GCC_PORT:= gcc${V}-devel 90. else 91_GCC_PORT:= gcc${V} 92. endif 93CC:= gcc${V} 94CXX:= g++${V} 95CPP:= cpp${V} 96_GCC_RUNTIME:= ${LOCALBASE}/lib/gcc${V} 97. if ${PORTNAME} == gcc 98# When building GCC itself, we want the target libraries to be used 99# and not the host GCC libraries. 100. else 101CFLAGS+= -Wl,-rpath=${_GCC_RUNTIME} 102CXXFLAGS+= -Wl,-rpath=${_GCC_RUNTIME} 103LDFLAGS+= -Wl,-rpath=${_GCC_RUNTIME} -L${_GCC_RUNTIME} 104. endif 105.undef V 106 107# Now filter unsupported flags for CC and CXX. 108CFLAGS:= ${CFLAGS:N-mretpoline} 109CXXFLAGS:= ${CXXFLAGS:N-mretpoline} 110 111BUILD_DEPENDS+= ${CC}:lang/${_GCC_PORT} 112. if defined(_USE_GCC_RUN_DEPENDS) 113RUN_DEPENDS+= ${CC}:lang/${_GCC_PORT} 114. endif 115 116# GCC ports already depend on binutils; make sure whatever we build 117# leverages this as well. 118USE_BINUTILS= yes 119 120.endif # defined(_USE_GCC) && !defined(FORCE_BASE_CC_FOR_TESTING) 121 122 123test-gcc: 124 @echo USE_GCC=${USE_GCC} 125.if defined(IGNORE) 126 @echo "IGNORE: ${IGNORE}" 127.else 128. if defined(USE_GCC) 129 @echo Using GCC version ${_USE_GCC} 130. endif 131 @echo CC=${CC} - CXX=${CXX} - CPP=${CPP} 132 @echo CFLAGS=\"${CFLAGS}\" 133 @echo CXXFLAGS=\"${CXXFLAGS}\" 134 @echo LDFLAGS=\"${LDFLAGS}\" 135.endif 136