Skip to content

Commit

Permalink
(#6677) imake: add imake/1.0.8 recipe
Browse files Browse the repository at this point in the history
* imake: add imake/1.0.8 recipe

* imake: fix MSVC build

* imake: don't add build_requires test type to test package

* imake: simplify test_package's _settings_build

* imake: fix MSVC debug build

* imake: more MSVC fixes for debug build type with MTd runtime
  • Loading branch information
madebr authored Aug 6, 2021
1 parent 2e53a79 commit d8c8cf6
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 0 deletions.
10 changes: 10 additions & 0 deletions recipes/imake/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"1.0.8":
url: "https://www.x.org/releases/individual/util/imake-1.0.8.tar.gz"
sha256: "8178a09bfef33ad5f61cb5cb62283df7d3a5682f014507d2e7cfd922485a5c00"
patches:
"1.0.8":
- patch_file: "patches/0001-reproducible-behavior.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-msvc-debug-build_type.patch"
base_path: "source_subfolder"
141 changes: 141 additions & 0 deletions recipes/imake/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
from conans import ConanFile, tools, AutoToolsBuildEnvironment
import contextlib
import os

required_conan_version = ">=1.33.0"


class ImakeConan(ConanFile):
name = "imake"
description = "Obsolete C preprocessor interface to the make utility"
topics = ("conan", "imake", "xmkmf", "preprocessor", "build", "system")
license = "MIT"
homepage = "https://gitlab.freedesktop.org/xorg/util/imake"
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "arch", "compiler", "build_type"
options = {
"ccmakedep": [True, False],
"cleanlinks": [True, False],
"makeg": [True, False],
"mergelib": [True, False],
"mkdirhier": [True, False],
"mkhtmlindex": [True, False],
"revpath": [True, False],
"xmkmf": [True, False],
}
default_options = {
"ccmakedep": True,
"cleanlinks": True,
"makeg": True,
"mergelib": True,
"mkdirhier": True,
"mkhtmlindex": True,
"revpath": True,
"xmkmf": True,
}

exports_sources = "patches/*"
generators = "pkg_config"

_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def requirements(self):
self.requires("xorg-proto/2021.4")

def build_requirements(self):
self.build_requires("automake/1.16.3")
self.build_requires("pkgconf/1.7.4")
if self._settings_build.os == "Windows":
self.build_requires("msys2/cci.latest")

def configure(self):
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx

def package_id(self):
del self.info.settings.compiler

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)

@contextlib.contextmanager
def _build_context(self):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self):
env = {
"CC": "{} cl -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"CXX": "{} cl -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"CPP": "{} cl -E".format(tools.unix_path(self._user_info_build["automake"].compile)),
}
with tools.environment_append(env):
yield
else:
yield

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=self._settings_build.os == "Windows")
self._autotools.libs = []
if self.settings.os == "Windows":
self._autotools.defines.append("WIN32")
if self.settings.compiler == "Visual Studio":
self._autotools.defines.extend([
"_CRT_SECURE_NO_WARNINGS",
"CROSSCOMPILE_CPP",
])
self._autotools.flags.append("-FS")
yes_no = lambda v: "yes" if v else "no"
conf_args = [
"--enable-ccmakedep={}".format(yes_no(self.options.ccmakedep)),
"--enable-cleanlinks={}".format(yes_no(self.options.cleanlinks)),
"--enable-makeg={}".format(yes_no(self.options.makeg)),
"--enable-mergelib={}".format(yes_no(self.options.mergelib)),
"--enable-mkdirhier={}".format(yes_no(self.options.mkdirhier)),
"--enable-mkhtmlindex={}".format(yes_no(self.options.mkhtmlindex)),
"--enable-revpath={}".format(yes_no(self.options.revpath)),
"--enable-xmkmf={}".format(yes_no(self.options.xmkmf)),
]

# FIXME: RAWCPP (ac_cv_path_RAWCPP) is not compatible with MSVC preprocessor. It needs to be cpp.
if tools.get_env("CPP"):
conf_args.extend([
"--with-script-preproc-cmd={}".format(tools.get_env("CPP")),
])
self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
return self._autotools

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
# tools.replace_in_file(os.path.join(self._source_subfolder, ""))
with self._build_context():
autotools = self._configure_autotools()
autotools.make(args=["V=1"])

def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
with self._build_context():
autotools = self._configure_autotools()
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libdirs = []

bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
14 changes: 14 additions & 0 deletions recipes/imake/all/patches/0001-reproducible-behavior.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Hardcode gcc instead of using `PREPROC` (=compiler used when building imake).
This leads to more reproducible behavior.
(CC can be overridden by a CC environment variable or --cc argument)
--- mdepend.cpp
+++ mdepend.cpp
@@ -21,7 +21,7 @@
XCOMM "-" (at least, that is what the documentation implies).
XCOMM

-CC=PREPROC
+CC=gcc

silent='-'

57 changes: 57 additions & 0 deletions recipes/imake/all/patches/0002-msvc-debug-build_type.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Needed when building MSVC with build_type=Debug + compiler.runtime=MTd
- escape comments with XCOMM
- avoid C4717: '_fstat64i32': recursive on all control paths, function will cause runtime stack overflow
- /tmp/xxxx does not exist on Windows
--- mdepend.cpp
+++ mdepend.cpp
@@ -125,9 +125,9 @@
shift
;;

- # Flag to tell compiler to output dependencies directly
- # For example, with Sun compilers, -xM or -xM1 or
- # with gcc, -M
+ XCOMM Flag to tell compiler to output dependencies directly
+ XCOMM For example, with Sun compilers, -xM or -xM1 or
+ XCOMM with gcc, -M
-d)
compilerlistsdepends="y"
compilerlistdependsflag="$2"
--- imake.c
+++ imake.c
@@ -159,9 +159,6 @@
#include <X11/Xosdefs.h>
#include <string.h>
#include <ctype.h>
-#ifdef WIN32
-# include "Xw32defs.h"
-#endif
#include <sys/types.h>
#include <fcntl.h>
#ifdef X_NOT_POSIX
@@ -252,6 +249,9 @@
#if defined(__NetBSD__) /* see code clock in init() below */
# include <sys/utsname.h>
#endif
+#ifdef WIN32
+# include "Xw32defs.h"
+#endif

typedef unsigned char boolean;
#define TRUE 1
@@ -303,9 +303,14 @@
const char *cpp = NULL;

const char *tmpMakefile;
+#ifdef _WIN32
+const char *tmpMakefileTemplate = "Imf.XXXXXX"; /* HACK: create temporary files in current folder */
+const char *tmpImakefileTemplate = "IIf.XXXXXX"; /* HACK: create temporary files in current folder */
+#else
const char *tmpMakefileTemplate = "/tmp/Imf.XXXXXX";
-const char *tmpImakefile;
const char *tmpImakefileTemplate = "/tmp/IIf.XXXXXX";
+#endif
+const char *tmpImakefile;
const char *make_argv[ ARGUMENTS ] = {
#ifdef WIN32
"nmake"
2 changes: 2 additions & 0 deletions recipes/imake/all/test_package/Imake.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default:
@echo "IMAKE_TEMPLATE:" IMAKE_TEMPLATE
1 change: 1 addition & 0 deletions recipes/imake/all/test_package/Imakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Imakefile
44 changes: 44 additions & 0 deletions recipes/imake/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
import contextlib
import os
import shutil

required_conan_version = ">=1.36.0"


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"

exports_sources = "Imakefile", "Imake.tmpl"

def build_requirements(self):
if not tools.get_env("CONAN_MAKE_PROGRAM"):
self.build_requires("make/4.2.1")

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

@contextlib.contextmanager
def _build_context(self):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self):
env = {
"CC": "cl -nologo",
}
with tools.environment_append(env):
yield
else:
yield

def build(self):
for src in self.exports_sources:
shutil.copy(os.path.join(self.source_folder, src), os.path.join(self.build_folder, src))
if not tools.cross_building(self):
with self._build_context():
self.run("imake", run_environment=True)

def test(self):
if not tools.cross_building(self):
autotools = AutoToolsBuildEnvironment(self)
autotools.make()
3 changes: 3 additions & 0 deletions recipes/imake/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.8":
folder: all

0 comments on commit d8c8cf6

Please sign in to comment.