From 4a4300eae49622868868999f773b72d3e4598d59 Mon Sep 17 00:00:00 2001
From: Weijia Wang <9713184+wegank@users.noreply.github.com>
Date: Sat, 8 Oct 2022 21:44:03 +0200
Subject: [PATCH] wxhexeditor: add darwin support

---
 pkgs/applications/editors/wxhexeditor/default.nix | 13 +++++++++----
 pkgs/top-level/all-packages.nix                   |  4 +++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/pkgs/applications/editors/wxhexeditor/default.nix b/pkgs/applications/editors/wxhexeditor/default.nix
index f310fb85a26c..efcbe32f78d7 100644
--- a/pkgs/applications/editors/wxhexeditor/default.nix
+++ b/pkgs/applications/editors/wxhexeditor/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, fetchFromGitHub, fetchpatch, wxGTK, autoconf, automake, libtool, python2, gettext }:
+{ lib, stdenv, fetchFromGitHub, fetchpatch, wxGTK, autoconf, automake, libtool, python2, gettext, openmp, Cocoa }:
 
 stdenv.mkDerivation rec {
   pname = "wxHexEditor";
@@ -12,13 +12,17 @@ stdenv.mkDerivation rec {
   };
 
   nativeBuildInputs = [ autoconf automake ];
-  buildInputs = [ wxGTK libtool python2 gettext ];
+  buildInputs = [ wxGTK libtool python2 gettext ]
+    ++ lib.optionals stdenv.cc.isClang [ openmp ]
+    ++ lib.optionals stdenv.isDarwin [ Cocoa ];
 
   preConfigure = "patchShebangs .";
 
   prePatch = ''
     substituteInPlace Makefile --replace "/usr" "$out"
     substituteInPlace Makefile --replace "mhash; ./configure" "mhash; ./configure --prefix=$out"
+  '' + lib.optionalString stdenv.cc.isClang ''
+    substituteInPlace Makefile --replace "-lgomp" "-lomp"
   '';
 
   patches = [
@@ -30,7 +34,7 @@ stdenv.mkDerivation rec {
     ./missing-semicolon.patch
   ];
 
-  makeFlags = [ "OPTFLAGS=-fopenmp" ];
+  makeFlags = lib.optionals stdenv.cc.isGNU [ "OPTFLAGS=-fopenmp" ];
 
   meta = {
     description = "Hex Editor / Disk Editor for Huge Files or Devices";
@@ -46,6 +50,7 @@ stdenv.mkDerivation rec {
     '';
     homepage = "http://www.wxhexeditor.org/";
     license = lib.licenses.gpl2;
-    platforms = lib.platforms.linux;
+    platforms = lib.platforms.unix;
+    maintainers = with lib.maintainers; [ wegank ];
   };
 }
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 9cfdc1f70e02..1e2bb347978f 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -32423,7 +32423,9 @@ with pkgs;
   wsjtx = qt5.callPackage ../applications/radio/wsjtx { };
 
   wxhexeditor = callPackage ../applications/editors/wxhexeditor {
-    wxGTK = wxGTK31;
+    inherit (darwin.apple_sdk.frameworks) Cocoa;
+    inherit (llvmPackages) openmp;
+    wxGTK = wxGTK32;
   };
 
   xa = callPackage ../development/compilers/xa/xa.nix { };