summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 46ecd97abe5ccae5de5d0b5140728d9a2fef4b8c (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
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
# Maintainer: Chris Severance aur.severach aATt spamgourmet dott com

# Todo: should we make a udev startup for setserial RS-422 485

# lsmod | grep -Ee '(mxu11x0|ti_usb_3410_5052)'

_opt_DKMS=1           # This can be toggled between installs

set -u
pkgname='moxa-mxu11x0'
pkgver='5.0'
pkgrel='1'
pkgdesc='kernel module driver for Moxa UPort USB serial 1110 1130i 1150i RS-232 422 485'
arch=('i686' 'x86_64')
url='https://www.moxa.com/en/products/industrial-edge-connectivity/usb-to-serial-converters-usb-hubs/usb-to-serial-converters/uport-1000-series'
license=('GPL')
depends=('glibc')
optdepends=('setserial: set RS-422 485 modes')
options=('!strip')
install="${pkgname}-install.sh"
_srcdir='moxa-all'
#source=("https://www.moxa.com/drivers/IDC_SW/UPort/Driver/UPort%201100%20Series/Linux/V${pkgver}/legacy/driv_linux_kernel2.x_uport1p_v${pkgver}_build_18050314.tgz")
source=(
  "https://www.moxa.com/Moxa/media/PDIM/S100000385/moxa-uport-1000-series-linux-kernel-5.0-for-uport-11x0-series-driver-v${pkgver}.zip"
  'https://www.moxa.com/Moxa/media/PDIM/S100000385/moxa-uport-1000-series-linux-kernel-4.0-for-uport-11x0-series-driver-v4.0.zip'
  'https://www.moxa.com/Moxa/media/PDIM/S100000385/moxa-uport-1000-series-linux-kernel-3.0-for-uport-11x0-series-driver-v3.0.zip'
)
noextract=("${source[@]##*/}")
md5sums=('e38bb66d6b830c490a90ce9c549d6124'
         '611e04ddfc0432a98776368ff899c0b6'
         'e1ae31fdac579083afe96051cd9ceaa6')
sha256sums=('e4fd3cd953c98017691daf51e25cad4f311877aa498531efff0075fbdd9819df'
            '809f5d1a3e75498727ecf4a0925483672b0e8c7f3583c4839e84dcbc8cc0b935'
            'da510884b6ea2a6c72a822d84bc7faea85908ad5736ea18f4bafdd2f7e22e761')

if [ "${_opt_DKMS}" -ne 0 ]; then
  depends+=('linux' 'dkms' 'linux-headers')
else
  makedepends+=('linux-headers')
fi

_modulename="${pkgname#*-}"
_builtinmod='ti_usb_3410_5052'

declare -gA _folders
_setfolders() {
  local _src _dst
  for _src in "${source[@]##*/}"; do
    if [[ "${_src}" =~ 'driver-v'([0-9]+)'.' ]]; then
      _dst="moxa-${BASH_REMATCH[1]}"
      _folders["${_src}"]="${_dst}"
    else
      echo "Unable to identify version in ${_src}"
      set +u
      false
    fi
  done
}
_setfolders

# We can't modify .install but we can stop and force the user to fix it.
_install_check() {
  local _ckvar
  local _ckline
  local _pkgname="${pkgname}"
  for _ckvar in '_pkgname' '_modulename' '_builtinmod'; do
    _ckline="${_ckvar}='${!_ckvar}'"
    if ! grep -qe "^${_ckline}"'$' "${startdir}/${install}"; then
      set +u
      msg "${install} must be fixed"
      echo "${_ckline}"
      false
    fi
  done
}

_multipatch() {
  # Remove MACOS files
  rm -r '__MACOSX'
  rm -f 'readme.txt'

  cd 'source'

  # Scorched Earth, all new Makefile now that the build system is totally broken for any distro with more than one kernel version.
  rm '.DS_Store' 'Makefile' 'mxinstall'
  rm -f 'readme.txt'

  cd 'driver'
  rm 'Makefile' 'mxconf' 'ver.mk'
}

prepare() {
  set -u

  mkdir "${_srcdir}"
  local _src _dst
  for _src in "${!_folders[@]}"; do
    _dst="${_folders[${_src}]}"
    mkdir "${_dst}"
    set +u; msg2 "Extracting ${_src} with bsdtar"; set -u
    bsdtar -x -C "${_dst}" -f "${_src}"
    pushd "${_dst}" > /dev/null
    _multipatch
    popd > /dev/null
    mv "${_dst}/source/driver" "${_srcdir}/${_dst}"
    rmdir "${_dst}/source" "${_dst}"
  done

  _install_check

  cd "${_srcdir}"

  echo > 'Makefile' "
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/"'

KVER   := $(shell uname -r)
KDIR   := /usr/lib/modules/$(KVER)/build
KMAJOR := moxa-$(shell cut -d. -f1 <<<"$(KVER)")
PWD    := $(shell pwd)
TARGET := mxu11x0

all: module

ifneq ($(SUBDIRS),)
obj-m := $(KMAJOR)/$(TARGET).o
else
module:
	$(MAKE) -s -C $(KDIR) M=$(PWD) SUBDIRS=$(PWD) modules
	cp -p $(KMAJOR)/$(TARGET).ko .
endif

clean:
	$(MAKE) -s -C $(KDIR) M=$(PWD) SUBDIRS=$(PWD) clean

install:
	install -Dp $(TARGET).ko -t $(DESTDIR)$(KDIR)/../kernel/drivers/usb/serial/
'

  set +u
}

build() {
  set -u
  cd "${_srcdir}"
  make -j1 # too small for parallel make
  set +u
}

package() {
  set -u
  cd "${_srcdir}"

  if [ "${_opt_DKMS}" -eq 0 ]; then
    # I don't want Linux version info showing on AUR web. After a few months 'linux<0.0.0' makes it look like an out of date package.
    local _kernelversionsmall="$(uname -r)"
    _kernelversionsmall="${_kernelversionsmall%%-*}"
    _kernelversionsmall="${_kernelversionsmall%\.0}" # trim 4.0.0 -> 4.0, 4.1.0 -> 4.1
    # prevent the mksrcinfo bash emulator from getting these vars!
    #eval 'conf''licts=("linux>${_kernelversionsmall}" "linux<${_kernelversionsmall}")'
    eval 'dep''ends+=("linux=${_kernelversionsmall}")'
  fi

  make -j1 DESTDIR="${pkgdir}" install

  # The module is in the same folder as DKMS. Compress to a different name to prevent conflict.
  # When future versions of DKMS compress we'll stop doing this.
  find "${pkgdir}/usr/lib/modules/" -type 'f' -name '*.ko' -exec 'gzip' '-9' '{}' ';'

  # Blacklist built in module
  set +u; msg2 'Blacklist built in module'; set -u
  install -Dm644 <(cat << EOF
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/

# This will kill other TI devices like some Multitech MT9234ZBA-USB 93537152LF
#blacklist ${_builtinmod}

# Override alias list in ti_usb_3410_5052
# Moxa 1110 1130 1150 1151 1131
alias usb:v110Ap1151d*dc*dsc*dp*ic*isc*ip*in* mxu11x0
alias usb:v110Ap1150d*dc*dsc*dp*ic*isc*ip*in* mxu11x0
alias usb:v110Ap1131d*dc*dsc*dp*ic*isc*ip*in* mxu11x0
alias usb:v110Ap1130d*dc*dsc*dp*ic*isc*ip*in* mxu11x0
alias usb:v110Ap1110d*dc*dsc*dp*ic*isc*ip*in* mxu11x0
# This prefers the Moxa driver over the TI driver for boot and hotplug
softdep ${_builtinmod} pre: ${_modulename}
EOF
  ) "${pkgdir}/usr/lib/modprobe.d/${pkgname}.conf"

  if [ "${_opt_DKMS}" -ne 0 ]; then
    set +u; msg2 'Installing DKMS files'; set -u
    rm -r "${pkgdir}/usr/lib/modules/"
    local _dkms="${pkgdir}/usr/src/${pkgname}-${pkgver}"
    install -Dm644 <(cat << EOF
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/

PACKAGE_NAME="${pkgname}"
PACKAGE_VERSION="${pkgver}"
AUTOINSTALL="yes"

BUILT_MODULE_NAME[0]="${_modulename}"
#BUILT_MODULE_LOCATION[0]=""
# Using all processors doesn't compile this tiny module any faster.
MAKE[0]="make -j1"
CLEAN[0]="make -j1 clean"
# The install version is .ko.gz. The DKMS version is .ko. No conflicts.
DEST_MODULE_LOCATION[0]="/kernel/drivers/usb/serial"
EOF
    ) "${_dkms}/dkms.conf"
    cp -pr './' "${_dkms}/"
    sed -e '# No DKMS instructions say to do this but it works and keeps the MAKE line real simple' \
        -e 's:shell uname -r:KERNELRELEASE:g' \
      -i "${_dkms}/Makefile"
    make -s -C "${_dkms}/" clean KERNELRELEASE="$(uname -r)"
  fi
  set +u
}

set +u