summaryrefslogtreecommitdiff
path: root/mk/compiler.mk
diff options
context:
space:
mode:
Diffstat (limited to 'mk/compiler.mk')
-rw-r--r--mk/compiler.mk91
1 files changed, 82 insertions, 9 deletions
diff --git a/mk/compiler.mk b/mk/compiler.mk
index a81d2db1f43..b38810c1629 100644
--- a/mk/compiler.mk
+++ b/mk/compiler.mk
@@ -1,26 +1,40 @@
-# $NetBSD: compiler.mk,v 1.6 2003/09/12 22:53:18 salo Exp $
+# $NetBSD: compiler.mk,v 1.7 2003/09/17 14:37:32 grant Exp $
# This Makefile fragment implements handling for supported
# C/C++/fortran compilers.
#
# The following variables are used:
#
-# USE_GCC2
-# Use pkgsrc gcc2 from lang/gcc.
+# GCC_REQD
+# Sets the minimum required version of gcc. Packages can set
+# this if they are known to require gcc>2.8.0, which is the
+# compiler shipped with NetBSD 1.5.
#
-# USE_GCC3
-# Use pkgsrc gcc3 from lang/gcc3.
+# Note: Be conservative when setting GCC_REQD, as lang/gcc3 is
+# known not to build on some platforms, eg. Darwin. If gcc3 is
+# required, set GCC_REQD=3.0 so that we do not try to pull in
+# lang/gcc3 unnecessarily and have it fail.
#
# USE_GCC_SHLIB
# Indicates that a package uses GCC shared libraries, so we
# register a runtime dependency on the compiler package.
#
+# USE_GCC2
+# Use pkgsrc gcc2 from lang/gcc. This overrides any GCC_REQD
+# setting.
+#
+# USE_GCC3
+# Use pkgsrc gcc3 from lang/gcc3. This overrides any GCC_REQD
+# setting.
+#
+# USE_PKGSRC_GCC
+# Use the appropriate version of GCC from pkgsrc based on
+# GCC_REQD.
+#
# USE_SUNPRO
# Use the Sun Microsystems Inc. WorkShop/Forte/Sun ONE Studio
# compiler collection.
#
-# The following variable is reserved for future use:
-#
# USE_MIPSPRO
# Use the Silicon Graphics, Inc. MIPSpro compiler.
#
@@ -30,8 +44,65 @@ COMPILER_MK= # defined
.include "../../mk/bsd.prefs.mk"
+# Do a dance to determine which version of gcc is being used, if any,
+# and whether it satisfies GCC_REQD.
+#
+# We only pull in lang/gcc or lang/gcc3 if necessary, or if
+# USE_PKGSRC_GCC is defined.
+#
+.if !defined(USE_SUNPRO) && !defined(USE_MIPSPRO) && \
+ !defined(USE_GCC2) && !defined(USE_GCC3)
+
+# Darwin's gcc reports "Apple Computer ... based on gcc version ...",
+# so we can't just grep for ^gcc.
+_CC_VERSION_STRING!= if ${CC} -v 2>&1 | ${GREP} -q 'gcc version'; then \
+ echo `${CC} -v 2>&1 | ${GREP} 'gcc version'`; \
+ fi
+
+# egcs is considered to be gcc-2.8.1.
+. if !empty(_CC_VERSION_STRING:Mgcc*)
+_CC_VERSION!= ${CC} -dumpversion
+_CC_IS_GCC= YES
+. elif !empty(_CC_VERSION_STRING:Megcs*)
+_CC_VERSION= 2.8.1
+_CC_IS_GCC= YES
+. endif
+
+. if defined(_CC_IS_GCC)
+GCC_REQD?= 2.8.0
+_GCC_VERSION_REQD= gcc>=${GCC_REQD}
+
+# packages should define USE_PKGSRC_GCC to force install and use of
+# pkgsrc gcc, which defaults to gcc2.
+. if defined(USE_PKGSRC_GCC)
+GCC_REQD= 2.95.3
+_NEED_PKGSRC_GCC= YES
+. else
+_GCC_IN_USE= gcc-${_CC_VERSION}
+_NEED_PKGSRC_GCC!= \
+ if ${PKG_ADMIN} pmatch '${_GCC_VERSION_REQD}' ${_GCC_IN_USE}; then \
+ ${ECHO} "NO"; \
+ else \
+ ${ECHO} "YES"; \
+ fi
+. endif # USE_PKGSRC_GCC
+
+. endif # _CC_IS_GCC
+
+.endif # !USE_MIPSPRO && !USE_SUNPRO && !USE_GCC2 && !USE_GCC3
+
+# we default to gcc2 if all of the above determined that we need
+# pkgsrc gcc.
+.if defined(_NEED_PKGSRC_GCC) && ${_NEED_PKGSRC_GCC} == "YES"
+. if !empty(GCC_REQD:M3*)
+USE_GCC3= # defined
+. else
+USE_GCC2= # defined
+. endif
+.endif
+
.if defined(USE_GCC2) && empty(PKGPATH:Mlang/gcc) && empty(_PKGSRC_DEPS:Mgcc-2*)
-GCC_REQD?= 2.95.3
+GCC_REQD= 2.95.3
# we need to define these early, as they are used by gcc/buildlink2.mk.
_GCC_SUBPREFIX= gcc-2.95.3/
@@ -60,7 +131,7 @@ F77= ${_GCC_PREFIX}bin/g77
PKG_FC= ${F77}
.elif defined(USE_GCC3) && empty(PKGPATH:Mlang/gcc3) && empty(_PKGSRC_DEPS:Mgcc-3*)
-GCC_REQD?= 3.3
+GCC_REQD= 3.3
# we need to define these early, as they are used by gcc3/buildlink2.mk.
_GCC_SUBPREFIX= gcc-3.3/
@@ -70,10 +141,12 @@ _GCC_ARCHDIR= ${_GCC_PREFIX}${_GCC_ARCHSUBDIR}
. include "../lang/gcc3/buildlink2.mk"
. else
_GCC_PREFIX= ${LOCALBASE}/${_GCC_SUBPREFIX}
+. if exists(${_GCC_PREFIX}bin/gcc)
_GCC_LIBGCCDIR!= \
dirname `${_GCC_PREFIX}bin/gcc --print-libgcc-file-name`
_GCC_ARCHSUBDIR= \
${_GCC_LIBGCCDIR:S|^${LOCALBASE}/${_GCC_SUBPREFIX}||}
+. endif
# Packages that link against gcc shared libraries need a full
# dependency.