1{ stdenv, bzip2, patchelf, glibc, gcc, fetchurl, version, releaseType, sha256, ncurses
2, dirName ? null, subdirName ? null }:
3with stdenv.lib;
4let
5 versionParts = splitString "-" version; # 4.7 2013q3 20130916
6 majorVersion = elemAt versionParts 0; # 4.7
7 yearQuarter = elemAt versionParts 1; # 2013q3
8 underscoreVersion = replaceChars ["."] ["_"] version; # 4_7-2013q3-20130916
9 yearQuarterParts = splitString "q" yearQuarter; # 2013 3
10 year = elemAt yearQuarterParts 0; # 2013
11 quarter = elemAt yearQuarterParts 1; # 3
12 dirName_ = if dirName != null then dirName else majorVersion;
13 subdirName_ = if subdirName != null then subdirName
14 else "${majorVersion}-${year}-q${quarter}-${releaseType}"; # 4.7-2013-q3-update
15in
16stdenv.mkDerivation {
17 name = "gcc-arm-embedded-${version}";
18
19 src = fetchurl {
20 url = "https://launchpad.net/gcc-arm-embedded/${dirName_}/${subdirName_}/+download/gcc-arm-none-eabi-${underscoreVersion}-linux.tar.bz2";
21 sha256 = sha256;
22 };
23
24 buildInputs = [ bzip2 patchelf ];
25
26 dontPatchELF = true;
27
28 phases = "unpackPhase patchPhase installPhase";
29
30 installPhase = ''
31 mkdir -pv $out
32 cp -r ./* $out
33
34 for f in $(find $out); do
35 if [ -f "$f" ] && patchelf "$f" 2> /dev/null; then
36 patchelf --set-interpreter ${getLib glibc}/lib/ld-linux.so.2 \
37 --set-rpath ${stdenv.lib.makeLibraryPath [ "$out" gcc ncurses ]} \
38 "$f" || true
39 fi
40 done
41 '';
42
43 meta = with stdenv.lib; {
44 description = "Pre-built GNU toolchain from ARM Cortex-M & Cortex-R processors (Cortex-M0/M0+/M3/M4, Cortex-R4/R5/R7)";
45 homepage = https://launchpad.net/gcc-arm-embedded;
46 license = with licenses; [ bsd2 gpl2 gpl3 lgpl21 lgpl3 mit ];
47 maintainers = [ maintainers.rasendubi ];
48 platforms = platforms.linux;
49 };
50}