summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: e96ee4a184dbeebbb4ea853832342f24af019a6b (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Generated by pacgem 0.9.12
_gemname="memoist"
_gembuilder=("install"
             "man"
             "license"
             "fix")
_ruby="/usr/bin/ruby"
_gem="/usr/bin/gem"
pkgname="ruby-memoist"
pkgver="0.16.2"
pkgrel=1
pkgdesc="memoize methods invocation"
arch=("any")
url="https://github.com/matthewrudy/memoist"
license=("MIT")
_licensefile=("LICENSE.md")
groups=("pacgem")
makedepends=("ruby"
             "binutils")
depends=("ruby")
conflicts=()
optdepends=("ruby-bundler: The best way to manage your application's dependencies (Development dependency)"
            "ruby-rake: Rake is a Make-like program implemented in Ruby (Development dependency)"
            "ruby-minitest: minitest provides a complete suite of testing facilities supporting TDD, BDD, mo... (Development dependency)")
source=("https://rubygems.org/gems/$_gemname-$pkgver.gem")
sha256sums=("a52c53a3f25b5875151670b2f3fd44388633486dc0f09f9a7150ead1e3bf3c45")
noextract=("$_gemname-$pkgver.gem")
options=("!emptydirs")

_gem_install() {
  msg 'Installing gem...'

  # Install the gem
  install -d -m755 $_bindir $_gemdir
  $_gem install -N --ignore-dependencies --no-user-install \
                --bindir $_bindir --install-dir $_gemdir "$srcdir/$_gemname-$pkgver.gem"
}

_gem_man() {
  msg 'Installing man pages...'

  # Find man pages and move them to the correct directory
  local mandir="$_gemdir/gems/$_gemname-$pkgver/man"
  if [[ -d $mandir ]]; then
    install -d -m755 $_mandir
    local file
    for file in $(find $mandir -type f -and -name *.[0-9]); do
      local dir=$_mandir/man${file##*.}
      install -d -m755 $dir
      mv $file $dir
    done
    rm -rf $mandir
  fi
}

_gem_license() {
  if [[ "${#_licensefile[@]}" -ne 0 ]]; then
    msg "Installing license $license..."
    install -d -m755 "$pkgdir/usr/share/licenses/$pkgname"
    local file
    for file in ${_licensefile[@]}; do
      ln -s "../../../..$_gemdestdir/gems/$_gemname-$pkgver/$file" "$pkgdir/usr/share/licenses/$pkgname/$(basename $file)" || true
    done
  fi
}

_gem_fix() {
  msg 'Fixing gem installation...'

  # Set mode of executables to 755
  [[ -d "$_gemdir/bin" ]] && find "$_gemdir/bin" -type f -exec chmod 755 -- '{}' ';'

  # Remove cached gem file
  rm -f "$_gemdir/cache/$_gemname-$pkgver.gem"

  # Sometimes there are files which are not world readable. Fix this.
  find $pkgdir -type f '!' -perm '-004' -exec chmod o+r -- '{}' ';'
}

_gem_cleanext() {
  msg 'Removing native build leftovers...'
  local extdir="$_gemdir/gems/$_gemname-$pkgver/ext"
  [[ -d $extdir ]] && find "$extdir" -name '*.o' -exec rm -f -- '{}' ';'
}

# Check if dependency is already satisfied
_dependency_satisfied() {
  local dep=$1 deps="${depends[@]}"
  [[ $(type -t in_array) == 'function' ]] || error "in_array should be provided by makepkg"
  while true; do
    in_array $dep ${deps[@]} && return 0
    local found=0 pkg
    # Warning: This could break easily if the pacman output format changes.
    for pkg in $(LC_ALL=C pacman -Qi ${deps[@]} 2>/dev/null | sed '/Depends On/!d;s/.*: //;s/None\|[<>]=\?[^ ]*\|=[^ ]*//g'); do
      if ! in_array $pkg ${deps[@]}; then
        deps=(${deps[@]} $pkg) && found=1
      fi
    done
    (( $found )) || break
  done
  return 1
}

_gem_autodepends() {
  msg 'Automatic dependency resolution...'

  # Find all referenced shared libraries
  local deps=$(find $pkgdir -type f -name '*.so')
  [[ -n $deps ]] || return 0

  deps=$(readelf -d $deps | sed -n 's/.*Shared library: \[\(.*\)\].*/\1/p' | sort | uniq)

  # Find referenced libraries on the library search path
  local libs=() lib path
  for lib in $deps; do
    for path in /lib /usr/lib; do
      [[ -f "$path/$lib" ]] && libs=(${libs[@]} "$path/$lib")
    done
  done
  (( ${#libs} )) || return 0

  msg2 "Referenced libraries: ${libs[*]}"

  # Find matching packages with pacman -Qo
  # and add them to the depends array
  local pkg
  for pkg in $(pacman -Qqo ${libs[@]}); do
    _dependency_satisfied $pkg || depends=(${depends[@]} $pkg)
  done
  msg2 "Referenced packages: ${depends[*]}"
}

_rbconfig() {
  $_ruby -e "require 'rbconfig'; puts RbConfig::CONFIG['$1']"
}

package() {
  # Directories defined inside build() because if ruby is not installed on the system
  # makepkg will barf when sourcing the PKGBUILD
  _gemdestdir=$($_gem environment gemdir)
  _gemdir=$pkgdir$_gemdestdir
  _bindir=$pkgdir$(_rbconfig bindir)
  _mandir=$pkgdir$(_rbconfig mandir)

  local i
  for i in ${_gembuilder[@]}; do
    _gem_$i
  done
}