sdcc: refactor

- remove null'ities
- assert validity of excludedPorts list
- use finalAttrs design pattern
- split outputs
- add meta.mainProgram,

+53 -24
+53 -24
pkgs/by-name/sd/sdcc/package.nix
··· 1 - { lib, stdenv, fetchurl, autoconf, bison, boost, flex, texinfo, zlib, gputils ? null 2 - , excludePorts ? [] }: 1 + { lib 2 + , stdenv 3 + , fetchurl 4 + , autoconf 5 + , bison 6 + , boost 7 + , flex 8 + , gputils 9 + , texinfo 10 + , zlib 11 + , withGputils ? false 12 + , excludePorts ? [] 13 + }: 3 14 4 - let 5 - # choices: mcs51 z80 z180 r2k r3ka gbz80 tlcs90 ds390 ds400 pic14 pic16 hc08 s08 stm8 6 - excludedPorts = excludePorts ++ (lib.optionals (gputils == null) [ "pic14" "pic16" ]); 7 - in 8 - 9 - stdenv.mkDerivation rec { 15 + assert lib.subtractLists [ 16 + "ds390" "ds400" "gbz80" "hc08" "mcs51" "pic14" "pic16" "r2k" "r3ka" "s08" 17 + "stm8" "tlcs90" "z80" "z180" 18 + ] excludePorts == []; 19 + stdenv.mkDerivation (finalAttrs: { 10 20 pname = "sdcc"; 11 21 version = "4.2.0"; 12 22 13 23 src = fetchurl { 14 - url = "mirror://sourceforge/sdcc/sdcc-src-${version}.tar.bz2"; 15 - sha256 = "sha256-tJuuHSO81gV6gsT/5WE/nNDLz9HpQOnYTEv+nfCowFM="; 24 + url = "mirror://sourceforge/sdcc/sdcc-src-${finalAttrs.version}.tar.bz2"; 25 + hash = "sha256-tJuuHSO81gV6gsT/5WE/nNDLz9HpQOnYTEv+nfCowFM="; 16 26 }; 17 27 28 + outputs = [ "out" "doc" "man" ]; 29 + 18 30 enableParallelBuilding = true; 19 31 20 - buildInputs = [ boost gputils texinfo zlib ]; 32 + nativeBuildInputs = [ 33 + autoconf 34 + bison 35 + flex 36 + ]; 21 37 22 - nativeBuildInputs = [ autoconf bison flex ]; 38 + buildInputs = [ 39 + boost 40 + texinfo 41 + zlib 42 + ] ++ lib.optionals withGputils [ 43 + gputils 44 + ]; 23 45 24 - configureFlags = map (f: "--disable-${f}-port") excludedPorts; 46 + configureFlags = let 47 + excludedPorts = excludePorts 48 + ++ (lib.optionals (!withGputils) [ "pic14" "pic16" ]); 49 + in 50 + map (f: "--disable-${f}-port") excludedPorts; 25 51 26 52 preConfigure = '' 27 53 if test -n "''${dontStrip-}"; then ··· 29 55 fi 30 56 ''; 31 57 32 - meta = with lib; { 58 + meta = { 59 + homepage = "https://sdcc.sourceforge.net/"; 33 60 description = "Small Device C Compiler"; 34 61 longDescription = '' 35 62 SDCC is a retargettable, optimizing ANSI - C compiler suite that targets 36 - the Intel MCS51 based microprocessors (8031, 8032, 8051, 8052, etc.), Maxim 37 - (formerly Dallas) DS80C390 variants, Freescale (formerly Motorola) HC08 based 38 - (hc08, s08) and Zilog Z80 based MCUs (z80, z180, gbz80, Rabbit 2000/3000, 39 - Rabbit 3000A). Work is in progress on supporting the Microchip PIC16 and 40 - PIC18 targets. It can be retargeted for other microprocessors. 63 + the Intel MCS51 based microprocessors (8031, 8032, 8051, 8052, etc.), 64 + Maxim (formerly Dallas) DS80C390 variants, Freescale (formerly Motorola) 65 + HC08 based (hc08, s08) and Zilog Z80 based MCUs (z80, z180, gbz80, Rabbit 66 + 2000/3000, Rabbit 3000A). Work is in progress on supporting the Microchip 67 + PIC16 and PIC18 targets. It can be retargeted for other microprocessors. 41 68 ''; 42 - homepage = "https://sdcc.sourceforge.net/"; 43 - license = with licenses; if (gputils == null) then gpl2Plus else unfreeRedistributable; 44 - maintainers = with maintainers; [ bjornfor yorickvp ]; 45 - platforms = platforms.all; 69 + license = if withGputils 70 + then lib.licenses.unfreeRedistributable 71 + else lib.licenses.gpl2Plus; 72 + mainProgram = "sdcc"; 73 + maintainers = with lib.maintainers; [ bjornfor yorickvp ]; 74 + platforms = lib.platforms.all; 46 75 }; 47 - } 76 + })