summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 7e155b9b6eca40db9f8951b96f87093058b7f423 (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
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
# Contributor && Maintarner: Swift Geek <swiftgeek ɐt gmail døt com>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: hokasch <hokasch at operamail dot com>
# Contributor: Dennis Brendel <buddabrod at gmail dot com>
# Contributor: Mathias Buren <mathias.buren at gmail dot com>
# Contributor: Benjamin Mtz (Cruznick) <cruznick at archlinux dot us>
# Contributor: t3kk3n <corp at hush dot ai>

#TODO: Investigate empty dir - /usr/lib/modules/3.12.9-2-ARCH/
#TODO: Document and finish automation for patching and config
#TODO: Add config (from makepkg.d only) for downloading most recent snapshot (include logic in pkgver() function)

_runkernver=$(uname -r)
_shortkernver=${_runkernver%.*}
_kernelname=${_runkernver##*-}

pkgname=backports-patched
pkgver=4.4.2_1
_upver="${pkgver//_/-}"
pkgrel=7
pkgdesc='Backports provides drivers released on newer kernels backported for usage on older kernels. Patched flavor'
url='https://backports.wiki.kernel.org/index.php/Main_Page'
arch=('i686' 'x86_64')
license=('GPL')
depends=('linux')

# Assocative array for different forks like linux-ck, linux-grsec
declare -A linfork
linfork["ARCH"]=''
linfork["grsec"]='-grsec'
linfork["ck"]='-ck'
makedepends=('linux-api-headers' "linux-headers${linfork[${_kernelname}]}>=$_shortkernver")

optdepends=('backports-frag+ack: wl-frag+ack patch')
install=backports.install
# Stable and rc? TODO: Check with rc :D | Double %% cuts to the first, single % cuts to the last
source=("http://www.kernel.org/pub/linux/kernel/projects/backports/stable/v${_upver%-*}/backports-${_upver}.tar.xz")
# Snapshot:
#source=("http://www.kernel.org/pub/linux/kernel/projects/backports/${pkgver:0:4}/${pkgver:4:2}/${pkgver:6:2}/backports-${pkgver}.tar.xz")
sha256sums=('a979e194c2ed9fdfca092a448e626d85c5af0e4de5ad993c0967afd15af01285')

# Check for daily pkgver eg. 20370718
date -d "$pkgver" > /dev/null 2>&1
if [[ $? == 0 ]]; then
  source=("http://www.kernel.org/pub/linux/kernel/projects/backports/${pkgver:0:4}/${pkgver:4:2}/${pkgver:6:2}/backports-${pkgver}.tar.xz")
  warning "Skipping checksum check for snapshots"
fi

_extramodules=extramodules-${_shortkernver}-${_kernelname}
_kernver=$(cat /usr/lib/modules/${_extramodules}/version) # TODO make this a lower boundary and utilize in reality pacman to get freshest paths. Or make it for specific kernels. Or multiply it over specific kernels ? :3

_cfgdir="/etc/makepkg.d/${pkgname}/"
_patchdir="${_cfgdir}/patches/"

countdown() {
  local i
  for ((i=$1; i>=1; i--)); do
    [[ ! -e /proc/$$ ]] && exit
    echo -ne "\rPress [i] to start interactive config in $i second(s) "
    sleep 1
  done
}

prepare() {
  cd "${srcdir}/backports-${_upver}"
  # modprobe -l dropped in kmod
  sed 's:modprobe -l \([^ )`]*\):find /usr/lib/modules/*/kernel -name "\1.ko*" | sed "s|.*/kernel||":' -i scripts/*
  sed 's:\$(MODPROBE) -l \([^ )`]*\):find /usr/lib/modules/*/kernel -name "\1.ko*" | sed "s|.*/kernel||":' -i Makefile

  # rfkill.h does not use compat-3.1.h # TODO : IS THIS RLY NEEDED ?
  #echo '#define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT)' >> net/wireless/core.h

  # Patch time!
  # WARNING - PART BELOW IS UNTESTED: current format - 00-name for cfgfile (to export variables) and 12-3-name for patches (3 stands for -p3)
  if [ -d "${_cfgdir}" ]; then
    _CFGLIST=$(ls -1 "${_cfgdir}" | awk ' /^[0-9][0-9]-.*/ {print "source '${_cfgdir}'"$0";"}')
    eval $_CFGLIST
    unset _CFGLIST
    if [ -d "${_patchdir}" ]; then
      _PATCHLIST=$(ls -1 "${_patchdir}" | awk ' /^[0-9][0-9]-[0-9]-.*/ {print $0}')
      for _patch in $_PATCHLIST; do
        msg "Merging patch: ${_patch}"
        patch -p${_patch:3:1} -i ${_patchdir}/${_patch}
      done
      unset _PATCHLIST
    fi
  fi

  # Patch for sane install
cd "${srcdir}/backports-${_upver}"
patch -p0 <<'EOF'
--- Makefile.real	2013-07-13 18:50:46.000000000 +0200
+++ Makefile.real.fixed	2013-07-28 01:52:51.922779881 +0200
@@ -87,14 +87,6 @@
 	@$(MAKE) -C $(KLIB_BUILD) M=$(BACKPORT_PWD)			\
 		INSTALL_MOD_DIR=$(KMODDIR) $(KMODPATH_ARG)		\
 		modules_install
-	@./scripts/blacklist.sh $(KLIB)/ $(KLIB)/$(KMODDIR)
-	@./scripts/compress_modules.sh $(KLIB)/$(KMODDIR)
-	@./scripts/check_depmod.sh
-	@/sbin/depmod -a
-	@./scripts/update-initramfs.sh $(KLIB)
-	@echo
-	@echo Your backported driver modules should be installed now.
-	@echo Reboot.
 	@echo
 
 .PHONY: modules_install
EOF

}

build() {
  cd "${srcdir}/backports-${_upver}"
  # unset _selected_drivers # WARNING! DEBUGGING UNSET - MAKE SURE THAT THIS LINE IS COMMENTED
  # Get config - not in prepare beause interactive part is using cc
  if [ -n "${_selected_drivers}" ]; then
    msg "Defconfig(s) detected"
  else # TODO: else if not that try showing up dialog menu with checkboxes based on available defconfigs ;)
    warning "Config undetected"
    # Check for dialog
    if [ ! -e /usr/bin/dialog ]; then
      error "Cannot fallback to interactive config - dialog package not installed"
      false
    fi
    # WAIT 10s FOR INTEACTIVE PART - PRESS I FOR INTERACTIVE CONFIG
    tty -s # Checks if user input is accesssible, otherwise fail
    countdown 10 & countdown_pid=$!
    read -s -n 1 -t 10 ikey || true
    kill -s SIGHUP $countdown_pid
    echo -e -n "\n"
    [[ "$ikey" =~ ^[iI]$ ]] || false
    # BEGIN INTERACTIVE PART TODO: ADD OLDCONFIG OPTION WITH FILE SELECT
    cfgway=$(dialog --keep-tite --backtitle "$pkgname" --no-items --radiolist 'Choose method to configure' 0 0 0 'defconfig' off 'menuconfig' off 2>&1 >/dev/tty)
    msg2 "Chosen to configure with \"${cfgway}\""
    case "$cfgway" in
      defconfig)
        for i in $(ls ./defconfigs/); do
          list_opts+=("$i" "off")
        done
        echo "${list_opts[*]}"
        _selected_drivers=( $(dialog --keep-tite --backtitle "$pkgname" --no-items --checklist 'Choose driver groups to compile' 0 0 0 ${list_opts[*]} 2>&1 >/dev/tty) )
        msg2 "Selected drivers groups: ${_selected_drivers[*]}"
        ;;
      menuconfig)
        make menuconfig
        ;;
      "")
        error "Nothing selected!\nPerhaps You used [enter] instead of [space] to select menu item?"
        false
        ;;
      *)
        echo Break out from the PKGBUILD
        false
        ;;
    esac
    # END OF THE INTERACTIVE PART
  fi

  if [[ -n "$_selected_drivers" ]]; then #THIS means that defconfigs are used! actual config has to be generated here!!
    # Workaround - create slapped together defconfig "user" http://i.imgur.com/axyrOZH.jpg
    (
      cd ./defconfigs/
      warning "Creating slapped together defconfig 'user'"
      cat ${_selected_drivers[*]} | sort -u
      cat ${_selected_drivers[*]} | sort -u > user
    )

    # Temporary disabled until resolved
    # make ${_selected_drivers[*]/#/defconfig-}
    make defconfig-user # Temporary solution

    msg  ${_selected_drivers[*]} «" # CONVERT TO MESSAGE AND ONLY IF VAR IS -n
  fi

  # Actual build
  msg "Starting actual build"
  make KLIB=/usr/lib/modules/"${_kernver}" # should be make modules
}

package() {
  cd "${srcdir}/backports-${_upver}"
  mkdir ${pkgdir}/usr/
  make INSTALL_MOD_PATH="${pkgdir}/usr" KMODDIR=../"${_extramodules}" install
  find "${pkgdir}" -name '*.ko' -exec gzip -9 {} \;

  #install -d "${pkgdir}"/usr/bin
  #install scripts/*{enable,load} "${pkgdir}"/usr/bin

  #install -d "${pkgdir}"/usr/lib/compat-drivers
  #install scripts/modlib.sh "${pkgdir}"/usr/lib/compat-drivers

  # Preparation for future
  install -d "${pkgdir}"/etc/makepkg.d/"${pkgname}"/patches
}