@@ -1,8 +1,37 @@
11{ stdenv, fetchurl,
2− bison2, flex, fontconfig, freetype, gperf, icu, openssl, libjpeg, libpng, perl, python, ruby, sqlite
2+ bison2, flex, fontconfig, freetype, gperf, icu, openssl, libjpeg, libpng, perl, python, ruby, sqlite,
3+ darwin, writeScriptBin, cups
34}:
45
5−stdenv.mkDerivation rec {
6+let
7+ fakeXcrun = writeScriptBin "xcrun" ''
8+ #!${stdenv.shell}
9+ echo >&2 "Fake xcrun: ''$@"
10+ args=()
11+ while (("$#")); do
12+ case "$1" in
13+ -sdk*) shift;;
14+ -find*) shift;;
15+ *) args+=("$1");;
16+ esac
17+ shift
18+ done
19+
20+ if [ "''${#args[@]}" -gt "0" ]; then
21+ echo >&2 "Fake xcrun: ''${args[@]}"
22+ exec "''${args[@]}"
23+ fi
24+ '';
25+ fakeClang = writeScriptBin "clang" ''
26+ #!${stdenv.shell}
27+ if [[ "$@" == *.c ]]; then
28+ exec "${stdenv.cc}/bin/clang" "$@"
29+ else
30+ exec "${stdenv.cc}/bin/clang++" "$@"
31+ fi
32+ '';
33+
34+in stdenv.mkDerivation rec {
635 name = "phantomjs-${version}";
736 version = "2.0.0-20150528";
837
@@ -11,19 +40,58 @@ stdenv.mkDerivation rec {
1140 sha256 = "18h37bxxg25lacry9k3vb5yim057bqcxmsifw97jrjp7gzfx56v5";
1241 };
1342
14− buildInputs = [ bison2 flex fontconfig freetype gperf icu openssl libjpeg libpng perl python ruby sqlite ];
43+ buildInputs = [ bison2 flex fontconfig freetype gperf icu openssl libjpeg libpng perl python ruby sqlite ]
44+ ++ stdenv.lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
45+ AGL ApplicationServices AppKit Cocoa OpenGL
46+ darwin.libobjc fakeClang cups
47+ ]);
48+
1549
1650 patchPhase = ''
1751 patchShebangs .
1852 sed -i -e 's|/bin/pwd|pwd|' src/qt/qtbase/configure
53+ '' + stdenv.lib.optionalString stdenv.isDarwin ''
54+ sed -i 's,-licucore,/usr/lib/libicucore.dylib,' src/qt/qtwebkit/Source/WTF/WTF.pri
55+ substituteInPlace src/qt/qtwebkit/Tools/qmake/mkspecs/features/features.pri \
56+ --replace "ENABLE_3D_RENDERING=1" "ENABLE_3D_RENDERING=0"
57+ sed -i 88d src/qt/qtwebkit/Tools/qmake/mkspecs/features/features.prf
58+ echo 'CONFIG -= create_cmake' >> src/qt/qtwebkit/Source/api.pri
59+ echo 'CONFIG -= create_cmake' >> src/qt/qtwebkit/Source/widgetsapi.pri
60+ pushd src/qt
61+
62+ substituteInPlace qtbase/configure \
63+ --replace /usr/bin/xcode-select true \
64+ --replace '/usr/bin/xcodebuild -sdk $sdk -version Path 2>/dev/null' 'echo /var/empty' \
65+ --replace '/usr/bin/xcrun -sdk $sdk -find' 'type -P'
66+ substituteInPlace qtbase/mkspecs/features/mac/default_pre.prf \
67+ --replace '/usr/bin/xcode-select --print-path 2>/dev/null' "echo ${stdenv.libc}" \
68+ --replace '/usr/bin/xcrun -find xcrun 2>/dev/null' 'echo success' \
69+ --replace '/usr/bin/xcodebuild -version' 'echo Xcode 7.2; echo Build version 7C68' \
70+ --replace 'sdk rez' ""
71+ for file in $(grep -rl /usr/bin/xcrun .); do
72+ substituteInPlace "$file" --replace "/usr/bin/xcrun" ${fakeXcrun}/bin/xcrun
73+ done
74+ substituteInPlace qtbase/src/tools/qlalr/lalr.cpp --replace _Nullable Nullable
75+
76+ popd
1977 '';
2078
79+ __impureHostDeps = stdenv.lib.optional stdenv.isDarwin "/usr/lib/libicucore.dylib";
80+
2181 buildPhase = "./build.sh --confirm";
2282
2383 installPhase = ''
2484 mkdir -p $out/share/doc/phantomjs
2585 cp -a bin $out
2686 cp -a ChangeLog examples LICENSE.BSD README.md third-party.txt $out/share/doc/phantomjs
87+ '' + stdenv.lib.optionalString stdenv.isDarwin ''
88+ install_name_tool -change \
89+ ${darwin.CF}/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation \
90+ /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation \
91+ -change \
92+ ${darwin.configd}/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration \
93+ /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration \
94+ $out/bin/phantomjs
2795 '';
2896
2997 meta = {