mirror of
https://github.com/nillerusr/source-engine.git
synced 2025-04-20 01:47:19 +00:00
Package with Nix, add build-flags wscript parameter
This commit is contained in:
parent
29985681a1
commit
bd140bb156
19
build.nix
Normal file
19
build.nix
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{ callPackage
|
||||||
|
, symlinkJoin
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
# Strangely, these are overridable
|
||||||
|
hl2-unwrapped = callPackage ./hl2-unwrapped.nix { };
|
||||||
|
hl2-wrapper = callPackage ./hl2-wrapper.nix { inherit hl2-unwrapped; };
|
||||||
|
in
|
||||||
|
symlinkJoin {
|
||||||
|
name = "hl2";
|
||||||
|
|
||||||
|
paths = [
|
||||||
|
hl2-unwrapped
|
||||||
|
hl2-wrapper
|
||||||
|
];
|
||||||
|
|
||||||
|
postBuild = "ln -s $out/bin/hl2-wrapper $out/bin/hl2";
|
||||||
|
}
|
26
flake.lock
generated
Normal file
26
flake.lock
generated
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1734566935,
|
||||||
|
"narHash": "sha256-cnBItmSwoH132tH3D4jxmMLVmk8G5VJ6q/SC3kszv9E=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "087408a407440892c1b00d80360fd64639b8091d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
16
flake.nix
Normal file
16
flake.nix
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs }:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages.x86_64-linux = {
|
||||||
|
hl2 = pkgs.callPackage ./build.nix { };
|
||||||
|
default = self.packages.x86_64-linux.hl2;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
48
hl2-unwrapped.nix
Normal file
48
hl2-unwrapped.nix
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{ stdenv
|
||||||
|
, python3
|
||||||
|
, wafHook
|
||||||
|
, callPackage
|
||||||
|
, SDL2
|
||||||
|
, freetype
|
||||||
|
, fontconfig
|
||||||
|
, zlib
|
||||||
|
, bzip2
|
||||||
|
, libjpeg
|
||||||
|
, libpng
|
||||||
|
, curl
|
||||||
|
, openal
|
||||||
|
, libopus
|
||||||
|
, pkg-config
|
||||||
|
, gcc
|
||||||
|
, extraWafConfigureFlags ? [ ]
|
||||||
|
}:
|
||||||
|
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
pname = "hl2";
|
||||||
|
version = "1.0";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
python3
|
||||||
|
SDL2
|
||||||
|
freetype
|
||||||
|
fontconfig
|
||||||
|
zlib
|
||||||
|
bzip2
|
||||||
|
libjpeg
|
||||||
|
libpng
|
||||||
|
curl
|
||||||
|
openal
|
||||||
|
libopus
|
||||||
|
pkg-config
|
||||||
|
gcc
|
||||||
|
wafHook
|
||||||
|
];
|
||||||
|
|
||||||
|
wafConfigureFlags = [
|
||||||
|
"-T fastnative"
|
||||||
|
"--disable-warns"
|
||||||
|
"--build-flags=-Wno-error=format-security,-O3"
|
||||||
|
] ++ extraWafConfigureFlags;
|
||||||
|
}
|
105
hl2-wrapper.nix
Normal file
105
hl2-wrapper.nix
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
{ writeShellScriptBin
|
||||||
|
, getopt
|
||||||
|
, xorg
|
||||||
|
, hl2-unwrapped
|
||||||
|
}:
|
||||||
|
|
||||||
|
writeShellScriptBin "hl2-wrapper" ''
|
||||||
|
config_path=$HOME/.config/hl2/config
|
||||||
|
default_resource_path=$HOME/hl2
|
||||||
|
|
||||||
|
longoptions="resource-path:,impermanent,help"
|
||||||
|
shortoptions="r:h"
|
||||||
|
|
||||||
|
impermanent=false
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "hl2(-wrapper) usage:"
|
||||||
|
echo "Define resource_path variable in $config_path, with the argument shown below or put resource files in $default_resource_path."
|
||||||
|
grep ' \+-.*) ' $0 | sed 's/#//' | sed -r 's/([a-z])\)/\1/'
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Just in case
|
||||||
|
save_newly_created_files() {
|
||||||
|
newly_created_files=$(cd $tmp_dir && find . -type f | cut -c 2-)
|
||||||
|
|
||||||
|
echo "$newly_created_files" | while read file;
|
||||||
|
do
|
||||||
|
cp $tmp_dir$file $resource_path$file
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
if ! $impermanent; then
|
||||||
|
save_newly_created_files
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf $tmp_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -e $config_path ]]
|
||||||
|
then
|
||||||
|
source $config_path
|
||||||
|
fi
|
||||||
|
|
||||||
|
parsed=$(${getopt}/bin/getopt -l $longoptions -o $shortoptions -a -- "$@")
|
||||||
|
|
||||||
|
eval set -- "$parsed"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-r | --resource-path) # Defines resources folder path
|
||||||
|
resource_path="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--impermanent) # Don't save newly created files that are not in symlimked folders (you probably don't want to use this)
|
||||||
|
impermanent=true
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-h | --help) # Get help
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Wrong argument: $1"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ! $resource_path ]]
|
||||||
|
then
|
||||||
|
echo "The path to Half-Life 2 resource folder is not set either in a config file or with an argument. Looking for resource files in the standard directory (~/hl2)."
|
||||||
|
resource_path=$default_resource_path
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -d $resource_path ]]
|
||||||
|
then
|
||||||
|
echo "$resource_path doesn't exist. Set a proper resource path."
|
||||||
|
exit 1
|
||||||
|
elif [[ ! -d $resource_path/hl2 || ! -d $resource_path/platform ]]
|
||||||
|
then
|
||||||
|
echo "$resource_path doesn't contain 'hl2' and/or 'platform' folder. Set a proper resource path."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tmp_dir=$(mktemp -d)
|
||||||
|
echo $tmp_dir
|
||||||
|
|
||||||
|
mkdir $tmp_dir/{hl2,platform}
|
||||||
|
ln -s $resource_path/hl2/* $tmp_dir/hl2/
|
||||||
|
ln -s $resource_path/platform/* $tmp_dir/platform/
|
||||||
|
rm -rf $tmp_dir/hl2/bin
|
||||||
|
|
||||||
|
${xorg.lndir}/bin/lndir "${hl2-unwrapped}" $tmp_dir
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
( cd $tmp_dir ; ./hl2_launcher )
|
||||||
|
''
|
23
shell.nix
Normal file
23
shell.nix
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
pkgs.mkShell rec {
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
makeWrapper
|
||||||
|
SDL2
|
||||||
|
freetype
|
||||||
|
fontconfig
|
||||||
|
zlib
|
||||||
|
bzip2
|
||||||
|
libjpeg
|
||||||
|
libpng
|
||||||
|
curl
|
||||||
|
openal
|
||||||
|
libopus
|
||||||
|
pkg-config
|
||||||
|
gcc
|
||||||
|
];
|
||||||
|
buildInputs = [
|
||||||
|
(pkgs.python3.withPackages (ps: with ps; [
|
||||||
|
ipython
|
||||||
|
]))
|
||||||
|
];
|
||||||
|
}
|
10
wscript
10
wscript
@ -322,6 +322,9 @@ def options(opt):
|
|||||||
grp.add_option('--sanitize', action = 'store', dest = 'SANITIZE', default = '',
|
grp.add_option('--sanitize', action = 'store', dest = 'SANITIZE', default = '',
|
||||||
help = 'build with sanitizers [default: %default]')
|
help = 'build with sanitizers [default: %default]')
|
||||||
|
|
||||||
|
grp.add_option('--build-flags', action = 'store', dest = 'BUILD_FLAGS', type = 'string',
|
||||||
|
help = 'specify build flags (both cflags and cxxflags) separated by a comma. Note that this does NOT override flags produced automatically by waf!')
|
||||||
|
|
||||||
opt.load('compiler_optimizations subproject')
|
opt.load('compiler_optimizations subproject')
|
||||||
|
|
||||||
opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install_v2 waf_unit_test subproject')
|
opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install_v2 waf_unit_test subproject')
|
||||||
@ -598,6 +601,13 @@ def configure(conf):
|
|||||||
cxxflags += conf.filter_cxxflags(compiler_optional_flags, cflags)
|
cxxflags += conf.filter_cxxflags(compiler_optional_flags, cflags)
|
||||||
cflags += conf.filter_cflags(compiler_optional_flags + c_compiler_optional_flags, cflags)
|
cflags += conf.filter_cflags(compiler_optional_flags + c_compiler_optional_flags, cflags)
|
||||||
|
|
||||||
|
preferred_flags = conf.options.BUILD_FLAGS
|
||||||
|
if preferred_flags:
|
||||||
|
preferred_flags = preferred_flags.split(',')
|
||||||
|
cflags += preferred_flags
|
||||||
|
cxxflags += preferred_flags
|
||||||
|
linkflags += preferred_flags
|
||||||
|
|
||||||
conf.env.append_unique('CFLAGS', cflags)
|
conf.env.append_unique('CFLAGS', cflags)
|
||||||
conf.env.append_unique('CXXFLAGS', cxxflags)
|
conf.env.append_unique('CXXFLAGS', cxxflags)
|
||||||
conf.env.append_unique('LINKFLAGS', linkflags)
|
conf.env.append_unique('LINKFLAGS', linkflags)
|
||||||
|
Loading…
Reference in New Issue
Block a user