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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# Old Maintainer: Mikhail Vorozhtsov <[email protected]>
# Maintainer: Gustavo Alvarez <[email protected]>
# Change PKGBUILD sugested by: Nagisa

#########################
## -- Build options -- ##
#########################
_use_nacl=1          # Enable Native Client support.
_use_libpdf=1        # Enable Chrome PDF support.
_use_pepperflash=1   # Use Pepper Flash plugin. Depends on Native Client!

##########################################################
## -- Invalid build options (build fails if enabled) -- ##
##########################################################
#_use_system_ffmpeg=0  # Use system ffmpeg libraries when building.
# Doesn't work because of GCC 4.7 headers. If you use 4.6, you can enable it.
_use_clang=0           # Use clang compiler. Results in faster build and smaller chromium.

##############################################
## -- Package and components information -- ##
##############################################
pkgname='chromium-dev'
pkgver='25.0.1323.1'
_toolchains_rev="10235" 
pkgrel='1'
pkgdesc='The open-source project behind Google Chrome (Dev channel)'
arch=('i686' 'x86_64')
url='http://www.chromium.org/'
license=('BSD')
depends=('dbus-glib' 'alsa-lib' 'hicolor-icon-theme' 'libevent' 'libxss' 'nss' 'libxslt' 'udev' 'desktop-file-utils' 'gtk2' 'flac' 'libpng' 'libjpeg' 
         'icu' 'libusb' 'expat' 'libvpx' 'libwebp' 'minizip' 'speex') #'opus'
makedepends=('python2' 'gperf' 'yasm' 'mesa' 'bison' 'xdg-utils' 'elfutils' 'subversion' 'python2-simplejson')
install="${pkgname}.install"
backup=('etc/chromium-dev/default')
noextract=()
source=("http://commondatastorage.googleapis.com/chromium-browser-official/chromium-${pkgver}.tar.bz2"
        "${pkgname}.desktop"
        "${pkgname}.sh"
        'default'
        'gcc-4.7.diff'
        'chromium-ppapi-r0.patch'
        'chromium-20.0.1132.57-glib-2.16-use-siginfo_t.patch'
        'pulse_audio_fix.patch')
sha1sums=('de32f7d5a2b44e8c54ed1733903c14a56f8e378b'
          '004d7496d7e08d96bb884748a9e55cd71cf78cee'
          '54c53502c26456c9735e67314b2d61e29477438e'
          'd6d2da45c0729dfd1c606a15c8ffb7591dbc7b44'
          'e25739be0c7e6d14c2675d3ed4dcd99f63f4661c'
          'c07d63888e5b72ecb598e45645cdd5c05d8e0c89'
          '770065c9e6c68ee7da2a4205cca23b252102cfea'
          'ed61977e494b6f23b9639f80bad15447c63b5554')
_before_srcdir="$(pwd)"

################################################
## -- Don't touch anything below this line -- ##
################################################
# Additional dependencies
#[ "${_use_system_ffmpeg}" = "1" ] && depends+=('ffmpeg')

# Do we use NaCl?
if [ "${_use_nacl}" = "1" ]; then
    _naclsdk_path="http://gsdview.appspot.com/nativeclient-archive2/toolchain/${_toolchains_rev}"
    _toolchain_path="http://gsdview.appspot.com/nativeclient-archive2/x86_toolchain/r${_toolchains_rev}"

    _naclsdk_nacl_sha1sum=$(curl -sL "${_naclsdk_path}/naclsdk_linux_x86.tgz.sha1hash")
    _naclsdk_pnacl_sha1sum=$(curl -sL "${_naclsdk_path}/naclsdk_pnacl_linux_x86.tgz.sha1hash")
    _naclsdk_toolchain_sha1sum=$(curl -sL "${_toolchain_path}/toolchain_linux_x86.tar.bz2.sha1hash")
    
    source+=("naclsdk_nacl-${_toolchains_rev}.tgz"::"${_naclsdk_path}/naclsdk_linux_x86.tgz"
             "naclsdk_pnacl-${_toolchains_rev}.tgz"::"${_naclsdk_path}/naclsdk_pnacl_linux_x86.tgz"
             "naclsdk_toolchain-${_toolchains_rev}.tar.bz2"::"${_toolchain_path}/toolchain_linux_x86.tar.bz2")
    sha1sums+=("${_naclsdk_nacl_sha1sum}"
               "${_naclsdk_pnacl_sha1sum}"
               "${_naclsdk_toolchain_sha1sum}")
    noextract+=("naclsdk_nacl-${_toolchains_rev}.tgz"
                "naclsdk_pnacl-${_toolchains_rev}.tgz"
                "naclsdk_toolchain-${_toolchains_rev}.tar.bz2")
fi

# Pepper Flash Plugin and/or libpdf?
if [ "${_use_pepperflash}" = "1" ] || [ "${_use_libpdf}" = "1" ]; then
    [ "$CARCH" = "i686" ] && _rpm_arch='i386'
    [ "$CARCH" = "x86_64" ] && _rpm_arch='x86_64'
    rm -f filelists.xml
    curl -sL "http://dl.google.com/linux/chrome/rpm/stable/${_rpm_arch}/repodata/filelists.xml.gz" | gzip -d > filelists.xml
    _rpm_build="$(grep -e "unstable" filelists.xml | cut -d '"' -f12 | head -n 1)"
    _rpm_sha1sum="$(grep -e "unstable" filelists.xml | cut -d '"' -f2 | head -n 1)"
    rm -f filelists.xml

    source+=("http://dl.google.com/linux/chrome/rpm/stable/${_rpm_arch}/google-chrome-unstable-${pkgver}-${_rpm_build}.${_rpm_arch}.rpm")
    sha1sums+=("${_rpm_sha1sum}")
    noextract+=("google-chrome-unstable-${pkgver}-${_rpm_build}.${_rpm_arch}.rpm")
fi

# Are we in Gnome?
_use_gnome=0
if [ -x /usr/bin/gconftool-2 ]; then
    depends+=('gconf' 'libgnome-keyring')
    _use_gnome=1
fi

# Use Pulseaudio?
_use_pulseaudio=0
if [ -x /usr/bin/pulseaudio ]; then
    depends+=('libpulse')
    _use_pulseaudio=1
fi

# -- Fails -- #
# Disable Pepper flash if NaCL is disabled.
if [ "${_use_pepperflash}" = "1" ] && [ "${_use_nacl}" = "0" ]; then
    msg "To use PepperFlash you need to build chromium with NaCl!. Disabling PepperFlash support"
    _use_pepperflash=0
fi

build() {
    ##############################
    ## -- Get ready to build -- ##
    ##############################
    cd "${srcdir}"

    rm -rf chromium-build
    mv "chromium-${pkgver}" chromium-build
    cd chromium-build

    #msg "Compiler specific configuration..."
    if [ "${_use_clang}" = "1" ]; then
        msg2 "Download clang"
        sh ./tools/clang/scripts/update.sh
    fi

    msg "Configure to save configuration in ~/.config/${pkgname}"
    sed -e "s|'filename': 'chromium-browser'|'filename': '${pkgname}'|" -e "s|'confdir': 'chromium'|'confdir': '${pkgname}'|" -i chrome/chrome_exe.gypi
    sed -e "s|config_dir.Append(\"chromium\")|config_dir.Append(\"${pkgname}\")|" -e "s|config_dir.Append(\"chrome-frame\")|config_dir.Append(\"chrome-frame-${pkgname#chromium-}\")|" -i chrome/common/chrome_paths_linux.cc

    msg "Remove unnecesary components"
    find third_party -type f \! -iname '*.gyp*' \
        \! -path 'third_party/angle/*' \
        \! -path 'third_party/cacheinvalidation/*' \
        \! -path 'third_party/cld/*' \
        \! -path 'third_party/cros_system_api/*'  \
        \! -path 'third_party/ffmpeg/*' \
        \! -path 'third_party/flac/flac.h' \
        \! -path 'third_party/flot/*' \
        \! -path 'third_party/gpsd/*' \
        \! -path 'third_party/harfbuzz/*' \
        \! -path 'third_party/harfbuzz-ng/*' \
        \! -path 'third_party/hunspell/*' \
        \! -path 'third_party/hyphen/*' \
        \! -path 'third_party/iccjpeg/*' \
        \! -path 'third_party/jsoncpp/*' \
        \! -path 'third_party/khronos/*' \
        \! -path 'third_party/leveldatabase/*' \
        \! -path 'third_party/libjingle/*' \
        \! -path 'third_party/libphonenumber/*' \
        \! -path 'third_party/libsrtp/*' \
        \! -path 'third_party/libusb/libusb.h' \
        \! -path 'third_party/libva/*' \
        \! -path 'third_party/libvpx/libvpx.h' \
        \! -path 'third_party/libxml/chromium/*' \
        \! -path 'third_party/libXNVCtrl/*' \
        \! -path 'third_party/libyuv/*' \
        \! -path 'third_party/llvm-build/*' \
        \! -path 'third_party/lss/*' \
        \! -path 'third_party/mesa/*' \
        \! -path 'third_party/modp_b64/*' \
        \! -path 'third_party/mongoose/*' \
        \! -path 'third_party/mt19937ar/*' \
        \! -path 'third_party/npapi/*' \
        \! -path 'third_party/openmax/*' \
        \! -path 'third_party/opus/*' \
        \! -path 'third_party/ots/*' \
        \! -path 'third_party/ply/*' \
        \! -path 'third_party/protobuf/*' \
        \! -path 'third_party/pywebsocket/*' \
        \! -path 'third_party/qcms/*' \
        \! -path 'third_party/re2/*' \
        \! -path 'third_party/scons-2.0.1/*' \
        \! -path 'third_party/sfntly/*' \
        \! -path 'third_party/skia/*' \
        \! -path 'third_party/smhasher/*' \
        \! -path 'third_party/speex/speex.h' \
        \! -path 'third_party/sqlite/*' \
        \! -path 'third_party/tcmalloc/*' \
        \! -path 'third_party/tlslite/*' \
        \! -path 'third_party/trace-viewer/*' \
        \! -path 'third_party/undoview/*' \
        \! -path 'third_party/v8-i18n/*' \
        \! -path 'third_party/v8/*' \
        \! -path 'third_party/webdriver/*' \
        \! -path 'third_party/webgl_conformance/*' \
        \! -path 'third_party/WebKit/*' \
        \! -path 'third_party/webrtc/*' \
        \! -path 'third_party/widevine/*' \
        -delete

    msg "Misc patches"
    # Fix missing gcc4.7.x header
    patch --silent -p0 -E -i "${srcdir}/gcc-4.7.diff"

    # Fix build with glibc 2.16
    patch --silent -p1 -E -i "${srcdir}/chromium-20.0.1132.57-glib-2.16-use-siginfo_t.patch"

    # Fix compilation with glib-2.31.6 (http://crbug.com/109527)
    sed -i 's|glib/gutils.h|glib.h|' "${srcdir}/chromium-build/ui/base/l10n/l10n_util.cc"

    # Fix build with Pulseaudio (http://crbug.com/157876)
    patch --silent -p1 -E -i "${srcdir}/pulse_audio_fix.patch"

    # Missing gyp files in tarball. (http://crbug.com/144823)
    if [[ ! -e chrome/test/data/nacl/nacl_test_data.gyp ]]; then
        mkdir -p chrome/test/data/nacl
        touch chrome/test/data/nacl/nacl_test_data.gyp
        echo "{
          'targets': [
            {
              'target_name': 'nacl_tests',
              'type': 'none',
            },
          ],
        }" > chrome/test/data/nacl/nacl_test_data.gyp
    fi

    # Make it possible to remove third_party/adobe
    echo > "${srcdir}/flapper_version.h"

    msg "Use python2"
    rm -rf "${srcdir}/python"
    mkdir "${srcdir}/python"
    ln -s /usr/bin/python2 "${srcdir}/python/python"
    export PATH="${srcdir}/python":$PATH
    # Really use Python2
    find . -type f -exec sed -i -r -e 's|/usr/bin/python$|&2|g' -e 's|(/usr/bin/python2)\.4$|\1|g' {} +

#    if [ "${_use_system_ffmpeg}" = 1 ]; then
#        msg "Patch for ffpmeg-git"
#        patch --silent -p0 -E < ../patch_for_ffmpeg-git.patch
#    fi

    if [ "${_use_nacl}" = 1 ]; then
        msg "Prepare NaCl SDK"
        mkdir native_client/toolchain/.tars
        ln -s "${srcdir}/naclsdk_nacl-${_toolchains_rev}.tgz" "native_client/toolchain/.tars/naclsdk_linux_x86.tgz"
        ln -s "${srcdir}/naclsdk_pnacl-${_toolchains_rev}.tgz" "native_client/toolchain/.tars/naclsdk_pnacl_linux_x86.tgz"
        ln -s "${srcdir}/naclsdk_toolchain-${_toolchains_rev}.tar.bz2" "native_client/toolchain/.tars/toolchain_linux_x86.tar.bz2"
        patch --silent -p0 -E -i "${srcdir}/chromium-ppapi-r0.patch"
    fi

    #######################
    ## -- Let's build -- ##
    #######################
    msg "Building Chromium..."
    [ "${CARCH}" = "i686" ] && _chromium_arch='ia32'
    [ "${CARCH}" = "x86_64" ] && _chromium_arch='x64'

    # CFLAGS are passed through release_extra_cflags below
    export -n CFLAGS CXXFLAGS
    # Silence "identifier 'nullptr' is a keyword in C++11" warnings (but make others in C :/ )
    CFLAGS+=' -Wno-c++0x-compat'

    # TODO
    # use_system_ssl=1 (http://crbug.com/58087)
    # use_system_sqlite=1 (http://crbug.com/22208)
    # use_system_hunspell=1 (upstream changes needed)
    # use_system_ffmpeg=1 (TODO)
    # linux_use_tcmalloc=0 (https://bugs.gentoo.org/show_bug.cgi?id=413637)


    GYP_DEFINES="\
        target_arch="${_chromium_arch}" \
        werror= \
        no_strict_aliasing=1 \
        linux_sandbox_path="/usr/lib/${pkgname}/chromium-sandbox" \
        linux_sandbox_chrome_path="/usr/lib/${pkgname}/chromium" \
        release_extra_cflags=\""${CFLAGS}"\" \
        ffmpeg_branding=Chrome \
        proprietary_codecs=1 \
        use_system_bzip2=1 \
        use_system_flac=1 \
        use_system_icu=1 \
        use_system_libevent=1 \
        use_system_libexpat=1 \
        use_system_libjpeg=1 \
        use_system_libpng=1 \
        use_system_libusb=1
        use_system_libwebp=1 \
        use_system_libxml=1 \
        use_system_libxslt=1 \
        use_system_minizip=1 \
        use_system_hunspell=0 \
        use_system_libsrtpd=0 \
        use_system_opus=0 \
        use_system_speex=1 \
        use_system_sqlite=0 \
        use_system_ssl=0 \
        use_system_v8=0 \
        use_system_libvpx=1 \
        use_system_xdg_utils=1 \
        use_system_yasm=1 \
        use_system_zlib=1 \
        use_gconf="${_use_gnome}" \
        use_gnome_keyring="${_use_gnome}" \
        use_pulseaudio="${_use_pulseaudio}" \
        linux_link_gnome_keyring="${_use_gnome}" \
        linux_strip_binary=1 \
        remove_webcore_debug_symbols=1 \
        linux_use_gold_binary=0 \
        linux_use_gold_flags=0 \
        linux_use_tcmalloc=0 \
        linux_link_gsettings=1 \
        flapper_version_h_file="${srcdir}/flapper_version.h" \
        disable_sse2=1 \
    "
    [ "${_use_nacl}" = "0" ] && GYP_DEFINES+="disable_nacl=1 "

    if [ "${_use_clang}" = "1" ]; then
        GYP_DEFINES+="clang=1 clang_use_chrome_plugins=1 "
    else
        GYP_DEFINES+="gcc_version=47 "
    fi
#    if [ "${_use_system_ffmpeg}" = "1" ]; then
#        GYP_DEFINES+="use_system_ffmpeg=1 build_ffmpegsumo=0 "
#    else
        GYP_DEFINES+="build_ffmpegsumo=1 "
#    fi

    export GYP_DEFINES

    msg2 "Building build project..."
    build/gyp_chromium -f make --depth=. build/all.gyp

    make BUILDTYPE=Release chrome chrome_sandbox chromedriver
}

package() {
    cd "${srcdir}/chromium-build"

    _chromium_home="${pkgdir}/usr/lib/${pkgname}"

    install -d "${_chromium_home}"
    install -d "${pkgdir}/etc/chromium-dev"

    msg "Packaging ${pkgname}"
    install -Dm755 out/Release/chrome "${_chromium_home}/chromium"
    install -Dm4755 -o root -g root out/Release/chrome_sandbox "${_chromium_home}/chromium-sandbox"
    install -Dm755 out/Release/chromedriver "${_chromium_home}/chromiumdriver"
    install -Dm644 out/Release/{chrome,chrome_100_percent,chrome_remote_desktop,content_resources,resources}.pak "${_chromium_home}/"

    cp -a out/Release/locales "${_chromium_home}"/

    install -Dm644 out/Release/chrome.1 "${pkgdir}/usr/share/man/man1/${pkgname}.1"

    install -Dm644 "${srcdir}/${pkgname}.desktop" "${pkgdir}/usr/share/applications/${pkgname}.desktop"

    for _size in 16 22 24 32 48 128 256; do
        case ${_size} in
            16|32) branding="chrome/app/theme/default_100_percent/chromium" ;;
            *) branding="chrome/app/theme/chromium" ;;
        esac
        install -Dm644 "${branding}/product_logo_${_size}.png" "${pkgdir}/usr/share/icons/hicolor/${_size}x${_size}/apps/${pkgname}.png"
    done

    install -Dm755 "${srcdir}/${pkgname}.sh" "${pkgdir}/usr/bin/${pkgname}"

    install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
    install -Dm644 "${srcdir}/default" "${pkgdir}/etc/chromium-dev/default"

#    if [ "${_use_system_ffmpeg}" = "1" ]; then
#        msg2 "Adding FFMPEG libs"
#        for _n in avcodec avdevice avfilter avformat avutil postproc swscale; do
#            if [ -e /usr/lib/lib"${_n}".so.[0-9] ]; then
#                _f=`echo /usr/lib/lib"${_n}".so.[0-9]`
#            else
#                _f=`echo /usr/lib/lib"${_n}".so.[0-9][0-9]`
#            fi
#            _f=`basename "${_f}"`
#            ln -s ../"${_f}" "${_chromium_home}"/"${_f}"
#            done
#    else
        install -Dm775 out/Release/libffmpegsumo.so "${_chromium_home}/"
#    fi

    # Install NaCL components
    if [ "${_use_nacl}" = 1 ]; then
        msg2 "Adding NaCl components"
        install -Dm755 out/Release/libppGoogleNaClPluginChrome.so "${_chromium_home}/libppGoogleNaClPluginChrome.so"
        [ "${CARCH}" = "i686" ] && install -Dm755 out/Release/nacl_irt_x86_32.nexe "${_chromium_home}/nacl_irt_x86_32.nexe"
        [ "${CARCH}" = "x86_64" ] && install -Dm755 out/Release/nacl_irt_x86_64.nexe "${_chromium_home}/nacl_irt_x86_64.nexe"
        install -Dm755 out/Release/nacl_helper{,_bootstrap} "${_chromium_home}"/
    fi

    # Extract and install PepperFlash and libpdf.so
    if [ "${_use_pepperflash}" = "1" ]; then
        msg2 "Adding PepperFlash"
        cd "${srcdir}"
        bsdtar -xf "google-chrome-unstable-${pkgver}-${_rpm_build}.${_rpm_arch}.rpm" opt/google/chrome/PepperFlash
        install -dm755 "${_chromium_home}/PepperFlash"
        for i in "${srcdir}/opt/google/chrome/PepperFlash/"*; do install -m644 "$i" "${_chromium_home}/PepperFlash"; done
        chmod 775 "${_chromium_home}/PepperFlash/libpepflashplayer.so"
        _flash_ver="$(cat "${_chromium_home}/PepperFlash/manifest.json" | grep version | sed 's|[a-z,": ]*||g')"
        sed -e "s|use_pepperflash=0|use_pepperflash=1|" -e "s|version=0|version=${_flash_ver}|" -i "${_before_srcdir}/${pkgname}.install"
        rm -fr "${srcdir}/opt"
    fi

    if [ "${_use_libpdf}" = "1" ]; then
        msg2 "Adding libpdf"
        cd "${srcdir}"
        bsdtar -xf "google-chrome-unstable-${pkgver}-${_rpm_build}.${_rpm_arch}.rpm" opt/google/chrome/libpdf.so
        install -m755 "${srcdir}/opt/google/chrome/libpdf.so" "${_chromium_home}/libpdf.so"
        rm -rf "${srcdir}/opt"
    fi
}