From a238739003d17bde201f3ce3fd9c44bc65f3f131 Mon Sep 17 00:00:00 2001 From: kiana-S Date: Wed, 27 Apr 2022 22:07:42 -0400 Subject: [PATCH] Add basic template structure --- flake.nix | 91 ++++-------------------------------------- with-asar/Makefile | 17 ++++++++ with-asar/flake.nix | 88 ++++++++++++++++++++++++++++++++++++++++ with-asar/src/main.asm | 0 4 files changed, 112 insertions(+), 84 deletions(-) create mode 100644 with-asar/Makefile create mode 100644 with-asar/flake.nix create mode 100644 with-asar/src/main.asm diff --git a/flake.nix b/flake.nix index bc540e7..a474e39 100644 --- a/flake.nix +++ b/flake.nix @@ -1,87 +1,10 @@ { -description = "SNES emulator with an extensive set of debugging tools"; + description = "Templates for coding SNES roms"; -inputs = { - nixpkgs.url = "github:NixOS/nixpkgs"; - flake-utils.url = "github:numtide/flake-utils"; - - mesen-s.url = "github:NovaSquirrel/Mesen-SX"; - asar.url = "github:RPGHacker/asar"; -}; - -outputs = { self, - nixpkgs, - flake-utils, - mesen-s, - asar, -... }@inputs: - flake-utils.lib.eachDefaultSystem (system: - with import nixpkgs { inherit system; }; - let - # Executable name - pname = ""; - # Project version - version = ""; - - asar-pkg = stdenv.mkDerivation { - pname = "asar"; - version = "1.81"; - - src = asar; - - nativeBuildInputs = [ cmake ]; - configurePhase = "cmake src"; - installPhase = '' - install -Dm755 asar/asar-standalone $out/bin/asar - ''; - }; - mesen-s-pkg = stdenv.mkDerivation { - pname = "mesen-s"; - version = "0.4.0"; - - src = mesen-s; - - nativeBuildInputs = [ clang zip makeWrapper ]; - buildInputs = [ mono6 SDL2 glib gtk2-x11 ]; - - postPatch = "patchShebangs ."; - preBuild = "make clean"; - makeFlags = [ "LTO=true" ]; - - # Adapted from the AUR repo's PKGBUILD - installPhase = '' - cat > mesen-s << END - #!/usr/bin/env sh - mono $out/opt/mesen-s/mesen-s "\$@" - END - - install -Dm755 mesen-s $out/bin/mesen-s - install -Dm755 bin/x64/Release/Mesen-S.exe $out/opt/mesen-s/mesen-s - install -Dm644 InteropDLL/obj.x64/libMesenSCore.x64.dll $out/lib/libMesenSCore.dll - ''; - - preFixup = '' - MPATH="$out/lib:${glib.out}/lib:${gtk2-x11}/lib" - wrapProgram $out/bin/mesen-s --prefix MONO_PATH : "$MPATH" --prefix LD_LIBRARY_PATH : "$MPATH" \ - --prefix PATH : ${lib.makeBinPath [ stdenv.shell mono6 ]} - ''; - }; - in { - shells.default = mkShell { - packages = [ asar-pkg mesen-s-pkg ]; - }; - - packages.default = stdenv.mkDerivation { - inherit pname version; - - src = self; - - nativeBuildInputs = [ asar-pkg ]; - }; - - apps.default = { - type = "app"; - program = "${self.packages.${system}.default}/bin/${pname}"; - }; - }); + outputs = { self }: { + templates.with-asar = { + description = "A template for programming with the Asar assembler"; + path = ./with-asar; + }; + }; } diff --git a/with-asar/Makefile b/with-asar/Makefile new file mode 100644 index 0000000..732c45b --- /dev/null +++ b/with-asar/Makefile @@ -0,0 +1,17 @@ +NAME ?= main + +ASM=asar +ASMFLAGS= + +VPATH=src + +.PHONY: all +all: $(NAME).sfc + +$(NAME).sfc: main.asm + $(ASM) $(ASMFLAGS) $^ $@ + +# Clean directory +.PHONY: clean +clean: + rm $(NAME).sfc diff --git a/with-asar/flake.nix b/with-asar/flake.nix new file mode 100644 index 0000000..6079db3 --- /dev/null +++ b/with-asar/flake.nix @@ -0,0 +1,88 @@ +{ +description = "SNES emulator with an extensive set of debugging tools"; + +inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + + mesen-s-src.url = "github:NovaSquirrel/Mesen-SX"; + mesen-s-src.flake = false; + asar-src.url = "github:RPGHacker/asar"; + asar-src.flake = false; +}; + +outputs = { self, + nixpkgs, + flake-utils, + mesen-s-src, + asar-src, +... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + with import nixpkgs { inherit system; }; + let + # Executable name + pname = ""; + # Project version + version = ""; + + asar = stdenv.mkDerivation { + pname = "asar"; + version = "1.81"; + + src = asar-src; + + nativeBuildInputs = [ cmake ]; + configurePhase = "cmake src"; + installPhase = '' + install -Dm555 asar/asar-standalone $out/bin/asar + ''; + }; + mesen-s = stdenv.mkDerivation { + pname = "mesen-s"; + version = "0.4.0"; + + src = mesen-s-src; + + nativeBuildInputs = [ clang zip makeWrapper ]; + buildInputs = [ mono6 SDL2 glib gtk2-x11 ]; + + preBuild = "make clean"; + makeFlags = [ "LTO=true" ]; + + # Adapted from the AUR repo's PKGBUILD + installPhase = '' + cat > mesen-s << END + #!/usr/bin/env sh + mono $out/opt/mesen-s/mesen-s "\$@" + END + + install -Dm555 mesen-s $out/bin/mesen-s + install -Dm555 bin/x64/Release/Mesen-S.exe $out/opt/mesen-s/mesen-s + install -Dm444 InteropDLL/obj.x64/libMesenSCore.x64.dll $out/lib/libMesenSCore.dll + ''; + + preFixup = '' + MPATH="$out/lib:${glib.out}/lib:${gtk2-x11}/lib" + wrapProgram $out/bin/mesen-s --prefix MONO_PATH : "$MPATH" --prefix LD_LIBRARY_PATH : "$MPATH" \ + --prefix PATH : ${lib.makeBinPath [ stdenv.shell mono6 ]} + ''; + }; + in { + packages.emulator = mesen-s; + + shells.default = mkShell { + packages = [ asar mesen-s ]; + }; + + packages.default = stdenv.mkDerivation { + inherit pname version; + + src = self; + + nativeBuildInputs = [ asar ]; + + makeFlags = [ "NAME=${pname}" ]; + installPhase = "install -m444 ${pname}.sfc $out"; + }; + }); +} diff --git a/with-asar/src/main.asm b/with-asar/src/main.asm new file mode 100644 index 0000000..e69de29