2019-01-01 14:04:23 +08:00
|
|
|
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
|
2018-10-08 04:52:23 +08:00
|
|
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
2016-12-27 16:17:12 +08:00
|
|
|
#
|
2018-10-08 04:52:23 +08:00
|
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
|
|
|
2014-10-09 12:59:47 +08:00
|
|
|
from spack import *
|
2018-06-28 00:31:21 +08:00
|
|
|
from spack.operating_systems.mac_os import macos_version
|
2017-05-09 04:28:28 +08:00
|
|
|
from llnl.util import tty
|
2014-10-09 12:59:47 +08:00
|
|
|
|
2017-05-09 04:28:28 +08:00
|
|
|
import glob
|
|
|
|
import os
|
2016-02-13 01:51:43 +08:00
|
|
|
import sys
|
2016-05-15 13:35:55 +08:00
|
|
|
|
2014-11-06 01:54:43 +08:00
|
|
|
|
2017-01-26 18:27:15 +08:00
|
|
|
class Gcc(AutotoolsPackage):
|
2017-05-09 04:28:28 +08:00
|
|
|
"""The GNU Compiler Collection includes front ends for C, C++, Objective-C,
|
|
|
|
Fortran, Ada, and Go, as well as libraries for these languages."""
|
2014-10-09 12:59:47 +08:00
|
|
|
|
2017-05-09 04:28:28 +08:00
|
|
|
homepage = 'https://gcc.gnu.org'
|
2018-08-16 14:27:21 +08:00
|
|
|
url = 'https://ftpmirror.gnu.org/gcc/gcc-7.1.0/gcc-7.1.0.tar.bz2'
|
2016-08-23 08:26:54 +08:00
|
|
|
list_url = 'http://ftp.gnu.org/gnu/gcc/'
|
2017-04-02 05:03:54 +08:00
|
|
|
list_depth = 1
|
2014-11-06 01:54:43 +08:00
|
|
|
|
2018-07-27 21:14:49 +08:00
|
|
|
version('8.2.0', '64898a165f67e136d802a92e7633bf1b06c85266027e52127ea025bf5fc2291b5e858288aac0bdba246e6cdf7c6ec88bc8e0e7f3f6f1985f4297710cafde56ed')
|
2018-05-05 07:52:03 +08:00
|
|
|
version('8.1.0', '65f7c65818dc540b3437605026d329fc')
|
2018-12-08 23:22:28 +08:00
|
|
|
|
|
|
|
version('7.4.0', 'eddde28d04f334aec1604456e536416549e9b1aa137fc69204e65eb0c009fe51')
|
2018-01-31 20:41:12 +08:00
|
|
|
version('7.3.0', 'be2da21680f27624f3a87055c4ba5af2')
|
2017-08-15 18:14:07 +08:00
|
|
|
version('7.2.0', 'ff370482573133a7fcdd96cd2f552292')
|
2017-05-09 04:28:28 +08:00
|
|
|
version('7.1.0', '6bf56a2bca9dac9dbbf8e8d1036964a8')
|
2018-12-08 23:22:28 +08:00
|
|
|
|
|
|
|
version('6.5.0', '7ef1796ce497e89479183702635b14bb7a46b53249209a5e0f999bebf4740945')
|
2017-07-05 21:44:07 +08:00
|
|
|
version('6.4.0', '11ba51a0cfb8471927f387c8895fe232')
|
2016-12-26 10:52:58 +08:00
|
|
|
version('6.3.0', '677a7623c7ef6ab99881bc4e048debb6')
|
2016-08-23 08:26:54 +08:00
|
|
|
version('6.2.0', '9768625159663b300ae4de2f4745fcc4')
|
2016-05-04 04:58:14 +08:00
|
|
|
version('6.1.0', '8fb6cb98b8459f5863328380fbf06bd1')
|
2018-12-08 23:22:28 +08:00
|
|
|
|
2017-11-09 03:27:08 +08:00
|
|
|
version('5.5.0', '0f70424213b4a1113c04ba66ddda0c1f')
|
2016-07-22 03:36:22 +08:00
|
|
|
version('5.4.0', '4c626ac2a83ef30dfb9260e6f59c2b30')
|
2015-12-08 16:57:07 +08:00
|
|
|
version('5.3.0', 'c9616fd448f980259c31de613e575719')
|
2015-10-06 21:57:17 +08:00
|
|
|
version('5.2.0', 'a51bcfeb3da7dd4c623e27207ed43467')
|
2016-08-23 08:26:54 +08:00
|
|
|
version('5.1.0', 'd5525b1127d07d215960e6051c5da35e')
|
2018-12-08 23:22:28 +08:00
|
|
|
|
2016-08-23 08:26:54 +08:00
|
|
|
version('4.9.4', '87c24a4090c1577ba817ec6882602491')
|
2015-10-06 21:57:17 +08:00
|
|
|
version('4.9.3', '6f831b4d251872736e8e9cc09746f327')
|
2015-01-23 15:34:39 +08:00
|
|
|
version('4.9.2', '4df8ee253b7f3863ad0b86359cd39c43')
|
|
|
|
version('4.9.1', 'fddf71348546af523353bd43d34919c1')
|
2015-10-06 21:57:17 +08:00
|
|
|
version('4.8.5', '80d2c2982a3392bb0b89673ff136e223')
|
2015-01-23 15:34:39 +08:00
|
|
|
version('4.8.4', '5a84a30839b2aca22a2d723de2a626ec')
|
|
|
|
version('4.7.4', '4c696da46297de6ae77a82797d2abe28')
|
|
|
|
version('4.6.4', 'b407a3d1480c11667f293bfb1f17d1a4')
|
|
|
|
version('4.5.4', '27e459c2566b8209ab064570e1b378f7')
|
2016-01-04 09:22:13 +08:00
|
|
|
|
2017-12-03 17:19:55 +08:00
|
|
|
# We specifically do not add 'all' variant here because:
|
|
|
|
# (i) Ada, Go, Jit, and Objective-C++ are not default languages.
|
2017-05-09 04:28:28 +08:00
|
|
|
# In that respect, the name 'all' is rather misleading.
|
2017-12-03 17:19:55 +08:00
|
|
|
# (ii) Languages other than c,c++,fortran are prone to configure bug in GCC
|
|
|
|
# For example, 'java' appears to ignore custom location of zlib
|
|
|
|
# (iii) meaning of 'all' changes with GCC version, i.e. 'java' is not part
|
|
|
|
# of gcc7. Correctly specifying conflicts() and depends_on() in such a
|
|
|
|
# case is a PITA.
|
2017-05-09 04:28:28 +08:00
|
|
|
variant('languages',
|
2017-12-03 17:19:55 +08:00
|
|
|
default='c,c++,fortran',
|
|
|
|
values=('ada', 'brig', 'c', 'c++', 'fortran',
|
2017-05-09 04:28:28 +08:00
|
|
|
'go', 'java', 'jit', 'lto', 'objc', 'obj-c++'),
|
|
|
|
multi=True,
|
|
|
|
description='Compilers and runtime libraries to build')
|
2016-05-15 13:35:55 +08:00
|
|
|
variant('binutils',
|
2017-08-08 01:13:31 +08:00
|
|
|
default=False,
|
2017-05-09 04:28:28 +08:00
|
|
|
description='Build via binutils')
|
2016-08-18 00:28:21 +08:00
|
|
|
variant('piclibs',
|
|
|
|
default=False,
|
2017-05-09 04:28:28 +08:00
|
|
|
description='Build PIC versions of libgfortran.a and libstdc++.a')
|
2017-07-08 11:17:52 +08:00
|
|
|
variant('strip',
|
|
|
|
default=False,
|
|
|
|
description='Strip executables to reduce installation size')
|
2017-05-09 04:28:28 +08:00
|
|
|
|
|
|
|
# https://gcc.gnu.org/install/prerequisites.html
|
|
|
|
depends_on('gmp@4.3.2:')
|
2018-10-31 04:26:41 +08:00
|
|
|
# GCC 7.3 does not compile with newer releases on some platforms, see
|
|
|
|
# https://github.com/spack/spack/issues/6902#issuecomment-433030376
|
|
|
|
depends_on('mpfr@2.4.2:3.1.6')
|
2017-05-09 04:28:28 +08:00
|
|
|
depends_on('mpc@0.8.1:', when='@4.5:')
|
2018-10-31 04:26:41 +08:00
|
|
|
# Already released GCC versions do not support any newer version of ISL
|
|
|
|
# GCC 5.4 https://github.com/spack/spack/issues/6902#issuecomment-433072097
|
|
|
|
# GCC 7.3 https://github.com/spack/spack/issues/6902#issuecomment-433030376
|
|
|
|
# GCC 9+ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86724
|
|
|
|
depends_on('isl@0.15', when='@5:5.9')
|
|
|
|
depends_on('isl@0.15:0.18', when='@6:8.9')
|
|
|
|
depends_on('isl@0.15:0.20', when='@9:')
|
2017-05-09 04:28:28 +08:00
|
|
|
depends_on('zlib', when='@6:')
|
|
|
|
depends_on('gnat', when='languages=ada')
|
|
|
|
depends_on('binutils~libiberty', when='+binutils')
|
|
|
|
depends_on('zip', type='build', when='languages=java')
|
2014-11-06 01:54:43 +08:00
|
|
|
|
2016-03-28 04:18:23 +08:00
|
|
|
# TODO: integrate these libraries.
|
2017-05-09 04:28:28 +08:00
|
|
|
# depends_on('ppl')
|
|
|
|
# depends_on('cloog')
|
2017-03-25 03:56:22 +08:00
|
|
|
|
2018-04-11 00:46:44 +08:00
|
|
|
# https://gcc.gnu.org/install/test.html
|
|
|
|
depends_on('dejagnu@1.4.4', type='test')
|
|
|
|
depends_on('expect', type='test')
|
|
|
|
depends_on('tcl', type='test')
|
|
|
|
depends_on('autogen@5.5.4:', type='test')
|
|
|
|
depends_on('guile@1.4.1:', type='test')
|
2017-03-25 03:56:22 +08:00
|
|
|
|
2017-05-09 04:28:28 +08:00
|
|
|
# See https://golang.org/doc/install/gccgo#Releases
|
2017-05-25 08:13:18 +08:00
|
|
|
provides('golang', when='languages=go @4.6:')
|
|
|
|
provides('golang@:1', when='languages=go @4.7.1:')
|
|
|
|
provides('golang@:1.1', when='languages=go @4.8:')
|
|
|
|
provides('golang@:1.1.2', when='languages=go @4.8.2:')
|
|
|
|
provides('golang@:1.2', when='languages=go @4.9:')
|
|
|
|
provides('golang@:1.4', when='languages=go @5:')
|
|
|
|
provides('golang@:1.6.1', when='languages=go @6:')
|
|
|
|
provides('golang@:1.8', when='languages=go @7:')
|
2017-05-09 04:28:28 +08:00
|
|
|
|
|
|
|
# For a list of valid languages for a specific release,
|
|
|
|
# run the following command in the GCC source directory:
|
|
|
|
# $ grep ^language= gcc/*/config-lang.in
|
|
|
|
# See https://gcc.gnu.org/install/configure.html
|
|
|
|
|
|
|
|
# Support for processing BRIG 1.0 files was added in GCC 7
|
|
|
|
# BRIG is a binary format for HSAIL:
|
|
|
|
# (Heterogeneous System Architecture Intermediate Language).
|
|
|
|
# See https://gcc.gnu.org/gcc-7/changes.html
|
|
|
|
conflicts('languages=brig', when='@:6')
|
|
|
|
|
|
|
|
# BRIG does not seem to be supported on macOS
|
|
|
|
conflicts('languages=brig', when='platform=darwin')
|
|
|
|
|
|
|
|
# GCC 4.8 added a 'c' language. I'm sure C was always built,
|
|
|
|
# but this is the first version that accepts 'c' as a valid language.
|
|
|
|
conflicts('languages=c', when='@:4.7')
|
|
|
|
|
|
|
|
# GCC 4.6 added support for the Go programming language.
|
|
|
|
# See https://gcc.gnu.org/gcc-4.6/changes.html
|
|
|
|
conflicts('languages=go', when='@:4.5')
|
|
|
|
|
|
|
|
# Go is not supported on macOS
|
|
|
|
conflicts('languages=go', when='platform=darwin')
|
|
|
|
|
|
|
|
# The GCC Java frontend and associated libjava runtime library
|
|
|
|
# have been removed from GCC as of GCC 7.
|
|
|
|
# See https://gcc.gnu.org/gcc-7/changes.html
|
|
|
|
conflicts('languages=java', when='@7:')
|
|
|
|
|
|
|
|
# GCC 5 added the ability to build GCC as a Just-In-Time compiler.
|
|
|
|
# See https://gcc.gnu.org/gcc-5/changes.html
|
|
|
|
conflicts('languages=jit', when='@:4')
|
|
|
|
|
2016-03-29 05:28:29 +08:00
|
|
|
if sys.platform == 'darwin':
|
2017-10-13 02:41:57 +08:00
|
|
|
# Fix parallel build on APFS filesystem
|
|
|
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81797
|
2018-06-28 00:31:21 +08:00
|
|
|
if macos_version() >= Version('10.13'):
|
2018-06-24 08:40:42 +08:00
|
|
|
patch('darwin/apfs.patch', when='@5.5.0,6.1:6.4,7.1:7.3')
|
|
|
|
# from homebrew via macports
|
|
|
|
# https://trac.macports.org/ticket/56502#no1
|
|
|
|
# see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83531
|
|
|
|
patch('darwin/headers-10.13-fix.patch', when='@5.5.0')
|
2017-05-09 04:28:28 +08:00
|
|
|
patch('darwin/gcc-7.1.0-headerpad.patch', when='@5:')
|
2018-05-06 22:28:33 +08:00
|
|
|
patch('darwin/gcc-6.1.0-jit.patch', when='@5:7')
|
2017-04-11 20:37:44 +08:00
|
|
|
patch('darwin/gcc-4.9.patch1', when='@4.9.0:4.9.3')
|
|
|
|
patch('darwin/gcc-4.9.patch2', when='@4.9.0:4.9.3')
|
2014-10-09 12:59:47 +08:00
|
|
|
|
2016-08-18 00:28:21 +08:00
|
|
|
patch('piclibs.patch', when='+piclibs')
|
2016-11-07 07:31:48 +08:00
|
|
|
patch('gcc-backport.patch', when='@4.7:4.9.2,5:5.3')
|
2016-08-18 00:28:21 +08:00
|
|
|
|
2018-07-04 20:39:07 +08:00
|
|
|
# Older versions do not compile with newer versions of glibc
|
|
|
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81712
|
|
|
|
patch('ucontext_t.patch', when='@4.9,5.1:5.4,6.1:6.4,7.1')
|
|
|
|
patch('ucontext_t-java.patch', when='@4.9,5.1:5.4,6.1:6.4 languages=java')
|
|
|
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81066
|
|
|
|
patch('stack_t-4.9.patch', when='@4.9')
|
|
|
|
patch('stack_t.patch', when='@5.1:5.4,6.1:6.4,7.1')
|
|
|
|
# https://bugs.busybox.net/show_bug.cgi?id=10061
|
|
|
|
patch('signal.patch', when='@4.9,5.1:5.4')
|
2018-12-08 10:06:07 +08:00
|
|
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85835
|
2018-12-12 12:54:12 +08:00
|
|
|
patch('sys_ustat.h.patch', when='@5.0:6.4,7.0:7.3,8.1')
|
|
|
|
patch('sys_ustat-4.9.patch', when='@4.9')
|
2018-07-04 20:39:07 +08:00
|
|
|
|
2017-05-09 04:28:28 +08:00
|
|
|
build_directory = 'spack-build'
|
|
|
|
|
2017-07-05 21:44:07 +08:00
|
|
|
def url_for_version(self, version):
|
|
|
|
url = 'http://ftp.gnu.org/gnu/gcc/gcc-{0}/gcc-{0}.tar.{1}'
|
2017-08-15 18:14:07 +08:00
|
|
|
suffix = 'xz'
|
2017-07-05 21:44:07 +08:00
|
|
|
|
2017-08-15 18:14:07 +08:00
|
|
|
if version < Version('6.4.0') or version == Version('7.1.0'):
|
|
|
|
suffix = 'bz2'
|
2017-07-05 21:44:07 +08:00
|
|
|
|
2017-11-09 03:27:08 +08:00
|
|
|
if version == Version('5.5.0'):
|
|
|
|
suffix = 'xz'
|
|
|
|
|
2017-07-05 21:44:07 +08:00
|
|
|
return url.format(version, suffix)
|
|
|
|
|
2017-05-09 04:28:28 +08:00
|
|
|
def patch(self):
|
2017-01-26 18:27:15 +08:00
|
|
|
spec = self.spec
|
|
|
|
prefix = self.spec.prefix
|
2014-11-06 01:54:43 +08:00
|
|
|
|
2016-10-03 09:54:43 +08:00
|
|
|
# Fix a standard header file for OS X Yosemite that
|
|
|
|
# is GCC incompatible by replacing non-GCC compliant macros
|
|
|
|
if 'yosemite' in spec.architecture:
|
2017-05-09 04:28:28 +08:00
|
|
|
if os.path.isfile('/usr/include/dispatch/object.h'):
|
2016-10-03 09:54:43 +08:00
|
|
|
new_dispatch_dir = join_path(prefix, 'include', 'dispatch')
|
|
|
|
mkdirp(new_dispatch_dir)
|
|
|
|
new_header = join_path(new_dispatch_dir, 'object.h')
|
2018-08-16 00:30:09 +08:00
|
|
|
install('/usr/include/dispatch/object.h', new_header)
|
2016-10-03 09:54:43 +08:00
|
|
|
filter_file(r'typedef void \(\^dispatch_block_t\)\(void\)',
|
|
|
|
'typedef void* dispatch_block_t',
|
|
|
|
new_header)
|
|
|
|
|
2017-05-20 01:03:56 +08:00
|
|
|
# Use installed libz
|
|
|
|
if self.version >= Version('6'):
|
|
|
|
filter_file('@zlibdir@',
|
|
|
|
'-L{0}'.format(spec['zlib'].prefix.lib),
|
|
|
|
'gcc/Makefile.in')
|
|
|
|
filter_file('@zlibinc@',
|
|
|
|
'-I{0}'.format(spec['zlib'].prefix.include),
|
|
|
|
'gcc/Makefile.in')
|
|
|
|
|
2017-05-09 04:28:28 +08:00
|
|
|
def configure_args(self):
|
|
|
|
spec = self.spec
|
|
|
|
|
2015-09-26 16:12:24 +08:00
|
|
|
# Generic options to compile GCC
|
2017-03-25 03:56:22 +08:00
|
|
|
options = [
|
|
|
|
'--disable-multilib',
|
2017-05-09 04:28:28 +08:00
|
|
|
'--enable-languages={0}'.format(
|
|
|
|
','.join(spec.variants['languages'].value)),
|
2017-03-25 03:56:22 +08:00
|
|
|
'--with-mpfr={0}'.format(spec['mpfr'].prefix),
|
|
|
|
'--with-gmp={0}'.format(spec['gmp'].prefix),
|
|
|
|
'--enable-lto',
|
|
|
|
'--with-quad'
|
|
|
|
]
|
|
|
|
|
2017-05-09 04:28:28 +08:00
|
|
|
# Use installed libz
|
|
|
|
if self.version >= Version('6'):
|
|
|
|
options.append('--with-system-zlib')
|
|
|
|
|
|
|
|
# Enabling language "jit" requires --enable-host-shared.
|
|
|
|
if 'languages=jit' in spec:
|
|
|
|
options.append('--enable-host-shared')
|
|
|
|
|
2015-09-26 16:12:24 +08:00
|
|
|
# Binutils
|
2016-02-13 01:51:43 +08:00
|
|
|
if spec.satisfies('+binutils'):
|
2017-05-09 04:28:28 +08:00
|
|
|
static_bootstrap_flags = '-static-libstdc++ -static-libgcc'
|
2016-05-15 13:35:55 +08:00
|
|
|
binutils_options = [
|
2017-05-09 04:28:28 +08:00
|
|
|
'--with-sysroot=/',
|
|
|
|
'--with-stage1-ldflags={0} {1}'.format(
|
|
|
|
self.rpath_args, static_bootstrap_flags),
|
|
|
|
'--with-boot-ldflags={0} {1}'.format(
|
|
|
|
self.rpath_args, static_bootstrap_flags),
|
|
|
|
'--with-gnu-ld',
|
|
|
|
'--with-ld={0}/ld'.format(spec['binutils'].prefix.bin),
|
|
|
|
'--with-gnu-as',
|
|
|
|
'--with-as={0}/as'.format(spec['binutils'].prefix.bin),
|
2016-05-15 13:35:55 +08:00
|
|
|
]
|
2016-02-13 01:51:43 +08:00
|
|
|
options.extend(binutils_options)
|
2017-03-25 03:56:22 +08:00
|
|
|
|
|
|
|
# MPC
|
|
|
|
if 'mpc' in spec:
|
|
|
|
options.append('--with-mpc={0}'.format(spec['mpc'].prefix))
|
|
|
|
|
|
|
|
# ISL
|
2016-02-15 06:40:25 +08:00
|
|
|
if 'isl' in spec:
|
2017-03-25 03:56:22 +08:00
|
|
|
options.append('--with-isl={0}'.format(spec['isl'].prefix))
|
2015-09-26 16:12:24 +08:00
|
|
|
|
2017-03-25 03:56:22 +08:00
|
|
|
# macOS
|
2016-05-15 13:35:55 +08:00
|
|
|
if sys.platform == 'darwin':
|
2017-03-25 03:56:22 +08:00
|
|
|
options.append('--with-build-config=bootstrap-debug')
|
2016-03-29 05:28:29 +08:00
|
|
|
|
2017-01-26 18:27:15 +08:00
|
|
|
return options
|
2016-01-21 18:40:38 +08:00
|
|
|
|
2017-01-26 18:27:15 +08:00
|
|
|
@property
|
|
|
|
def build_targets(self):
|
|
|
|
if sys.platform == 'darwin':
|
|
|
|
return ['bootstrap']
|
|
|
|
return []
|
2014-11-06 01:54:43 +08:00
|
|
|
|
2017-07-08 11:17:52 +08:00
|
|
|
@property
|
|
|
|
def install_targets(self):
|
|
|
|
if '+strip' in self.spec:
|
|
|
|
return ['install-strip']
|
|
|
|
return ['install']
|
|
|
|
|
2014-11-06 01:54:43 +08:00
|
|
|
@property
|
|
|
|
def spec_dir(self):
|
2017-05-09 04:28:28 +08:00
|
|
|
# e.g. lib/gcc/x86_64-unknown-linux-gnu/4.9.2
|
|
|
|
spec_dir = glob.glob('{0}/gcc/*/*'.format(self.prefix.lib))
|
2014-11-06 01:54:43 +08:00
|
|
|
return spec_dir[0] if spec_dir else None
|
|
|
|
|
2017-01-26 18:27:15 +08:00
|
|
|
@run_after('install')
|
2014-11-06 01:54:43 +08:00
|
|
|
def write_rpath_specs(self):
|
|
|
|
"""Generate a spec file so the linker adds a rpath to the libs
|
|
|
|
the compiler used to build the executable."""
|
|
|
|
if not self.spec_dir:
|
2017-05-09 04:28:28 +08:00
|
|
|
tty.warn('Could not install specs for {0}.'.format(
|
|
|
|
self.spec.format('$_$@')))
|
2014-11-06 01:54:43 +08:00
|
|
|
return
|
|
|
|
|
Python command, libraries, and headers (#3367)
## Motivation
Python installations are both important and unfortunately inconsistent. Depending on the Python version, OS, and the strength of the Earth's magnetic field when it was installed, the name of the Python executable, directory containing its libraries, library names, and the directory containing its headers can vary drastically.
I originally got into this mess with #3274, where I discovered that Boost could not be built with Python 3 because the executable is called `python3` and we were telling it to use `python`. I got deeper into this mess when I started hacking on #3140, where I discovered just how difficult it is to find the location and name of the Python libraries and headers.
Currently, half of the packages that depend on Python and need to know this information jump through hoops to determine the correct information. The other half are hard-coded to use `python`, `spec['python'].prefix.lib`, and `spec['python'].prefix.include`. Obviously, none of these packages would work for Python 3, and there's no reason to duplicate the effort. The Python package itself should contain all of the information necessary to use it properly. This is in line with the recent work by @alalazo and @davydden with respect to `spec['blas'].libs` and friends.
## Prefix
For most packages in Spack, we assume that the installation directory is `spec['python'].prefix`. This generally works for anything installed with Spack, but gets complicated when we include external packages. Python is a commonly used external package (it needs to be installed just to run Spack). If it was installed with Homebrew, `which python` would return `/usr/local/bin/python`, and most users would erroneously assume that `/usr/local` is the installation directory. If you peruse through #2173, you'll immediately see why this is not the case. Homebrew actually installs Python in `/usr/local/Cellar/python/2.7.12_2` and symlinks the executable to `/usr/local/bin/python`. `PYTHONHOME` (and presumably most things that need to know where Python is installed) needs to be set to the actual installation directory, not `/usr/local`.
Normally I would say, "sounds like user error, make sure to use the real installation directory in your `packages.yaml`". But I think we can make a special case for Python. That's what we decided in #2173 anyway. If we change our minds, I would be more than happy to simplify things.
To solve this problem, I created a `spec['python'].home` attribute that works the same way as `spec['python'].prefix` but queries Python to figure out where it was actually installed. @tgamblin Is there any way to overwrite `spec['python'].prefix`? I think it's currently immutable.
## Command
In general, Python 2 comes with both `python` and `python2` commands, while Python 3 only comes with a `python3` command. But this is up to the OS developers. For example, `/usr/bin/python` on Gentoo is actually Python 3. Worse yet, if someone is using an externally installed Python, all 3 commands may exist in the same directory! Here's what I'm thinking:
If the spec is for Python 3, try searching for the `python3` command.
If the spec is for Python 2, try searching for the `python2` command.
If neither are found, try searching for the `python` command.
## Libraries
Spack installs Python libraries in `spec['python'].prefix.lib`. Except on openSUSE 13, where it installs to `spec['python'].prefix.lib64` (see #2295 and #2253). On my CentOS 6 machine, the Python libraries are installed in `/usr/lib64`. Both need to work.
The libraries themselves change name depending on OS and Python version. For Python 2.7 on macOS, I'm seeing:
```
lib/libpython2.7.dylib
```
For Python 3.6 on CentOS 6, I'm seeing:
```
lib/libpython3.so
lib/libpython3.6m.so.1.0
lib/libpython3.6m.so -> lib/libpython3.6m.so.1.0
```
Notice the `m` after the version number. Yeah, that's a thing.
## Headers
In Python 2.7, I'm seeing:
```
include/python2.7/pyconfig.h
```
In Python 3.6, I'm seeing:
```
include/python3.6m/pyconfig.h
```
It looks like all Python 3 installations have this `m`. Tested with Python 3.2 and 3.6 on macOS and CentOS 6
Spack has really nice support for libraries (`find_libraries` and `LibraryList`), but nothing for headers. Fixed.
2017-04-30 08:24:13 +08:00
|
|
|
gcc = self.spec['gcc'].command
|
2017-05-09 04:28:28 +08:00
|
|
|
lines = gcc('-dumpspecs', output=str).strip().split('\n')
|
2015-10-06 21:57:17 +08:00
|
|
|
specs_file = join_path(self.spec_dir, 'specs')
|
2017-05-09 04:28:28 +08:00
|
|
|
with open(specs_file, 'w') as out:
|
2015-10-06 21:57:17 +08:00
|
|
|
for line in lines:
|
2017-05-09 04:28:28 +08:00
|
|
|
out.write(line + '\n')
|
|
|
|
if line.startswith('*link:'):
|
2017-05-10 07:51:40 +08:00
|
|
|
out.write('-rpath {0}:{1} '.format(
|
2017-05-09 04:28:28 +08:00
|
|
|
self.prefix.lib, self.prefix.lib64))
|
2015-10-06 21:57:17 +08:00
|
|
|
set_install_permissions(specs_file)
|
2017-11-23 19:44:55 +08:00
|
|
|
|
|
|
|
def setup_environment(self, spack_env, run_env):
|
|
|
|
run_env.set('CC', join_path(self.spec.prefix.bin, 'gcc'))
|
|
|
|
run_env.set('CXX', join_path(self.spec.prefix.bin, 'g++'))
|
|
|
|
run_env.set('FC', join_path(self.spec.prefix.bin, 'gfortran'))
|
|
|
|
run_env.set('F77', join_path(self.spec.prefix.bin, 'gfortran'))
|
|
|
|
run_env.set('F90', join_path(self.spec.prefix.bin, 'gfortran'))
|