22# Spack Project Developers. See the top-level COPYRIGHT file for details.
33#
44# SPDX-License-Identifier: (Apache-2.0 OR MIT)
5-
5+ import os
66from spack import *
77
88
@@ -27,7 +27,8 @@ class Gdl(CMakePackage):
2727 variant ('hdf5' , default = True , description = 'Enable HDF5' )
2828 variant ('openmp' , default = True , description = 'Enable OpenMP' )
2929 variant ('proj' , default = True , description = 'Enable LIBPROJ4' )
30- variant ('python' , default = False , description = 'Enable Python' )
30+ variant ('embed_python' , default = False , description = 'Ability to embed Python within GDL' )
31+ variant ('python' , default = False , description = 'Build the GDL Python module' )
3132 variant ('wx' , default = False , description = 'Enable WxWidgets' )
3233 variant ('x11' , default = False , description = 'Enable X11' )
3334
@@ -41,8 +42,8 @@ class Gdl(CMakePackage):
4142 depends_on (
'plplot+wx+wxold' ,
when = '[email protected] :' )
4243 depends_on ('plplot~wx' , when = '~wx' )
4344 depends_on ('proj' , when = '+proj' )
44- depends_on ('py-numpy' , type = ('build' , 'run' ), when = '+python ' )
45- depends_on (
'[email protected] :2.8' ,
type = (
'build' ,
'run' ),
when = '+python ' )
45+ depends_on ('py-numpy' , type = ('build' , 'run' ), when = '+embed_python ' )
46+ depends_on (
'[email protected] :2.8' ,
type = (
'build' ,
'run' ),
when = '+embed_python ' )
4647 depends_on ('wx' , when = '+wx' )
4748
4849 depends_on ('eigen' )
@@ -57,6 +58,21 @@ class Gdl(CMakePackage):
5758 depends_on ('pslib' )
5859 depends_on ('readline' )
5960
61+ conflicts ('+python' , when = '~embed_python' )
62+
63+ # Building the Python module requires patches currently targetting 0.9.8
64+ # othwerwise asking for the Python module *only* builds the Python module
65+ conflicts ('+python' , when = '@:0.9.7,0.9.9:' )
66+
67+ # Allows building gdl as a shared library to in turn allow building
68+ # both the executable and the Python module
69+ patch ('https://sources.debian.org/data/main/g/gnudatalanguage/0.9.8-7/debian/patches/Create-a-shared-library.patch' ,
70+ sha256 = 'bb380394c8ea2602404d8cd18047b93cf00fdb73b83d389f30100dd4b0e1a05c' ,
71+ when = '@0.9.8' )
72+ patch ('Always-build-antlr-as-shared-library.patch' ,
73+ sha256 = 'f40c06e8a8f1977780787f58885590affd7e382007cb677d2fb4723aaadd415c' ,
74+ when = '@0.9.8' )
75+
6076 def cmake_args (self ):
6177 args = []
6278
@@ -92,11 +108,16 @@ def cmake_args(self):
92108 else :
93109 args += ['-DLIBPROJ4=OFF' ]
94110
95- if '+python ' in self .spec :
111+ if '+embed_python ' in self .spec :
96112 args += ['-DPYTHON=ON' ]
97113 else :
98114 args += ['-DPYTHON=OFF' ]
99115
116+ if '+python' in self .spec :
117+ args += ['-DPYTHON_MODULE=ON' ]
118+ else :
119+ args += ['-DPYTHON_MODULE=OFF' ]
120+
100121 if '+wx' in self .spec :
101122 args += ['-DWXWIDGETS=ON' ]
102123 else :
@@ -108,3 +129,19 @@ def cmake_args(self):
108129 args += ['-DX11=OFF' ]
109130
110131 return args
132+
133+ @run_after ('install' )
134+ def post_install (self ):
135+ if '+python' in self .spec :
136+ # gdl installs the python module into prefix/lib/site-python
137+ # move it to the standard location
138+ src = os .path .join (
139+ self .spec .prefix .lib ,
140+ 'site-python' )
141+ dst = site_packages_dir
142+ if os .path .isdir (src ):
143+ if not os .path .isdir (dst ):
144+ mkdirp (dst )
145+ for f in os .listdir (src ):
146+ os .rename (os .path .join (src , f ),
147+ os .path .join (dst , f ))
0 commit comments