build: support multi os/arch conf for netsurf

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-10-29 20:06:29 +01:00
parent be5d7022cc
commit b9e2be2052
2 changed files with 21 additions and 11 deletions

View File

@@ -100,10 +100,10 @@ test:
.PHONY: install-dev install .PHONY: install-dev install
## Install and build dependencies for release ## Install and build dependencies for release
install: install-submodule install-zig-js-runtime install-netsurf install-mimalloc install: install-submodule install-zig-js-runtime install-libiconv install-netsurf install-mimalloc
## Install and build dependencies for dev ## Install and build dependencies for dev
install-dev: install-submodule install-zig-js-runtime-dev install-netsurf-dev install-mimalloc-dev install-dev: install-submodule install-zig-js-runtime-dev install-libiconv install-netsurf-dev install-mimalloc-dev
install-netsurf-dev: _install-netsurf install-netsurf-dev: _install-netsurf
install-netsurf-dev: OPTCFLAGS := -O0 -g -DNDEBUG install-netsurf-dev: OPTCFLAGS := -O0 -g -DNDEBUG
@@ -111,14 +111,16 @@ install-netsurf-dev: OPTCFLAGS := -O0 -g -DNDEBUG
install-netsurf: _install-netsurf install-netsurf: _install-netsurf
install-netsurf: OPTCFLAGS := -DNDEBUG install-netsurf: OPTCFLAGS := -DNDEBUG
BC_NS := $(BC)vendor/netsurf BC_NS := $(BC)vendor/netsurf/out/$(OS)-$(ARCH)
ICONV := $(BC)vendor/libiconv/out/$(OS)-$(ARCH) ICONV := $(BC)vendor/libiconv/out/$(OS)-$(ARCH)
# TODO: add Linux iconv path (I guess it depends on the distro) # TODO: add Linux iconv path (I guess it depends on the distro)
# TODO: this way of linking libiconv is not ideal. We should have a more generic way # TODO: this way of linking libiconv is not ideal. We should have a more generic way
# and stick to a specif version. Maybe build from source. Anyway not now. # and stick to a specif version. Maybe build from source. Anyway not now.
_install-netsurf: install-libiconv _install-netsurf: clean-netsurf
@printf "\e[36mInstalling NetSurf...\e[0m\n" && \ @printf "\e[36mInstalling NetSurf...\e[0m\n" && \
ls $(ICONV) 1> /dev/null || (printf "\e[33mERROR: you need to install libiconv in your system (on MacOS on with Homebrew)\e[0m\n"; exit 1;) && \ ls $(ICONV)/lib/libiconv.a 1> /dev/null || (printf "\e[33mERROR: you need to execute 'make install-libiconv'\e[0m\n"; exit 1;) && \
mkdir -p $(BC_NS) && \
cp -R vendor/netsurf/share $(BC_NS) && \
export PREFIX=$(BC_NS) && \ export PREFIX=$(BC_NS) && \
export OPTLDFLAGS="-L$(ICONV)/lib" && \ export OPTLDFLAGS="-L$(ICONV)/lib" && \
export OPTCFLAGS="$(OPTCFLAGS) -I$(ICONV)/include" && \ export OPTCFLAGS="$(OPTCFLAGS) -I$(ICONV)/include" && \
@@ -156,10 +158,7 @@ _install-netsurf: install-libiconv
clean-netsurf: clean-netsurf:
@printf "\e[36mCleaning NetSurf build...\e[0m\n" && \ @printf "\e[36mCleaning NetSurf build...\e[0m\n" && \
cd vendor/netsurf && \ rm -Rf $(BC_NS)
rm -R build && \
rm -R lib && \
rm -R include
test-netsurf: test-netsurf:
@printf "\e[36mTesting NetSurf...\e[0m\n" && \ @printf "\e[36mTesting NetSurf...\e[0m\n" && \
@@ -195,6 +194,7 @@ install-zig-js-runtime:
make install make install
.PHONY: _build_mimalloc .PHONY: _build_mimalloc
MIMALLOC := $(BC)vendor/mimalloc/out/$(OS)-$(ARCH) MIMALLOC := $(BC)vendor/mimalloc/out/$(OS)-$(ARCH)
_build_mimalloc: clean-mimalloc _build_mimalloc: clean-mimalloc
@mkdir -p $(MIMALLOC)/build && \ @mkdir -p $(MIMALLOC)/build && \

View File

@@ -193,7 +193,12 @@ fn moduleNetSurf(b: *std.Build, target: std.Build.ResolvedTarget) !*std.Build.Mo
// netsurf libs // netsurf libs
const ns = "vendor/netsurf"; const ns = "vendor/netsurf";
mod.addIncludePath(b.path(ns ++ "/include")); const ns_include_path = try std.fmt.allocPrint(
mod.owner.allocator,
ns ++ "/out/{s}-{s}/include",
.{ @tagName(os), @tagName(arch) },
);
mod.addIncludePath(b.path(ns_include_path));
const libs: [4][]const u8 = .{ const libs: [4][]const u8 = .{
"libdom", "libdom",
@@ -202,7 +207,12 @@ fn moduleNetSurf(b: *std.Build, target: std.Build.ResolvedTarget) !*std.Build.Mo
"libwapcaplet", "libwapcaplet",
}; };
inline for (libs) |lib| { inline for (libs) |lib| {
mod.addObjectFile(b.path(ns ++ "/lib/" ++ lib ++ ".a")); const ns_lib_path = try std.fmt.allocPrint(
mod.owner.allocator,
ns ++ "/out/{s}-{s}/lib/" ++ lib ++ ".a",
.{ @tagName(os), @tagName(arch) },
);
mod.addObjectFile(b.path(ns_lib_path));
mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src")); mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src"));
} }