summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/flang/package.py
blob: 364448e4bdee332eaa41e04d38abd32f31ca2950 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)


from spack import *
import os


class Flang(CMakePackage):
    """Flang is a Fortran compiler targeting LLVM."""

    homepage = "https://github.com/flang-compiler/flang"

    url      = "https://github.com/flang-compiler/flang/archive/flang_20180612.tar.gz"
    git      = "https://github.com/flang-compiler/flang.git"

    version('develop', branch='master')
    version('20180921', '4440ed5fdc390e4b7a085fb77b44ac54')
    version('20180612', '62284e26214eaaff261a922c67f6878c')

    depends_on('llvm@flang-develop', when='@develop')
    depends_on('llvm@flang-20180921', when='@20180921 target=x86_64:')
    depends_on('llvm@flang-20180612', when='@20180612 target=x86_64:')

    depends_on('llvm@flang-20180921', when='@20180921 target=aarch64:')

    # LLVM version specific to OpenPOWER.
    depends_on('llvm@flang-ppc64le-20180921', when='@20180921 target=ppc64le:')
    depends_on('llvm@flang-ppc64le-20180612', when='@20180612 target=ppc64le:')

    depends_on('pgmath@develop', when='@develop')
    depends_on('pgmath@20180921', when='@20180921')
    depends_on('pgmath@20180612', when='@20180612')

    def cmake_args(self):
        options = [
            '-DWITH_WERROR=OFF',
            '-DCMAKE_C_COMPILER=%s' % os.path.join(
                self.spec['llvm'].prefix.bin, 'clang'),
            '-DCMAKE_CXX_COMPILER=%s' % os.path.join(
                self.spec['llvm'].prefix.bin, 'clang++'),
            '-DCMAKE_Fortran_COMPILER=%s' % os.path.join(
                self.spec['llvm'].prefix.bin, 'flang'),
            '-DFLANG_LIBOMP=%s' % find_libraries(
                'libomp', root=self.spec['llvm'].prefix.lib)
        ]

        return options

    @run_after('install')
    def post_install(self):
        # we are installing flang in a path different from llvm, so we
        # create a wrapper with -L for e.g. libflangrti.so and -I for
        # e.g. iso_c_binding.mod. -B is needed to help flang to find
        # flang1 and flang2. rpath_arg is needed so that executables
        # generated by flang can find libflang later.
        flang = os.path.join(self.spec.prefix.bin, 'flang')
        with open(flang, 'w') as out:
            out.write('#!/bin/bash\n')
            out.write(
                '{0} -I{1} -L{2} -L{3} {4}{5} {6}{7} -B{8} "$@"\n'.format(
                    self.spec['llvm'].prefix.bin.flang,
                    self.prefix.include, self.prefix.lib,
                    self.spec['pgmath'].prefix.lib,
                    self.compiler.fc_rpath_arg, self.prefix.lib,
                    self.compiler.fc_rpath_arg,
                    self.spec['pgmath'].prefix.lib, self.spec.prefix.bin))
            out.close()
        chmod = which('chmod')
        chmod('+x', flang)

    def setup_environment(self, spack_env, run_env):
        # to find llvm's libc++.so
        spack_env.set('LD_LIBRARY_PATH', self.spec['llvm'].prefix.lib)
        run_env.set('FC', join_path(self.spec.prefix.bin, 'flang'))
        run_env.set('F77', join_path(self.spec.prefix.bin, 'flang'))
        run_env.set('F90', join_path(self.spec.prefix.bin, 'flang'))