# Copyright 2013-2020 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 *


class NetcdfCxx4(AutotoolsPackage):
    """NetCDF (network Common Data Form) is a set of software libraries and
    machine-independent data formats that support the creation, access, and
    sharing of array-oriented scientific data. This is the C++ distribution."""

    homepage = "https://www.unidata.ucar.edu/software/netcdf"
    url      = "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-cxx4-4.3.1.tar.gz"

    maintainers = ['WardF']

    version('4.3.1', sha256='6a1189a181eed043b5859e15d5c080c30d0e107406fbb212c8fb9814e90f3445')
    version('4.3.0', sha256='e34fbc6aba243ec82c23e9ee99db2430555ada849c54c1f3ab081b0ddd0f5f30')

    # Usually the configure automatically inserts the pic flags, but we can
    # force its usage with this variant.
    variant('pic', default=True, description='Produce position-independent code (for shared libs)')

    depends_on('netcdf-c')

    depends_on('automake', type='build')
    depends_on('autoconf', type='build')
    depends_on('libtool', type='build')
    depends_on('m4', type='build')

    force_autoreconf = True

    def flag_handler(self, name, flags):
        if name == 'cflags' and '+pic' in self.spec:
            flags.append(self.compiler.pic_flag)
        elif name == 'cppflags':
            flags.append('-I' + self.spec['netcdf-c'].prefix.include)

        return (None, None, flags)

    @property
    def libs(self):
        shared = True
        return find_libraries(
            'libnetcdf_c++4', root=self.prefix, shared=shared, recursive=True
        )

@@ -981,92 +981,699 @@
 nt('
-pic', default=True, description='Produce position-independent code (for shared libs)
+static', default=True, description='Enable building static libraries')%0A    variant('shared', default=True, description='Enable shared library')%0A    variant('pic', default=True, description='Produce position-independent code (for shared libs)')%0A    variant('dap', default=False, description='Enable DAP support')%0A    variant('jna', default=False, description='Enable JNA support')%0A    variant('doxygen', default=True, description='Enable doxygen docs')%0A    variant('ncgen4', default=True, description='Enable generating netcdf-4 data')%0A    variant('pnetcdf', default=True, description='Enable parallel-netcdf')%0A    variant('netcdf4', default=False, description='Enable netcdf-4 data structure
 ')%0A%0A
@@ -1854,24 +1854,66 @@
 e='build')%0A%0A
+    conflicts('~shared', when='~static')%0A%0A
     force_au
@@ -2373,22 +2373,22 @@
 ursive=True%0A
-
         )%0A
@@ -2387,8 +2387,1408 @@
       )%0A
+%0A    def configure_args(self):%0A%0A        if '+static' in self.spec:%0A            config_args.append('--enable-static')%0A        else:%0A            config_args.append('--disable-static')%0A%0A        if '+shared' in self.spec:%0A            config_args.append('--enable-shared')%0A        else:%0A            config_args.append('--disable-shared')%0A%0A        if '+pic' in self.spec:%0A            config_args.append('--with-pic')%0A        else:%0A            config_args.append('--without-pic')%0A%0A        if '+dap' in self.spec:%0A            config_args.append('--enable-dap')%0A        else:%0A            config_args.append('--disable-dap')%0A%0A        if '+jna' in self.spec:%0A            config_args.append('--enable-jna')%0A        else:%0A            config_args.append('--disable-jna')%0A%0A        if '+pnetcdf' in self.spec:%0A            config_args.append('--enable-pnetcdf')%0A        else:%0A            config_args.append('--disable-pnetcdf')%0A%0A        if '+netcdf4' in self.spec:%0A            config_args.append('--enable-netcdf-4')%0A        else:%0A            config_args.append('--disable-netcdf-4')%0A%0A        if '+ncgen4' in self.spec:%0A            config_args.append('--enable-ncgen4')%0A        else:%0A            config_args.append('--disable-ncgen4')%0A%0A        if '+doxygen' in self.spec:%0A            config_args.append('--enable-doxygen')%0A        else:%0A            config_args.append('--disable-doxygen')%0A%0A        return config_args%0A

Add new variants (#16047)