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