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
118
119
120
|
##############################################################################
# Copyright (c) 2013-2018, 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/spack/spack
# Please also see the NOTICE and LICENSE files 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 Bzip2(Package):
"""bzip2 is a freely available, patent free high-quality data
compressor. It typically compresses files to within 10% to 15%
of the best available techniques (the PPM family of statistical
compressors), whilst being around twice as fast at compression
and six times faster at decompression."""
homepage = "http://www.bzip.org"
url = "http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz"
list_url = "http://www.bzip.org/downloads.html"
version('1.0.6', '00b516f4704d4a7cb50a1d97e6e8e15b')
variant('shared', default=True, description='Enables the build of shared libraries.')
# override default implementation
@property
def libs(self):
shared = '+shared' in self.spec
return find_libraries(
'libbz2', root=self.prefix, shared=shared, recursive=True
)
def patch(self):
# bzip2 comes with two separate Makefiles for static and dynamic builds
# Tell both to use Spack's compiler wrapper instead of GCC
filter_file(r'^CC=gcc', 'CC={0}'.format(spack_cc), 'Makefile')
filter_file(
r'^CC=gcc', 'CC={0}'.format(spack_cc), 'Makefile-libbz2_so'
)
# The Makefiles use GCC flags that are incompatible with PGI
if self.compiler.name == 'pgi':
filter_file('-Wall -Winline', '-Minform=inform', 'Makefile')
filter_file('-Wall -Winline', '-Minform=inform', 'Makefile-libbz2_so') # noqa
# Patch the link line to use RPATHs on macOS
if 'darwin' in self.spec.architecture:
v = self.spec.version
v1, v2, v3 = (v.up_to(i) for i in (1, 2, 3))
kwargs = {'ignore_absent': False, 'backup': False, 'string': True}
mf = FileFilter('Makefile-libbz2_so')
mf.filter('$(CC) -shared -Wl,-soname -Wl,libbz2.so.{0} -o libbz2.so.{1} $(OBJS)' # noqa
.format(v2, v3),
'$(CC) -dynamiclib -Wl,-install_name -Wl,@rpath/libbz2.{0}.dylib -current_version {1} -compatibility_version {2} -o libbz2.{3}.dylib $(OBJS)' # noqa
.format(v1, v2, v3, v3),
**kwargs)
mf.filter(
'$(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.{0}'.format(v3), # noqa
'$(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.{0}.dylib'
.format(v3), **kwargs)
mf.filter(
'rm -f libbz2.so.{0}'.format(v2),
'rm -f libbz2.{0}.dylib'.format(v2), **kwargs)
mf.filter(
'ln -s libbz2.so.{0} libbz2.so.{1}'.format(v3, v2),
'ln -s libbz2.{0}.dylib libbz2.{1}.dylib'.format(v3, v2),
**kwargs)
def install(self, spec, prefix):
# Build the dynamic library first
if '+shared' in spec:
make('-f', 'Makefile-libbz2_so')
# Build the static library and everything else
make()
make('install', 'PREFIX={0}'.format(prefix))
if '+shared' in spec:
install('bzip2-shared', join_path(prefix.bin, 'bzip2'))
v1, v2, v3 = (self.spec.version.up_to(i) for i in (1, 2, 3))
if 'darwin' in self.spec.architecture:
lib = 'libbz2.dylib'
lib1, lib2, lib3 = ('libbz2.{0}.dylib'.format(v)
for v in (v1, v2, v3))
else:
lib = 'libbz2.so'
lib1, lib2, lib3 = ('libbz2.so.{0}'.format(v)
for v in (v1, v2, v3))
install(lib3, join_path(prefix.lib, lib3))
with working_dir(prefix.lib):
for l in (lib, lib1, lib2):
symlink(lib3, l)
with working_dir(prefix.bin):
force_remove('bunzip2', 'bzcat')
symlink('bzip2', 'bunzip2')
symlink('bzip2', 'bzcat')
|