about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/fbc/default.nix
blob: 631bf9c7bfe02ede231985d59adcb55e202350bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{ stdenv
, buildPackages
, lib
, fetchzip
, gpm
, libffi
, libGL
, libX11
, libXext
, libXpm
, libXrandr
, ncurses
}:

stdenv.mkDerivation rec {
  pname = "fbc";
  version = "1.10.1";

  src = fetchzip {
    # Bootstrap tarball has sources pretranslated from FreeBASIC to C
    url = "https://github.com/freebasic/fbc/releases/download/${version}/FreeBASIC-${version}-source-bootstrap.tar.xz";
    hash = "sha256-LBROv3m1DrEfSStMbNuLC+fldYNfSS+D09bJyNMNPP0=";
  };

  postPatch = ''
    patchShebangs tests/warnings/test.sh
  '';

  dontConfigure = true;

  depsBuildBuild = [
    buildPackages.stdenv.cc
    buildPackages.ncurses
    buildPackages.libffi
  ];

  buildInputs = [
    ncurses
    libffi
  ] ++ lib.optionals stdenv.hostPlatform.isLinux [
    gpm
    libGL
    libX11
    libXext
    libXpm
    libXrandr
  ];

  enableParallelBuilding = true;

  hardeningDisable = [
    "format"
  ];

  makeFlags = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
    "TARGET=${stdenv.hostPlatform.config}"
  ];

  preBuild = ''
    export buildJobs=$NIX_BUILD_CORES
    if [ -z "$enableParallelBuilding" ]; then
      buildJobs=1
    fi

    echo Bootstrap an unpatched build compiler
    make bootstrap-minimal -j$buildJobs \
      BUILD_PREFIX=${buildPackages.stdenv.cc.targetPrefix} LD=${buildPackages.stdenv.cc.targetPrefix}ld

    echo Compile patched build compiler and host rtlib
    make compiler -j$buildJobs \
      "FBC=$PWD/bin/fbc${stdenv.buildPlatform.extensions.executable} -i $PWD/inc" \
      BUILD_PREFIX=${buildPackages.stdenv.cc.targetPrefix} LD=${buildPackages.stdenv.cc.targetPrefix}ld
    make rtlib -j$buildJobs \
      "FBC=$PWD/bin/fbc${stdenv.buildPlatform.extensions.executable} -i $PWD/inc" \
      ${if (stdenv.buildPlatform == stdenv.hostPlatform) then
        "BUILD_PREFIX=${buildPackages.stdenv.cc.targetPrefix} LD=${buildPackages.stdenv.cc.targetPrefix}ld"
      else
        "TARGET=${stdenv.hostPlatform.config}"
      }

    echo Install patched build compiler and host rtlib to local directory
    make install-compiler prefix=$PWD/patched-fbc
    make install-rtlib prefix=$PWD/patched-fbc ${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) "TARGET=${stdenv.hostPlatform.config}"}
    make clean

    echo Compile patched host everything with previous patched stage
    buildFlagsArray+=("FBC=$PWD/patched-fbc/bin/fbc${stdenv.buildPlatform.extensions.executable} -i $PWD/inc")
  '';

  installFlags = [
    "prefix=${placeholder "out"}"
  ];

  # Tests do not work when cross-compiling even if build platform can execute
  # host binaries, compiler struggles to find the cross compiler's libgcc_s
  doCheck = stdenv.buildPlatform == stdenv.hostPlatform;

  checkTarget = "unit-tests warning-tests log-tests";

  checkFlags = [
    "UNITTEST_RUN_ARGS=--verbose" # see what unit-tests are doing
    "ABORT_CMD=false" # abort log-tests on failure
  ];

  checkPhase = ''
    runHook preCheck

    # Some tests fail with too much parallelism
    export maxCheckJobs=50
    export checkJobs=$(($NIX_BUILD_CORES<=$maxCheckJobs ? $NIX_BUILD_CORES : $maxCheckJobs))
    if [ -z "$enableParallelChecking" ]; then
      checkJobs=1
    fi

    # Run check targets in series, else the logs are a mess
    for target in $checkTarget; do
      make $target -j$checkJobs $makeFlags $checkFlags
    done

    runHook postCheck
  '';

  meta = with lib; {
    homepage = "https://www.freebasic.net/";
    description = "A multi-platform BASIC Compiler";
    longDescription = ''
      FreeBASIC is a completely free, open-source, multi-platform BASIC compiler (fbc),
      with syntax similar to (and support for) MS-QuickBASIC, that adds new features
      such as pointers, object orientation, unsigned data types, inline assembly,
      and many others.
    '';
    license = licenses.gpl2Plus; # runtime & graphics libraries are LGPLv2+ w/ static linking exception
    maintainers = with maintainers; [ OPNA2608 ];
    platforms = with platforms; windows ++ linux;
  };
}