|
1 |
| -from conans import ConanFile, tools, AutoToolsBuildEnvironment |
2 |
| -from conans.errors import ConanException, ConanInvalidConfiguration |
| 1 | +from conan import ConanFile |
| 2 | +from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps |
| 3 | +from conan.errors import ConanInvalidConfiguration |
| 4 | +from conan.tools.layout import basic_layout |
| 5 | +from conan.tools.apple import XCRun |
| 6 | +from conan.tools.files import copy, get, replace_in_file, rmdir, rm |
| 7 | +from conan.tools.build import cross_building |
| 8 | +from conan.tools.env import VirtualBuildEnv |
3 | 9 | import os
|
4 | 10 |
|
5 |
| -required_conan_version = ">=1.29.1" |
| 11 | +required_conan_version = ">=1.53.0" |
6 | 12 |
|
7 | 13 |
|
8 | 14 | class GccConan(ConanFile):
|
9 | 15 | name = "gcc"
|
10 |
| - description = "The GNU Compiler Collection includes front ends for C, " \ |
11 |
| - "C++, Objective-C, Fortran, Ada, Go, and D, as well as " \ |
12 |
| - "libraries for these languages (libstdc++,...). " |
| 16 | + description = ( |
| 17 | + "The GNU Compiler Collection includes front ends for C, " |
| 18 | + "C++, Objective-C, Fortran, Ada, Go, and D, as well as " |
| 19 | + "libraries for these languages (libstdc++,...). " |
| 20 | + ) |
13 | 21 | topics = ("gcc", "gnu", "compiler", "c", "c++")
|
14 | 22 | homepage = "https://gcc.gnu.org"
|
15 | 23 | url = "https://github.com/conan-io/conan-center-index"
|
16 | 24 | license = "GPL-3.0-only"
|
17 | 25 | settings = "os", "compiler", "arch", "build_type"
|
18 |
| - _autotools = None |
19 | 26 |
|
20 |
| - def build_requirements(self): |
21 |
| - self.build_requires("flex/2.6.4") |
22 |
| - |
23 |
| - def _configure_autotools(self): |
24 |
| - if self._autotools: |
25 |
| - return self._autotools |
26 |
| - self._autotools = AutoToolsBuildEnvironment(self) |
27 |
| - pkgversion = 'conan GCC %s' % self.version |
28 |
| - bugurl = self.url + '/issues' |
29 |
| - libdir = "%s/lib/gcc/%s" % (self.package_folder, self.version) |
30 |
| - args = [ |
31 |
| - "--enable-languages=c,c++", |
32 |
| - "--disable-nls", |
33 |
| - "--disable-multilib", |
34 |
| - "--disable-bootstrap", |
35 |
| - "--with-system-zlib", |
36 |
| - "--with-gmp=%s" % self.deps_cpp_info['gmp'].rootpath, |
37 |
| - '--with-mpc=%s' % self.deps_cpp_info["mpc"].rootpath, |
38 |
| - "--with-mpfr=%s" % self.deps_cpp_info["mpfr"].rootpath, |
39 |
| - "--without-isl", |
40 |
| - "--libdir=%s" % libdir, |
41 |
| - '--with-pkgversion=%s' % pkgversion, |
42 |
| - "--program-suffix=-%s" % self.version, |
43 |
| - "--with-bugurl=%s" % bugurl |
44 |
| - ] |
45 |
| - if self.settings.os == "Macos": |
46 |
| - xcrun = tools.XCRun(self.settings) |
47 |
| - args.extend([ |
48 |
| - '--with-native-system-header-dir=/usr/include', |
49 |
| - "--with-sysroot={}".format(xcrun.sdk_path) |
50 |
| - ]) |
51 |
| - self._autotools.libs = [] # otherwise causes config.log to fail finding -lmpc |
| 27 | + def configure(self): |
52 | 28 | if self.settings.compiler in ["clang", "apple-clang"]:
|
53 |
| - # xgcc: error: unrecognized command-line option -stdlib=libc++ |
54 |
| - if self.settings.compiler.libcxx == "libc++": |
55 |
| - self._autotools.cxx_flags.remove("-stdlib=libc++") |
56 |
| - elif self.settings.compiler.libcxx in ["libstdc++", "libstdc++11"]: |
57 |
| - self._autotools.cxx_flags.remove("-stdlib=libstdc++") |
58 |
| - self._autotools.configure(args=args, configure_dir=self._source_subfolder) |
59 |
| - return self._autotools |
60 |
| - |
61 |
| - @property |
62 |
| - def _source_subfolder(self): |
63 |
| - return "source_subfolder" |
| 29 | + # Can't remove this from cxxflags with autotools - so get rid of it |
| 30 | + del self.settings.compiler.libcxx |
| 31 | + |
| 32 | + def build_requirements(self): |
| 33 | + self.tool_requires("binutils/2.38") |
| 34 | + self.tool_requires("flex/2.6.4") |
64 | 35 |
|
65 | 36 | def requirements(self):
|
66 | 37 | self.requires("mpc/1.2.0")
|
67 | 38 | self.requires("mpfr/4.1.0")
|
68 |
| - self.requires("gmp/6.2.0") |
69 |
| - self.requires("zlib/1.2.11") |
| 39 | + self.requires("gmp/6.2.1") |
| 40 | + self.requires("zlib/1.2.12") |
| 41 | + self.requires("isl/0.24") |
70 | 42 |
|
71 |
| - def configure(self): |
72 |
| - if self.settings.os == "Windows": |
73 |
| - raise ConanInvalidConfiguration("Windows builds aren't supported (yet), sorry") |
74 |
| - if tools.cross_building(self.settings): |
| 43 | + def package_id(self): |
| 44 | + del self.info.settings.compiler |
| 45 | + |
| 46 | + def validate(self): |
| 47 | + if self.info.settings.os == "Windows": |
| 48 | + raise ConanInvalidConfiguration( |
| 49 | + "Windows builds aren't supported (yet), sorry" |
| 50 | + ) |
| 51 | + if cross_building(self): |
75 | 52 | raise ConanInvalidConfiguration("no cross-building support (yet), sorry")
|
76 | 53 |
|
77 |
| - def source(self): |
78 |
| - tools.get(**self.conan_data["sources"][self.version]) |
79 |
| - extracted_dir = "gcc-%s" % self.version |
80 |
| - os.rename(extracted_dir, self._source_subfolder) |
| 54 | + def layout(self): |
| 55 | + basic_layout(self, src_folder="source") |
| 56 | + |
| 57 | + def generate(self): |
| 58 | + # Ensure binutils and flex are on the path |
| 59 | + buildenv = VirtualBuildEnv(self) |
| 60 | + buildenv.generate() |
| 61 | + |
| 62 | + tc = AutotoolsToolchain(self) |
| 63 | + tc.configure_args.append("--enable-languages=c,c++,fortran") |
| 64 | + tc.configure_args.append("--disable-nls") |
| 65 | + tc.configure_args.append("--disable-multilib") |
| 66 | + tc.configure_args.append("--disable-bootstrap") |
| 67 | + tc.configure_args.append("--with-system-zlib") |
| 68 | + tc.configure_args.append(f"--prefix={self.package_folder}") |
| 69 | + tc.configure_args.append(f"--with-isl={self.deps_cpp_info['isl'].rootpath}") |
| 70 | + tc.configure_args.append(f"--with-gmp={self.deps_cpp_info['gmp'].rootpath}") |
| 71 | + tc.configure_args.append(f"--with-mpc={self.deps_cpp_info['mpc'].rootpath}") |
| 72 | + tc.configure_args.append(f"--with-mpfr={self.deps_cpp_info['mpfr'].rootpath}") |
| 73 | + tc.configure_args.append(f"--with-pkgversion=conan GCC {self.version}") |
| 74 | + tc.configure_args.append(f"--program-suffix=-{self.version}") |
| 75 | + tc.configure_args.append(f"--with-bugurl={self.url}/issues") |
| 76 | + |
| 77 | + if self.info.settings.os == "Macos": |
| 78 | + xcrun = XCRun(self.settings) |
| 79 | + tc.configure_args.append("--with-native-system-header-dir=/usr/include") |
| 80 | + tc.configure_args.append(f"--with-sysroot={xcrun.sdk_path}") |
| 81 | + tc.make_args.append("BOOT_LDFLAGS=-Wl") |
| 82 | + tc.make_args.append("-headerpad_max_install_names") |
| 83 | + tc.generate() |
| 84 | + |
| 85 | + deps = AutotoolsDeps(self) |
| 86 | + deps.generate() |
81 | 87 |
|
82 |
| - @property |
83 |
| - def _make_args(self): |
84 |
| - if self.settings.os == "Macos": |
85 |
| - return ["BOOT_LDFLAGS=-Wl,-headerpad_max_install_names"] |
86 |
| - return [] |
| 88 | + def source(self): |
| 89 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
87 | 90 |
|
88 | 91 | def build(self):
|
89 | 92 | # If building on x86_64, change the default directory name for 64-bit libraries to "lib":
|
90 |
| - libdir = "%s/lib/gcc/%s" % (self.package_folder, self.version) |
91 |
| - tools.replace_in_file(os.path.join(self.source_folder, |
92 |
| - self._source_subfolder, "gcc", "config", "i386", "t-linux64"), |
93 |
| - "m64=../lib64", "m64=../lib", strict=False) |
| 93 | + replace_in_file( |
| 94 | + self, |
| 95 | + os.path.join(self.source_folder, "gcc", "config", "i386", "t-linux64"), |
| 96 | + "m64=../lib64", |
| 97 | + "m64=../lib", |
| 98 | + strict=False, |
| 99 | + ) |
| 100 | + |
94 | 101 | # Ensure correct install names when linking against libgcc_s;
|
95 | 102 | # see discussion in https://github.com/Homebrew/legacy-homebrew/pull/34303
|
96 |
| - tools.replace_in_file(os.path.join(self.source_folder, |
97 |
| - self._source_subfolder, "libgcc", "config", "t-slibgcc-darwin"), |
98 |
| - "@shlib_slibdir@", libdir, strict=False) |
99 |
| - autotools = self._configure_autotools() |
100 |
| - autotools.make(args=self._make_args) |
101 |
| - |
102 |
| - def package_id(self): |
103 |
| - del self.info.settings.compiler |
| 103 | + replace_in_file( |
| 104 | + self, |
| 105 | + os.path.join(self.source_folder, "libgcc", "config", "t-slibgcc-darwin"), |
| 106 | + "@shlib_slibdir@", |
| 107 | + os.path.join(self.package_folder, "lib"), |
| 108 | + strict=False, |
| 109 | + ) |
| 110 | + |
| 111 | + autotools = Autotools(self) |
| 112 | + autotools.configure() |
| 113 | + autotools.make() |
104 | 114 |
|
105 | 115 | def package(self):
|
106 |
| - autotools = self._configure_autotools() |
107 |
| - if self.settings.build_type == "Debug": |
108 |
| - autotools.install(args=self._make_args) |
109 |
| - else: |
110 |
| - autotools.make(args=["install-strip"] + self._make_args) |
111 |
| - tools.rmdir(os.path.join(self.package_folder, "share")) |
112 |
| - tools.remove_files_by_mask(self.package_folder, "*.la") |
113 |
| - self.copy(pattern="COPYING*", dst="licenses", src=self._source_subfolder) |
| 116 | + autotools = Autotools(self) |
| 117 | + autotools.make(target="install-strip") |
| 118 | + |
| 119 | + rmdir(self, os.path.join(self.package_folder, "share")) |
| 120 | + rm(self, "*.la", self.package_folder, recursive=True) |
| 121 | + copy( |
| 122 | + self, |
| 123 | + pattern="COPYING*", |
| 124 | + dst=os.path.join(self.package_folder, "licenses"), |
| 125 | + src=self.source_folder, |
| 126 | + keep_path=False, |
| 127 | + ) |
114 | 128 |
|
115 | 129 | def package_info(self):
|
| 130 | + if self.info.settings.os in ["Linux", "FreeBSD"]: |
| 131 | + self.cpp_info.system_libs.append("m") |
| 132 | + self.cpp_info.system_libs.append("rt") |
| 133 | + self.cpp_info.system_libs.append("pthread") |
| 134 | + self.cpp_info.system_libs.append("dl") |
| 135 | + |
116 | 136 | bindir = os.path.join(self.package_folder, "bin")
|
117 |
| - self.output.info("Appending PATH env var with : " + bindir) |
118 |
| - self.env_info.PATH.append(bindir) |
| 137 | + self.output.info("Prepending PATH env var with: " + bindir) |
| 138 | + self.buildenv_info.prepend_path("PATH", bindir) |
| 139 | + |
| 140 | + cc = os.path.join(bindir, f"gcc-{self.version}") |
| 141 | + self.output.info("Creating CC env var with: " + cc) |
| 142 | + self.buildenv_info.define("CC", cc) |
| 143 | + |
| 144 | + cxx = os.path.join(bindir, f"g++-{self.version}") |
| 145 | + self.output.info("Creating CXX env var with: " + cxx) |
| 146 | + self.buildenv_info.define("CXX", cxx) |
| 147 | + |
| 148 | + fc = os.path.join(bindir, f"gfortran-{self.version}") |
| 149 | + self.output.info("Creating FC env var with: " + fc) |
| 150 | + self.buildenv_info.define("FC", fc) |
| 151 | + |
| 152 | + ar = os.path.join(bindir, f"gcc-ar-{self.version}") |
| 153 | + self.output.info("Creating AR env var with: " + ar) |
| 154 | + self.buildenv_info.define("AR", ar) |
119 | 155 |
|
120 |
| - cc = os.path.join(bindir, "gcc-%s" % self.version) |
121 |
| - self.output.info("Creating CC env var with : " + cc) |
122 |
| - self.env_info.CC = cc |
| 156 | + nm = os.path.join(bindir, f"gcc-nm-{self.version}") |
| 157 | + self.output.info("Creating NM env var with: " + nm) |
| 158 | + self.buildenv_info.define("NM", nm) |
123 | 159 |
|
124 |
| - cxx = os.path.join(bindir, "g++-%s" % self.version) |
125 |
| - self.output.info("Creating CXX env var with : " + cxx) |
126 |
| - self.env_info.CXX = cxx |
| 160 | + ranlib = os.path.join(bindir, f"gcc-ranlib-{self.version}") |
| 161 | + self.output.info("Creating RANLIB env var with: " + ranlib) |
| 162 | + self.buildenv_info.define("RANLIB", ranlib) |
0 commit comments