From 9ba3b39e44705bc5f0638acb30a4c3077a96f7d9 Mon Sep 17 00:00:00 2001
From: Yorick van Pelt <yorick@yorickvanpelt.nl>
Date: Tue, 17 Jul 2018 17:28:13 +0200
Subject: [PATCH 1/6] gputils: init at 1.5.0-1

---
 pkgs/development/tools/misc/gputils/default.nix | 16 ++++++++++++++++
 pkgs/top-level/all-packages.nix                 |  2 ++
 2 files changed, 18 insertions(+)
 create mode 100644 pkgs/development/tools/misc/gputils/default.nix

diff --git a/pkgs/development/tools/misc/gputils/default.nix b/pkgs/development/tools/misc/gputils/default.nix
new file mode 100644
index 00000000000..dc736e2e89c
--- /dev/null
+++ b/pkgs/development/tools/misc/gputils/default.nix
@@ -0,0 +1,16 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  version = "1.5.0-1";
+  name = "gputils-${version}";
+  src = fetchurl {
+    url = "mirror://sourceforge/gputils/${name}.tar.bz2";
+    sha256 = "055v83fdgqljprapf7rmh8x66mr13fj0qypj49xba5spx0ca123g";
+  };
+  meta = with stdenv.lib; {
+    homepage = http://sdcc.sourceforge.net/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.yorickvp ];
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index d580ef14f6a..bb1b064990a 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -8163,6 +8163,8 @@ with pkgs;
 
   gotty = callPackage ../servers/gotty { };
 
+  gputils = callPackage ../development/tools/misc/gputils { };
+
   gradleGen = callPackage ../development/tools/build-managers/gradle { };
   gradle = self.gradleGen.gradle_latest;
   gradle_2_14 = self.gradleGen.gradle_2_14;

From f969e426c05e53c805140bd9a6f043a7e0de0771 Mon Sep 17 00:00:00 2001
From: Yorick van Pelt <yorick@yorickvanpelt.nl>
Date: Tue, 17 Jul 2018 17:28:26 +0200
Subject: [PATCH 2/6] sdcc: update for added gputils, add disabled flag, adopt

---
 pkgs/development/compilers/sdcc/default.nix | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/pkgs/development/compilers/sdcc/default.nix b/pkgs/development/compilers/sdcc/default.nix
index ec93ba79d44..f2b6e3af439 100644
--- a/pkgs/development/compilers/sdcc/default.nix
+++ b/pkgs/development/compilers/sdcc/default.nix
@@ -1,5 +1,9 @@
-{ stdenv, fetchurl, bison, flex, boost, texinfo, gputils ? null }:
-
+{ stdenv, fetchurl, bison, flex, boost, texinfo, autoconf, gputils ? null, disabled ? [] }:
+let
+  allDisabled = (if gputils == null then [ "pic14" "pic16" ] else []) ++ disabled;
+  # choices: mcs51 z80 z180 r2k r3ka gbz80 tlcs90 ds390 ds400 pic14 pic16 hc08 s08 stm8
+  inherit (stdenv) lib;
+in
 stdenv.mkDerivation rec {
   version = "3.7.0";
   name = "sdcc-${version}";
@@ -9,14 +13,13 @@ stdenv.mkDerivation rec {
     sha256 = "13llvx0j3v5qa7qd4fh7nix4j3alpd3ccprxvx163c4q8q4lfkc5";
   };
 
-  # TODO: remove this comment when gputils != null is tested
-  buildInputs = [ bison flex boost texinfo gputils ];
+  buildInputs = [ bison flex boost texinfo gputils autoconf ];
 
   configureFlags = ''
-    ${if gputils == null then "--disable-pic14-port --disable-pic16-port" else ""}
+    ${lib.concatMapStringsSep " " (f: "--disable-${f}-port") allDisabled}
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Small Device C Compiler";
     longDescription = ''
       SDCC is a retargettable, optimizing ANSI - C compiler suite that targets
@@ -29,6 +32,6 @@ stdenv.mkDerivation rec {
     homepage = http://sdcc.sourceforge.net/;
     license = licenses.gpl2;
     platforms = platforms.linux;
-    maintainers = [ maintainers.bjornfor ];
+    maintainers = [ maintainers.bjornfor maintainers.yorickvp ];
   };
 }

From 072febaa922635bd048d683ef51c408c1873f348 Mon Sep 17 00:00:00 2001
From: Yegor Timoshenko <yegortimoshenko@riseup.net>
Date: Tue, 17 Jul 2018 19:05:15 +0300
Subject: [PATCH 3/6] sdcc: null out gputils by default

---
 pkgs/top-level/all-packages.nix | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index bb1b064990a..c42510a5c8d 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -7074,7 +7074,9 @@ with pkgs;
 
   scalafmt = callPackage ../development/tools/scalafmt { };
 
-  sdcc = callPackage ../development/compilers/sdcc { };
+  sdcc = callPackage ../development/compilers/sdcc {
+    gputils = null;
+  };
 
   serpent = callPackage ../development/compilers/serpent { };
 

From 4bd4c876f2607322cee7716a7a67c3e2e2e294c4 Mon Sep 17 00:00:00 2001
From: Yegor Timoshenko <yegortimoshenko@riseup.net>
Date: Tue, 17 Jul 2018 19:16:24 +0300
Subject: [PATCH 4/6] sdcc: clean up

---
 pkgs/development/compilers/sdcc/default.nix | 24 +++++++++++----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/pkgs/development/compilers/sdcc/default.nix b/pkgs/development/compilers/sdcc/default.nix
index f2b6e3af439..0e9a348dd50 100644
--- a/pkgs/development/compilers/sdcc/default.nix
+++ b/pkgs/development/compilers/sdcc/default.nix
@@ -1,25 +1,27 @@
-{ stdenv, fetchurl, bison, flex, boost, texinfo, autoconf, gputils ? null, disabled ? [] }:
+{ stdenv, fetchurl, autoconf, bison, boost, flex, texinfo, gputils ? null
+, excludePorts ? [] }:
+
+with stdenv.lib;
+
 let
-  allDisabled = (if gputils == null then [ "pic14" "pic16" ] else []) ++ disabled;
   # choices: mcs51 z80 z180 r2k r3ka gbz80 tlcs90 ds390 ds400 pic14 pic16 hc08 s08 stm8
-  inherit (stdenv) lib;
+  excludedPorts = excludePorts ++ (optionals (gputils == null) [ "pic14" "pic16" ]);
 in
+
 stdenv.mkDerivation rec {
-  version = "3.7.0";
   name = "sdcc-${version}";
+  version = "3.7.0";
 
   src = fetchurl {
     url = "mirror://sourceforge/sdcc/sdcc-src-${version}.tar.bz2";
     sha256 = "13llvx0j3v5qa7qd4fh7nix4j3alpd3ccprxvx163c4q8q4lfkc5";
   };
 
-  buildInputs = [ bison flex boost texinfo gputils autoconf ];
+  buildInputs = [ autoconf bison boost flex gputils texinfo ];
 
-  configureFlags = ''
-    ${lib.concatMapStringsSep " " (f: "--disable-${f}-port") allDisabled}
-  '';
+  configureFlags = map (f: "--disable-${f}-port") excludedPorts;
 
-  meta = with lib; {
+  meta = {
     description = "Small Device C Compiler";
     longDescription = ''
       SDCC is a retargettable, optimizing ANSI - C compiler suite that targets
@@ -30,8 +32,8 @@ stdenv.mkDerivation rec {
       PIC18 targets. It can be retargeted for other microprocessors.
     '';
     homepage = http://sdcc.sourceforge.net/;
-    license = licenses.gpl2;
+    license = with licenses; if (gputils == null) then unfreeRedistributable else gpl2;
+    maintainers = with maintainers; [ bjornfor yorickvp ];
     platforms = platforms.linux;
-    maintainers = [ maintainers.bjornfor maintainers.yorickvp ];
   };
 }

From 879edd79be34563547c884d44fed0e05cc9a2266 Mon Sep 17 00:00:00 2001
From: Yegor Timoshenko <yegortimoshenko@riseup.net>
Date: Tue, 17 Jul 2018 19:17:03 +0300
Subject: [PATCH 5/6] sdcc: fix license condition

---
 pkgs/development/compilers/sdcc/default.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/development/compilers/sdcc/default.nix b/pkgs/development/compilers/sdcc/default.nix
index 0e9a348dd50..f7429933453 100644
--- a/pkgs/development/compilers/sdcc/default.nix
+++ b/pkgs/development/compilers/sdcc/default.nix
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
       PIC18 targets. It can be retargeted for other microprocessors.
     '';
     homepage = http://sdcc.sourceforge.net/;
-    license = with licenses; if (gputils == null) then unfreeRedistributable else gpl2;
+    license = with licenses; if (gputils == null) then gpl2 else unfreeRedistributable;
     maintainers = with maintainers; [ bjornfor yorickvp ];
     platforms = platforms.linux;
   };

From e6a721ed6076d900deb5644ac7d881220e3770ba Mon Sep 17 00:00:00 2001
From: Yegor Timoshenko <yegortimoshenko@riseup.net>
Date: Tue, 17 Jul 2018 19:19:01 +0300
Subject: [PATCH 6/6] gputils: clean up, fix homepage url

---
 pkgs/development/tools/misc/gputils/default.nix | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pkgs/development/tools/misc/gputils/default.nix b/pkgs/development/tools/misc/gputils/default.nix
index dc736e2e89c..aaaee20b81a 100644
--- a/pkgs/development/tools/misc/gputils/default.nix
+++ b/pkgs/development/tools/misc/gputils/default.nix
@@ -1,16 +1,18 @@
 { stdenv, fetchurl }:
 
 stdenv.mkDerivation rec {
-  version = "1.5.0-1";
   name = "gputils-${version}";
+  version = "1.5.0-1";
+
   src = fetchurl {
     url = "mirror://sourceforge/gputils/${name}.tar.bz2";
     sha256 = "055v83fdgqljprapf7rmh8x66mr13fj0qypj49xba5spx0ca123g";
   };
+
   meta = with stdenv.lib; {
-    homepage = http://sdcc.sourceforge.net/;
+    homepage = https://gputils.sourceforge.io/;
     license = licenses.gpl2;
+    maintainers = with maintainers; [ yorickvp ];
     platforms = platforms.linux;
-    maintainers = [ maintainers.yorickvp ];
   };
 }