-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
164 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,163 +1,167 @@ | ||
from conans import AutoToolsBuildEnvironment, ConanFile, MSBuild, tools | ||
from conans.errors import ConanInvalidConfiguration | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, replace_in_file, rmdir | ||
from conan.tools.gnu import Autotools, AutotoolsToolchain | ||
from conan.tools.layout import basic_layout | ||
from conan.tools.microsoft import MSBuild, is_msvc, msvs_toolset | ||
|
||
required_conan_version = ">=1.47.0" | ||
|
||
|
||
class Cc65Conan(ConanFile): | ||
name = "cc65" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://cc65.github.io/" | ||
description = "A freeware C compiler for 6502 based systems" | ||
license = "Zlib" | ||
topics = ("conan", "cc65", "compiler", "cmos", "6502", "8bit") | ||
exports_sources = "patches/**" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://cc65.github.io/" | ||
topics = ("compiler", "cmos", "6502", "8bit") | ||
|
||
package_type = "application" | ||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
_autotools = None | ||
_source_subfolder = "source_subfolder" | ||
def export_sources(self): | ||
export_conandata_patches(self) | ||
|
||
def configure(self): | ||
del self.settings.compiler.libcxx | ||
del self.settings.compiler.cppstd | ||
if self.settings.compiler == "Visual Studio": | ||
self.settings.rm_safe("compiler.libcxx") | ||
self.settings.rm_safe("compiler.cppstd") | ||
if is_msvc(self): | ||
if self.settings.arch not in ("x86", "x86_64"): | ||
raise ConanInvalidConfiguration("Invalid arch") | ||
if self.settings.arch == "x86_64": | ||
self.output.info("This recipe will build x86 instead of x86_64 (the binaries are compatible)") | ||
|
||
def build_requirements(self): | ||
if self.settings.compiler == "Visual Studio" and not tools.which("make"): | ||
self.build_requires("make/4.2.1") | ||
def layout(self): | ||
basic_layout(self, src_folder="src") | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version]) | ||
extracted_dir = self.name + "-" + self.version | ||
os.rename(extracted_dir, self._source_subfolder) | ||
def package_id(self): | ||
if str(self.info.settings.compiler) in ["msvc", "Visual Studio"]: | ||
if self.settings.arch == "x86_64": | ||
self.info.settings.arch = "x86" | ||
del self.info.settings.compiler | ||
|
||
@property | ||
def _datadir(self): | ||
return os.path.join(self.package_folder, "bin", "share", "cc65") | ||
def build_requirements(self): | ||
if is_msvc(self): | ||
self.tool_requires("make/4.3") | ||
|
||
@property | ||
def _samplesdir(self): | ||
return os.path.join(self.package_folder, "samples") | ||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
tc = AutotoolsToolchain(self) | ||
tc.make_args += [ | ||
f"PREFIX=/", | ||
f"datadir=/bin/share/cc65", | ||
f"samplesdir=/samples", | ||
] | ||
if self.settings.os == "Windows": | ||
tc.make_args.append("EXE_SUFFIX=.exe") | ||
tc.generate() | ||
|
||
def _build_msvc(self): | ||
msbuild = MSBuild(self) | ||
msvc_platforms = { | ||
"x86": "Win32", | ||
} | ||
arch = str(self.settings.arch) | ||
if arch != "x86": | ||
self.output.warn("{} detected: building x86 instead".format(self.settings.arch)) | ||
arch = "x86" | ||
|
||
msbuild.build(os.path.join(self._source_subfolder, "src", "cc65.sln"), | ||
build_type="Debug" if self.settings.build_type == "Debug" else "Release", | ||
arch=arch, platforms=msvc_platforms) | ||
autotools = self._configure_autotools() | ||
with tools.chdir(os.path.join(self._source_subfolder, "libsrc")): | ||
msbuild.build(sln=os.path.join(self.source_folder, "src", "cc65.sln")) | ||
with chdir(self, os.path.join(self.source_folder, "libsrc")): | ||
autotools = Autotools(self) | ||
autotools.configure() | ||
autotools.make() | ||
|
||
def _configure_autotools(self): | ||
if self._autotools: | ||
return self._autotools | ||
self._autotools = AutoToolsBuildEnvironment(self) | ||
return self._autotools | ||
|
||
@property | ||
def _make_args(self): | ||
datadir = self._datadir | ||
prefix = self.package_folder | ||
samplesdir = self._samplesdir | ||
if tools.os_info.is_windows: | ||
datadir = tools.unix_path(datadir) | ||
prefix = tools.unix_path(prefix) | ||
samplesdir = tools.unix_path(samplesdir) | ||
args = [ | ||
"PREFIX={}".format(prefix), | ||
"datadir={}".format(datadir), | ||
"samplesdir={}".format(samplesdir), | ||
] | ||
if self.settings.os == "Windows": | ||
args.append("EXE_SUFFIX=.exe") | ||
return args | ||
|
||
def _build_autotools(self): | ||
autotools = self._configure_autotools() | ||
with tools.chdir(os.path.join(self._source_subfolder)): | ||
autotools.make(args=self._make_args) | ||
with chdir(self, self.source_folder): | ||
autotools = Autotools(self) | ||
autotools.make() | ||
|
||
def _patch_sources(self): | ||
for patch in self.conan_data["patches"][self.version]: | ||
tools.patch(**patch) | ||
if self.settings.compiler == "Visual Studio": | ||
with tools.chdir(os.path.join(self._source_subfolder, "src")): | ||
apply_conandata_patches(self) | ||
if is_msvc(self): | ||
with chdir(self, os.path.join(self.source_folder, "src")): | ||
for fn in os.listdir("."): | ||
if not fn.endswith(".vcxproj"): | ||
continue | ||
tools.replace_in_file(fn, "v141", tools.msvs_toolset(self)) | ||
tools.replace_in_file(fn, "<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>", "") | ||
replace_in_file(self, fn, "v141", msvs_toolset(self)) | ||
replace_in_file(self, fn, | ||
("<WindowsTargetPlatformVersion>" | ||
"10.0.16299.0" | ||
"</WindowsTargetPlatformVersion>"), | ||
"") | ||
if self.settings.os == "Windows": | ||
# Add ".exe" suffix to calls from cl65 to other utilities | ||
for fn, var in (("cc65", "CC65"), ("ca65", "CA65"), ("co65", "CO65"), ("ld65", "LD65"), ("grc65", "GRC")): | ||
v = "{},".format(var).ljust(5) | ||
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "cl65", "main.c"), | ||
"CmdInit (&{v} CmdPath, \"{n}\");".format(v=v, n=fn), | ||
"CmdInit (&{v} CmdPath, \"{n}.exe\");".format(v=v, n=fn)) | ||
for fn, var in [ | ||
("cc65", "CC65"), | ||
("ca65", "CA65"), | ||
("co65", "CO65"), | ||
("ld65", "LD65"), | ||
("grc65", "GRC"), | ||
]: | ||
v = f"{var},".ljust(5) | ||
replace_in_file(self, os.path.join(self.source_folder, "src", "cl65", "main.c"), | ||
f'CmdInit (&{v} CmdPath, "{fn}");', | ||
f'CmdInit (&{v} CmdPath, "{fn}.exe");') | ||
|
||
def build(self): | ||
self._patch_sources() | ||
if self.settings.compiler == "Visual Studio": | ||
if is_msvc(self): | ||
self._build_msvc() | ||
else: | ||
self._build_autotools() | ||
|
||
def _package_msvc(self): | ||
self.copy("*.exe", src=os.path.join(self._source_subfolder, "bin"), dst=os.path.join(self.package_folder, "bin"), keep_path=False) | ||
copy(self, "*.exe", | ||
dst=os.path.join(self.package_folder, "bin"), | ||
src=os.path.join(self.source_folder, "bin"), | ||
keep_path=False) | ||
for dir in ("asminc", "cfg", "include", "lib", "target"): | ||
self.copy("*", src=os.path.join(self._source_subfolder, dir), dst=os.path.join(self._datadir, dir)) | ||
copy(self, "*", | ||
dst=os.path.join(self.package_folder, "bin", "share", "cc65", dir), | ||
src=os.path.join(self.source_folder, dir)) | ||
|
||
def _package_autotools(self): | ||
autotools = self._configure_autotools() | ||
with tools.chdir(os.path.join(self.build_folder, self._source_subfolder)): | ||
autotools.install(args=self._make_args) | ||
|
||
tools.rmdir(self._samplesdir) | ||
tools.rmdir(os.path.join(self.package_folder, "share")) | ||
with chdir(self, os.path.join(self.source_folder)): | ||
autotools = Autotools(self) | ||
autotools.install() | ||
rmdir(self, os.path.join(self.package_path, "samples")) | ||
rmdir(self, os.path.join(self.package_folder, "share")) | ||
|
||
def package(self): | ||
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder) | ||
if self.settings.compiler == "Visual Studio": | ||
copy(self, "LICENSE", | ||
dst=os.path.join(self.package_folder, "licenses"), | ||
src=self.source_folder) | ||
if is_msvc(self): | ||
self._package_msvc() | ||
else: | ||
self._package_autotools() | ||
|
||
def package_id(self): | ||
del self.info.settings.compiler | ||
if self.settings.compiler == "Visual Studio": | ||
if self.settings.arch == "x86_64": | ||
self.info.settings.arch = "x86" | ||
|
||
def package_info(self): | ||
bindir = os.path.join(self.package_folder, "bin") | ||
self.output.info("Appending PATH environment variable: %s" % bindir) | ||
self.env_info.PATH.append(bindir) | ||
|
||
self.output.info("Seting CC65_HOME environment variable: %s" % self._datadir) | ||
self.env_info.CC65_HOME = self._datadir | ||
self.cpp_info.frameworkdirs = [] | ||
self.cpp_info.libdirs = [] | ||
self.cpp_info.resdirs = [] | ||
self.cpp_info.includedirs = [] | ||
|
||
bin_ext = ".exe" if self.settings.os == "Windows" else "" | ||
bindir = os.path.join(self.package_folder, "bin") | ||
datadir = os.path.join(self.package_folder, "bin", "share", "cc65") | ||
|
||
self.output.info(f"Setting CC65_HOME environment variable: {datadir}") | ||
self.buildenv_info.define_path("CC65_HOME", datadir) | ||
|
||
cc65_cc = os.path.join(bindir, "cc65" + bin_ext) | ||
self.output.info("Seting CC65 environment variable: {}".format(cc65_cc)) | ||
self.env_info.CC65 = cc65_cc | ||
self.output.info(f"Setting CC65 environment variable: {cc65_cc}") | ||
self.buildenv_info.define_path("CC65", cc65_cc) | ||
|
||
cc65_as = os.path.join(bindir, "ca65" + bin_ext) | ||
self.output.info("Seting AS65 environment variable: {}".format(cc65_as)) | ||
self.env_info.AS65 = cc65_as | ||
self.output.info(f"Setting AS65 environment variable: {cc65_as}") | ||
self.buildenv_info.define_path("AS65", cc65_as) | ||
|
||
cc65_ld = os.path.join(bindir, "cl65" + bin_ext) | ||
self.output.info("Seting LD65 environment variable: {}".format(cc65_ld)) | ||
self.output.info(f"Setting LD65 environment variable: {cc65_ld}") | ||
self.buildenv_info.define_path("LD65", cc65_ld) | ||
|
||
# TODO: Legacy, to be removed on Conan 2.0 | ||
self.output.info(f"Appending PATH environment variable: {bindir}") | ||
self.env_info.PATH.append(bindir) | ||
self.env_info.CC65_HOME = datadir | ||
self.env_info.CC65 = cc65_cc | ||
self.env_info.AS65 = cc65_as | ||
self.env_info.LD65 = cc65_ld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
from conans import ConanFile, tools | ||
import os | ||
import shutil | ||
|
||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.files import copy, mkdir, rm | ||
from conan.tools.layout import basic_layout | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
exports_sources = "hello.c", "text.s" | ||
generators = "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
_targets = ("c64", "apple2") | ||
|
||
def build_requirements(self): | ||
self.tool_requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
basic_layout(self) | ||
|
||
def build(self): | ||
if not tools.cross_building(self.settings): | ||
for src in self.exports_sources: | ||
if can_run(self): | ||
for src in ["hello.c", "text.s"]: | ||
shutil.copy(os.path.join(self.source_folder, src), os.path.join(self.build_folder, src)) | ||
for target in self._targets: | ||
output = "hello_{}".format(target) | ||
tools.mkdir(target) | ||
try: | ||
# Try removing the output file to give confidence it is created by cc65 | ||
os.unlink(output) | ||
except FileNotFoundError: | ||
pass | ||
self.run("{p} -O -t {t} hello.c -o {t}/hello.s".format(p=os.environ["CC65"], t=target)) | ||
self.run("{p} -t {t} {t}/hello.s -o {t}/hello.o".format(p=os.environ["AS65"], t=target)) | ||
self.run("{p} -t {t} text.s -o {t}/text.o".format(p=os.environ["AS65"], t=target)) | ||
self.run("{p} -o {o} -t {t} {t}/hello.o {t}/text.o {t}.lib".format(o=output, p=os.environ["LD65"], t=target)) | ||
output = f"hello_{target}" | ||
mkdir(self, target) | ||
rm(self, output, self.build_folder) | ||
self.run(f"cc65 -O -t {target} hello.c -o {target}/hello.s") | ||
self.run(f"ca65 -t {target} {target}/hello.s -o {target}/hello.o") | ||
self.run(f"ca65 -t {target} text.s -o {target}/text.o") | ||
self.run(f"ld65 -o {output} -t {target} {target}/hello.o {target}/text.o {target}.lib") | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
if can_run(self): | ||
for target in self._targets: | ||
assert os.path.isfile("hello_{}".format(target)) | ||
assert os.path.isfile(f"hello_{target}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from conans import ConanFile, tools | ||
import os | ||
import shutil | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
exports_sources = "hello.c", "text.s" | ||
|
||
_targets = ("c64", "apple2") | ||
|
||
def build(self): | ||
if not tools.cross_building(self.settings): | ||
for src in self.exports_sources: | ||
shutil.copy(os.path.join(self.source_folder, src), os.path.join(self.build_folder, src)) | ||
for target in self._targets: | ||
output = "hello_{}".format(target) | ||
tools.mkdir(target) | ||
try: | ||
# Try removing the output file to give confidence it is created by cc65 | ||
os.unlink(output) | ||
except FileNotFoundError: | ||
pass | ||
self.run("{p} -O -t {t} hello.c -o {t}/hello.s".format(p=os.environ["CC65"], t=target)) | ||
self.run("{p} -t {t} {t}/hello.s -o {t}/hello.o".format(p=os.environ["AS65"], t=target)) | ||
self.run("{p} -t {t} text.s -o {t}/text.o".format(p=os.environ["AS65"], t=target)) | ||
self.run("{p} -o {o} -t {t} {t}/hello.o {t}/text.o {t}.lib".format(o=output, p=os.environ["LD65"], t=target)) | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
for target in self._targets: | ||
assert os.path.isfile("hello_{}".format(target)) |