diff options
| author | jamie <git@skilet.ro> | 2026-06-28 09:29:00 +0100 |
|---|---|---|
| committer | jamie <git@skilet.ro> | 2026-06-28 09:30:42 +0100 |
| commit | ad08b1b75becd28bd8be46a74058b2e497e3c3eb (patch) | |
| tree | 604ec2787acb9c627672856c18508af6e1e32629 | |
| parent | af58df0c100820c6821cb2ac067401f35cf4199e (diff) | |
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | flake.lock | 27 | ||||
| -rw-r--r-- | flake.nix | 144 |
3 files changed, 173 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e370078 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result/ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a94690d --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1782467914, + "narHash": "sha256-pGvFkM8N0xEkIIXDe5YYfbEAvHrk4IxBrjB/x8OomhE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e73de5be04e0eff4190a1432b946d469c794e7b4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7fda055 --- /dev/null +++ b/flake.nix @@ -0,0 +1,144 @@ +{ + description = "Benzin - Wii BRlyt/BRlan/TPL file tools"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + forAllSystems = nixpkgs.lib.genAttrs systems; + + mkPkg = + { + pkgs, + pname, + version, + srcDir, + buildInputs, + makefile, + description, + extraPatchPhase ? "", + }: + pkgs.stdenv.mkDerivation { + inherit + pname + version + buildInputs + description + ; + + src = if srcDir == "." then self else "${self}/${srcDir}"; + + patchPhase = '' + substituteInPlace ${makefile} --replace-fail 'gcc' '$(CC)' + ${extraPatchPhase} + ''; + + installPhase = '' + mkdir -p $out/bin + cp ${pname} $out/bin/ + ''; + + meta = { + inherit description; + homepage = "https://github.com/trap15/benzin"; + platforms = pkgs.lib.platforms.linux; + maintainers = [ ]; + }; + }; + in + { + packages = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + benzin = mkPkg { + inherit pkgs; + pname = "benzin"; + version = "2.1.11-beta"; + srcDir = "."; + buildInputs = [ pkgs.minixml ]; + makefile = "Makefile"; + description = "Tool for parsing and creating BRlyt/BRlan files (Wii UI format)"; + + extraPatchPhase = '' + # xml.c uses mxml 2.x struct internals; rewrite to use accessor functions. + # Remove the redundant assignment on line 35, then fix the for loop. + sed -i '/^[[:space:]]*current = node->child;$/{ + /for/d + d + }' xml.c + + substituteInPlace xml.c \ + --replace-fail 'for (current = node->child; current && ptr < end; current = current->next)' \ + 'for (current = mxmlGetFirstChild(node); current && ptr < end; current = mxmlGetNextSibling(current))' \ + --replace-fail 'current->type == MXML_TEXT' 'mxmlGetType(current) == MXML_TEXT' \ + --replace-fail 'current->type == MXML_OPAQUE' 'mxmlGetType(current) == MXML_OPAQUE' \ + --replace-fail 'current->type == MXML_INTEGER' 'mxmlGetType(current) == MXML_INTEGER' \ + --replace-fail 'current->type == MXML_REAL' 'mxmlGetType(current) == MXML_REAL' \ + --replace-fail 'current->value.opaque' 'mxmlGetOpaque(current)' \ + --replace-fail 'current->value.integer' 'mxmlGetInteger(current)' \ + --replace-fail 'current->value.real' 'mxmlGetReal(current)' \ + --replace-fail 'node->value.element.name' 'mxmlGetElement(node)' \ + --replace-fail 'temp = temp->parent' 'temp = mxmlGetParent(temp)' \ + --replace-fail 'node->prev' 'mxmlGetPrevSibling(node)' \ + --replace-fail 'node->parent' 'mxmlGetParent(node)' + + # Handle text node: insert local vars before the whitespace check + substituteInPlace xml.c \ + --replace-fail 'if (current->value.text.whitespace)' \ + 'int _mxml_ws; const char *_mxml_str = mxmlGetText(current, &_mxml_ws); if (_mxml_ws)' + + substituteInPlace xml.c \ + --replace-fail 'current->value.text.string' '_mxml_str' + ''; + }; + + zetsubou = mkPkg { + inherit pkgs; + pname = "zetsubou"; + version = "0.1"; + srcDir = "zetsubou"; + buildInputs = [ pkgs.gd ]; + makefile = "Makefile"; + description = "TPL (Texture Palette List) converter — TPL to/from BMP/PNG"; + }; + + gentpl = mkPkg { + inherit pkgs; + pname = "gentpl"; + version = "0.1"; + srcDir = "gentpl"; + buildInputs = [ pkgs.gd ]; + makefile = "Makefile"; + description = "Simple PNG to TPL converter"; + }; + + default = self.packages.${system}.benzin; + } + ); + + devShells = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + default = pkgs.mkShell { + buildInputs = with pkgs; [ + minixml + gd + ]; + }; + } + ); + }; +} |
