1{ stdenv
2, buildPackages
3, lib
4, fetchzip
5, gpm
6, libffi
7, libGL
8, libX11
9, libXext
10, libXpm
11, libXrandr
12, ncurses
13}:
14
15stdenv.mkDerivation rec {
16 pname = "fbc";
17 version = "1.10.0";
18
19 src = fetchzip {
20 # Bootstrap tarball has sources pretranslated from FreeBASIC to C
21 url = "https://github.com/freebasic/fbc/releases/download/${version}/FreeBASIC-${version}-source-bootstrap.tar.xz";
22 hash = "sha256-7FmyEfykOAgHaL2AG8zIgftzOszhwVzNKEqskiLGpfk=";
23 };
24
25 postPatch = ''
26 patchShebangs tests/warnings/test.sh
27 '';
28
29 dontConfigure = true;
30
31 depsBuildBuild = [
32 buildPackages.stdenv.cc
33 buildPackages.ncurses
34 buildPackages.libffi
35 ];
36
37 buildInputs = [
38 ncurses
39 libffi
40 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
41 gpm
42 libGL
43 libX11
44 libXext
45 libXpm
46 libXrandr
47 ];
48
49 enableParallelBuilding = true;
50
51 hardeningDisable = [
52 "format"
53 ];
54
55 makeFlags = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
56 "TARGET=${stdenv.hostPlatform.config}"
57 ];
58
59 preBuild = ''
60 export buildJobs=$NIX_BUILD_CORES
61 if [ -z "$enableParallelBuilding" ]; then
62 buildJobs=1
63 fi
64
65 echo Bootstrap an unpatched build compiler
66 make bootstrap-minimal -j$buildJobs \
67 BUILD_PREFIX=${buildPackages.stdenv.cc.targetPrefix} LD=${buildPackages.stdenv.cc.targetPrefix}ld
68
69 echo Compile patched build compiler and host rtlib
70 make compiler -j$buildJobs \
71 "FBC=$PWD/bin/fbc${stdenv.buildPlatform.extensions.executable} -i $PWD/inc" \
72 BUILD_PREFIX=${buildPackages.stdenv.cc.targetPrefix} LD=${buildPackages.stdenv.cc.targetPrefix}ld
73 make rtlib -j$buildJobs \
74 "FBC=$PWD/bin/fbc${stdenv.buildPlatform.extensions.executable} -i $PWD/inc" \
75 ${if (stdenv.buildPlatform == stdenv.hostPlatform) then
76 "BUILD_PREFIX=${buildPackages.stdenv.cc.targetPrefix} LD=${buildPackages.stdenv.cc.targetPrefix}ld"
77 else
78 "TARGET=${stdenv.hostPlatform.config}"
79 }
80
81 echo Install patched build compiler and host rtlib to local directory
82 make install-compiler prefix=$PWD/patched-fbc
83 make install-rtlib prefix=$PWD/patched-fbc ${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) "TARGET=${stdenv.hostPlatform.config}"}
84 make clean
85
86 echo Compile patched host everything with previous patched stage
87 buildFlagsArray+=("FBC=$PWD/patched-fbc/bin/fbc${stdenv.buildPlatform.extensions.executable} -i $PWD/inc")
88 '';
89
90 installFlags = [
91 "prefix=${placeholder "out"}"
92 ];
93
94 # Tests do not work when cross-compiling even if build platform can execute
95 # host binaries, compiler struggles to find the cross compiler's libgcc_s
96 doCheck = stdenv.buildPlatform == stdenv.hostPlatform;
97
98 checkTarget = "unit-tests warning-tests log-tests";
99
100 checkFlags = [
101 "UNITTEST_RUN_ARGS=--verbose" # see what unit-tests are doing
102 "ABORT_CMD=false" # abort log-tests on failure
103 ];
104
105 checkPhase = ''
106 runHook preCheck
107
108 # Some tests fail with too much parallelism
109 export maxCheckJobs=50
110 export checkJobs=$(($NIX_BUILD_CORES<=$maxCheckJobs ? $NIX_BUILD_CORES : $maxCheckJobs))
111 if [ -z "$enableParallelChecking" ]; then
112 checkJobs=1
113 fi
114
115 # Run check targets in series, else the logs are a mess
116 for target in $checkTarget; do
117 make $target -j$checkJobs $makeFlags $checkFlags
118 done
119
120 runHook postCheck
121 '';
122
123 meta = with lib; {
124 homepage = "https://www.freebasic.net/";
125 description = "A multi-platform BASIC Compiler";
126 longDescription = ''
127 FreeBASIC is a completely free, open-source, multi-platform BASIC compiler (fbc),
128 with syntax similar to (and support for) MS-QuickBASIC, that adds new features
129 such as pointers, object orientation, unsigned data types, inline assembly,
130 and many others.
131 '';
132 license = licenses.gpl2Plus; # runtime & graphics libraries are LGPLv2+ w/ static linking exception
133 maintainers = with maintainers; [ OPNA2608 ];
134 platforms = with platforms; windows ++ linux;
135 };
136}