summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 0a883950d1a7d105fc7257aa888f2a778dc508c9 (plain)
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
# Maintainer: Felix Kauselmann <licorn@gmail.com>

pkgname=libpdfium-nojs
pkgver=4638.r2.839d18189f
pkgrel=1
pkgdesc="Open-source PDF rendering engine."
arch=('x86_64')
url="https://pdfium.googlesource.com/pdfium/"
license=('BSD')
depends=('freetype2' 'lcms2' 'libjpeg' 'openjpeg2' 'icu')
conflicts=('libpdfium-bin')
provides=('libpdfium')
makedepends=('git' 'python2' 'gn' 'ninja')

source=("git+https://pdfium.googlesource.com/pdfium"
    "git+https://chromium.googlesource.com/chromium/src/build.git"
    "libpdfium.pc"
    )

md5sums=('SKIP'
    'SKIP'
    'feb270967925a0844b1b9a9e15288eb3'
    )

pkgver() {

  cd $srcdir/pdfium
  
  # Default branch can be either master or main
  local _default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | cut -f4 -d"/")
  
  # Version = branch name/number + number of commits since branch creation
  # + short head
  printf  "%s.r%s.%s" $(git rev-parse --abbrev-ref HEAD | cut -d '/' -f2)\
   $(git rev-list --count $_default_branch..) $(git rev-parse --short HEAD)

}

prepare() {

  cd "$srcdir/pdfium"

  ln -sf $srcdir/build build

  # Pdfium is developed alongside Chromium and does not provide releases
  # Upstream recommends using Chromium's dev channels instead

  # Extract pdfium branch name used in stable channel from omahaproxy and do
  # a checkout
  git checkout "chromium/$(curl https://omahaproxy.appspot.com/linux?channel=stable | cut -d'.' -f 3)"

  # git checkout "chromium/$(curl https://omahaproxy.appspot.com/linux?channel=beta | cut -d'.' -f 3)"
  # git checkout "chromium/$(curl https://omahaproxy.appspot.com/linux?channel=dev | cut -d'.' -f 3)"

  # Fix missing string headers for GCC + libstdcc compilation, but only for affected version
  if [ `git rev-parse --abbrev-ref HEAD` == 'chromium/4577' ]
  then
      git cherry-pick -n 7a6289c
  fi

  # Extract build repo revision needed from DEPS file and do a checkout
  cd "$srcdir/pdfium/build"
  git checkout $(awk '/build_revision/ {print substr($2,2,40)}' $srcdir/pdfium/DEPS) -q
  
  # Use system provided icu library (unbundling)
  mkdir -p "$srcdir/pdfium/third_party/icu"
  ln -sf "$srcdir/build/linux/unbundle/icu.gn" "$srcdir/pdfium/third_party/icu/BUILD.gn"

  # Download and decode shim header script needed to unbundle icu (gittiles is weird)
  mkdir -p "$srcdir/pdfium/tools/generate_shim_headers/"
  echo "Downloading generate_shim_headers script from Chromium."
  curl https://chromium.googlesource.com/chromium/src/+/master/tools/generate_shim_headers/generate_shim_headers.py?format=TEXT \
    | base64 --decode > "$srcdir/pdfium/tools/generate_shim_headers/generate_shim_headers.py"
  echo "Done."
  
  # Create fake gclient_args.gni file to satisfy include list for build/config/compiler/compiler.gni
  touch "$srcdir/build/config/gclient_args.gni"
  
} 

build() {

  cd "$srcdir/pdfium"

  local _flags=(
      'is_clang=false'
      'use_sysroot=false'
      'is_debug=false'
      'symbol_level=0'
      'pdf_enable_v8=false'
      'pdf_enable_xfa=false'
      'treat_warnings_as_errors=false'
      'use_system_libjpeg=true'
      'use_system_zlib=true'
      'pdf_bundle_freetype=false'
      'use_system_freetype=true'
      'use_system_lcms2=true'
      'use_system_libpng=true'
      'use_custom_libcxx=false'
      'pdf_is_standalone = true'
      'use_system_libopenjpeg2 = true'
      'is_component_build = true'
      'use_gold = false' 
  )
  
  gn gen out/Release --script-executable=/usr/bin/python2 --args="${_flags[*]}"
  ninja -C out/Release pdfium

  # set pdfium version in pc file
  sed "s/@VERSION@/${pkgver}/g" -i "${srcdir}/libpdfium.pc"

}

package() {

  cd "$srcdir/pdfium"

  install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -D public/*.h --target-directory="${pkgdir}/usr/include/pdfium"
  install -D public/cpp/* --target-directory="${pkgdir}/usr/include/pdfium/cpp"
  install -D docs/* --target-directory="${pkgdir}/usr/share/doc/pdfium"
  install -Dm755 out/Release/libpdfium.so --target-directory="${pkgdir}/usr/lib"
  install -Dm644 ${srcdir}/libpdfium.pc --target-directory=${pkgdir}/usr/lib/pkgconfig

}