summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/netcdf/package.py
blob: ab40c1434002e31c6c19ac61cca1cedf3d41e423 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
##############################################################################
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/llnl/spack
# Please also see the LICENSE file for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *


class Netcdf(Package):
    """NetCDF is a set of software libraries and self-describing,
    machine-independent data formats that support the creation, access,
    and sharing of array-oriented scientific data.

    """

    homepage = "http://www.unidata.ucar.edu/software/netcdf"
    url      = "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.3.3.tar.gz"

    version('4.4.1', '7843e35b661c99e1d49e60791d5072d8')
    version('4.4.0', 'cffda0cbd97fdb3a06e9274f7aef438e')
    version('4.3.3', '5fbd0e108a54bd82cb5702a73f56d2ae')

    variant('mpi',  default=True,  description='Enables MPI parallelism')
    variant('hdf4', default=False, description='Enable HDF4 support')

    depends_on("m4", type='build')
    depends_on("hdf", when='+hdf4')

    # Required for DAP support
    depends_on("curl")

    # Required for NetCDF-4 support
    depends_on("zlib")
    depends_on('hdf5@:1.8+mpi', when='@:4.4.0+mpi')
    depends_on('hdf5+mpi', when='@4.4.1:+mpi')
    depends_on('hdf5@:1.8~mpi', when='@:4.4.0~mpi')
    depends_on('hdf5~mpi', when='@4.4.1:~mpi')

    def install(self, spec, prefix):
        # Environment variables
        CPPFLAGS = []
        LDFLAGS  = []
        LIBS     = []

        config_args = [
            "--prefix=%s" % prefix,
            "--enable-fsync",
            "--enable-v2",
            "--enable-utilities",
            "--enable-shared",
            "--enable-static",
            "--enable-largefile",
            # necessary for HDF5 support
            "--enable-netcdf-4",
            "--enable-dynamic-loading",
            # necessary for DAP support
            "--enable-dap"
        ]

        # Make sure Netcdf links against Spack's curl, otherwise
        # otherwise it may pick up system's curl, which can give link
        # errors, e.g.:
        # undefined reference to `SSL_CTX_use_certificate_chain_file`
        LIBS.append("-lcurl")
        CPPFLAGS.append("-I%s" % spec['curl'].prefix.include)
        LDFLAGS.append("-L%s" % spec['curl'].prefix.lib)

        if '+mpi' in spec:
            config_args.append('--enable-parallel4')

        CPPFLAGS.append("-I%s/include" % spec['hdf5'].prefix)
        LDFLAGS.append("-L%s/lib"     % spec['hdf5'].prefix)

        # HDF4 support
        # As of NetCDF 4.1.3, "--with-hdf4=..." is no longer a valid option
        # You must use the environment variables CPPFLAGS and LDFLAGS
        if '+hdf4' in spec:
            config_args.append("--enable-hdf4")
            CPPFLAGS.append("-I%s/include" % spec['hdf'].prefix)
            LDFLAGS.append("-L%s/lib"     % spec['hdf'].prefix)
            LIBS.append("-l%s"         % "jpeg")

        if 'szip' in spec:
            CPPFLAGS.append("-I%s/include" % spec['szip'].prefix)
            LDFLAGS.append("-L%s/lib"     % spec['szip'].prefix)
            LIBS.append("-l%s"         % "sz")

        # Fortran support
        # In version 4.2+, NetCDF-C and NetCDF-Fortran have split.
        # Use the netcdf-fortran package to install Fortran support.

        config_args.append('CPPFLAGS=%s' % ' '.join(CPPFLAGS))
        config_args.append('LDFLAGS=%s'  % ' '.join(LDFLAGS))
        config_args.append('LIBS=%s'     % ' '.join(LIBS))

        configure(*config_args)
        make()
        make("install")