diff --git a/.gitignore b/.gitignore index ea1472e..00e91da 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ output/ + +result +result-* diff --git a/Makefile b/Makefile index 7a23797..745dd06 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,10 @@ CFLAGS_WARNINGS = -Wall -Wextra CFLAGS_RELEASE = -O2 -fstack-protector-strong -fpie CFLAGS_DEBUG = -O0 -ggdb -DDEBUG -fsanitize=address -static-libasan +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin + SOURCE_FOLDER = src SOURCE = main.c TARGET = wamf @@ -18,7 +22,7 @@ REMOTE_HOST = innovation.pvv.ntnu.no REMOTE_DIR = /tmp/wamf REMOTE_PATH = $(REMOTE_USER)@$(REMOTE_HOST):$(REMOTE_DIR) -.PHONY: all release debug clean deploy remote-build remote-clean remote-run +.PHONY: all install release debug clean deploy remote-build remote-clean remote-run help all: $(OUTPUT) @@ -31,6 +35,9 @@ $(OUTPUT) release: $(SOURCE_FOLDER)/$(SOURCE) $(OUTPUT_FOLDER) $(OUTPUT_DEBUG) debug: $(SOURCE_FOLDER)/$(SOURCE) $(OUTPUT_FOLDER) $(CC) $(CFLAGS) $(CFLAGS_WARNINGS) $(CFLAGS_DEBUG) -o $(OUTPUT_DEBUG) $(SOURCE_FOLDER)/$(SOURCE) +install: $(OUTPUT) + install -Dm755 $(OUTPUT) -t $(bindir) + clean: rm -rf $(OUTPUT_FOLDER) @@ -55,7 +62,6 @@ remote-run: remote-build @echo "Running on remote server..." ssh $(REMOTE_USER)@$(REMOTE_HOST) "cd $(REMOTE_DIR) && ./$(TARGET)" -.PHONY: help help: @echo "Available targets:" @echo " all - Build locally" diff --git a/flake.nix b/flake.nix index 6120759..96f3740 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "development shell"; + description = "RCON -> Bluemap player position API converter"; inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; @@ -7,11 +7,31 @@ let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; + inherit (pkgs) lib; in { - devShells.x86_64-linux.default = pkgs.mkShell { + devShells.${system}.default = pkgs.mkShell { buildInputs = with pkgs; [ clang ]; }; + + packages.${system} = let + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Makefile + ./src + ]; + }; + in { + default = self.packages.${system}.wamf; + wamf = pkgs.callPackage ./nix/package.nix { inherit src; }; + wamf-freebsd-cross = let + pkgs = import nixpkgs { + localSystem = system; + crossSystem = "x86_64-freebsd"; + }; + in pkgs.callPackage ./nix/package.nix { inherit src; }; + }; }; } diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..5990536 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,33 @@ +{ + lib, + src, + stdenv, +}: +let + isFreebsdCross = !stdenv.buildPlatform.isFreeBSD && stdenv.hostPlatform.isFreeBSD; +in +stdenv.mkDerivation { + pname = "where-are-my-friends"; + version = "0.1.0"; + inherit src; + + makeFlags = [ + "prefix=$(out)" + "CC=${stdenv.cc.targetPrefix}cc" + ]; + + postFixup = lib.optionalString isFreebsdCross '' + patchelf --set-interpreter /usr/libexec/ld-elf.so.1 "$out/bin/wamf" + patchelf --remove-rpath "$out/bin/wamf" + ''; + + hardeningDisable = lib.optionals isFreebsdCross [ "fortify" ]; + + meta = { + description = "RCON -> Bluemap player position API converter"; + homepage = "https://git.pvv.ntnu.no/Projects/where-are-my-friends"; + platforms = lib.platforms.unix; + mainProgram = "wamf"; + }; +} +