Skip to content

Commit

Permalink
openssl: fix overlong make recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Doekin committed Dec 29, 2024
1 parent 2121619 commit 2cf58d8
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 35 deletions.
169 changes: 160 additions & 9 deletions packages/o/openssl/configure/patch.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,165 @@
function _remove_unused_modules()
function _fix_overlong_make_recipe()
-- In the MSYS environment, the make recipe can be too long to execute.
-- This patch is adapted from OpenSSL 3.
-- For more details, see: https://github.com/openssl/openssl/issues/12116
io.gsub("Configurations/00-base-templates.conf", -- replace default AR

"DEFAULTS%s-=>%s-{" ..
"(.-)"..
[[AR%s-=>%s-"%S-"%s-,]].. -- AR => "ar",
"(.-)}",

"DEFAULTS => {"..
"%1"..
[[AR => "(unused)",]] ..
"%2}")
io.gsub("Configurations/00-base-templates.conf", -- replace default ARFLAGS

"DEFAULTS%s-=>%s-{" ..
"(.-)"..
[[ARFLAGS%s-=>%s-"%S-"%s-,]].. -- ARFLAGS => "r",
"(.-)}",

"DEFAULTS => {"..
"%1"..
[[ARFLAGS => "(unused)",]] ..
"%2}")
io.gsub("Configurations/00-base-templates.conf", -- replace BASE_unix ARFLAGS

"BASE_unix%s-=>%s-{" ..
"(.-)"..
[[ARFLAGS%s-=>%s-"%S-"%s-,]].. -- ARFLAGS => "r",
"(.-)}",

"BASE_unix => {"..
"%1"..
[[ARFLAGS => "qc",]] ..
"%2}")
io.gsub("Configurations/unix-Makefile.tmpl", -- insert fill_lines function

"(sub%s-dependmagic%s-{)" ..
"(.-)"..
"}%s-'';",

"%1"..
"%2"..
"}\n"..
[[
sub fill_lines {
my $item_sep = shift; # string
my $line_length = shift; # number of chars
my @result = ();
my $resultpos = 0;
foreach (@_) {
my $fill_line = $result[$resultpos] // '';
my $newline =
($fill_line eq '' ? '' : $fill_line . $item_sep) . $_;
if (length($newline) > $line_length) {
# If this is a single item and the intended result line
# is empty, we put it there anyway
if ($fill_line eq '') {
$result[$resultpos++] = $newline;
} else {
$result[++$resultpos] = $_;
}
} else {
$result[$resultpos] = $newline;
}
}
return @result;
}
]]..
[['';]])

io.gsub("Configurations/unix-Makefile.tmpl", -- change the way we handle dependencies

"sub%s-libobj2shlib%s-{" ..
"(.-)"..
[[my%s-%$objs.-;]].. -- my $objs = join(" ", @objs);
"(.-)}",

"sub libobj2shlib {"..
"%1"..
[[my $objs =
join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));]] ..
"%2}")
io.gsub("Configurations/unix-Makefile.tmpl", -- change the way we handle dependencies

"sub%s-libobj2shlib%s-{" ..
"(.-)"..
[[my%s-%$deps.-;]].. -- my $deps = join(" ", @objs, @defs, @deps);
"(.-)}",

"sub libobj2shlib {"..
"%1"..
[[my @fulldeps = (@objs, @defs, @deps);
my $fulldeps =
join(" \\\n" . ' ' x (length($full) + 2),
fill_lines(' ', $COLUMNS - length($full) - 2, @fulldeps));]] ..
"%2}")
io.gsub("Configurations/unix-Makefile.tmpl",

"sub%s-libobj2shlib%s-{" ..
"(.-)"..
[[%$target:%s-%$deps]].. -- $target: $deps
"(.-)}",

"sub libobj2shlib {"..
"%1"..
[[$target: $fulldeps]] ..
"%2}")
io.gsub("Configurations/unix-Makefile.tmpl",

"sub%s-obj2lib%s-{" ..
"(.-)"..
[[my%s-%$objs.-;]].. -- my $objs = join(" ", @objs);
"(.-)}",

"sub obj2lib {"..
"%1"..
[[my $deps = join(" \\\n" . ' ' x (length($lib) + 2),
fill_lines(' ', $COLUMNS - length($lib) - 2, @objs));
my $max_per_call = 250;
my @objs_grouped;
push @objs_grouped, join(" ", splice @objs, 0, $max_per_call) while @objs;
my $fill_lib =
join("\n\t", (map { "\$(AR) \$(ARFLAGS) $lib$libext $_" } @objs_grouped));]] ..
"%2}")
io.gsub("Configurations/unix-Makefile.tmpl",

"sub%s-obj2lib%s-{" ..
"(.-)"..
[[%$lib%$libext:.-]].. -- $lib$libext: $objs
"EOF",

"sub obj2lib {"..
"%1"..
"$lib$libext: $deps\n" ..
'\t' .. [[\$(RM) $lib$libext]] ..'\n' ..
'\t' .. [[$fill_lib]] ..'\n' ..
'\t' .. [[\$(RANLIB) \$\@ || echo Never mind.]] .. '\n' ..
"EOF")

end

function _remove_unused_pod_usage()
-- Perl in "Git for Windows" lacks Pod::Usage, which is only used for help messages in the Configure script.
-- It is not needed for the build and can be safely removed to avoid errors from the missing module.
io.replace("Configure", "use Pod::Usage;", "", {plain = true})
io.replace("Configure", "pod2usage.-;", "")
end

function main(package, opt)
if not package:is_plat("windows") and not opt.perl.use_unix_path then
os.tryrm("Configurations/unix*-checker.pm")
end
if package:is_plat("windows") and opt.perl.use_unix_path then
io.replace("Configurations/10-main.conf", "NUL", "null", {plain = true})
end
_remove_unused_modules()
function _replace_NUL_with_null()
-- The Configure script uses "NUL" to redirect output on Windows when checking NASM.
-- Creating a file named "NUL" can cause issues because "NUL" is a reserved name in Windows.
io.replace("Configurations/10-main.conf", "NUL", "null", {plain = true})
end

function main(package)
_remove_unused_pod_usage()
_replace_NUL_with_null()
_fix_overlong_make_recipe()
end
14 changes: 0 additions & 14 deletions packages/o/openssl/makefile/patch.lua

This file was deleted.

16 changes: 4 additions & 12 deletions packages/o/openssl/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ package("openssl")

if on_check then
on_check(function (package)
local perl = assert(package:find_tool("perl", {paths = {"$(env PERL)"}}), "package(openssl): perl not found!")
local working_dir = os.iorunv(perl.program, {"-MFile::Spec::Functions=rel2abs", "-e", "print rel2abs('.')"})
local working_dir = try {function() return os.iorunv("perl", {"-MFile::Spec::Functions=rel2abs", "-e", "print rel2abs('.')"}) end}
assert(working_dir, "package(openssl): perl not found!")
-- Check if Perl is using Unix-style paths
local use_unix_path = working_dir:find("/") == 1
if use_unix_path and package:is_plat("windows") or not use_unix_path and not package:is_plat("windows") then
Expand Down Expand Up @@ -97,10 +97,7 @@ package("openssl")
table.insert(configs, "no-makedepend")
table.insert(configs, "/FS")
end
-- local perl = package:dep("strawberry-perl")
-- assert(perl, "package(openssl): strawberry-perl not found!")
os.vrunv("perl", configs)
-- import("makefile.patch")(package, {perl = perl})

if jom then
jom.build(package)
Expand Down Expand Up @@ -201,18 +198,13 @@ package("openssl")
end
end

import("lib.detect.find_tool")
local perl = assert(find_tool("perl", {paths={"$(env PERL)"}}), "package(openssl): perl not found!")
local working_dir = os.iorunv(perl.program, {"-MFile::Spec::Functions=rel2abs", "-e", "print rel2abs('.')"})
perl.use_unix_path = working_dir:find("/") == 1
import("configure.patch")(package, {perl = perl})
import("configure.patch")(package)
if package:is_cross() or package:is_plat("mingw") then
os.vrunv(perl.program, table.join("./Configure", configs), {envs = buildenvs})
os.vrunv("perl", table.join("./Configure", configs), {envs = buildenvs})
else
os.vrunv("./config", configs, {shell = true, envs = buildenvs})
end

import("makefile.patch")(package, {perl = perl})
import("package.tools.make").build(package)
import("package.tools.make").make(package, {"install_sw"})
if package:config("shared") then
Expand Down

0 comments on commit 2cf58d8

Please sign in to comment.