summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 03a06355d740795612a0eb49f59c29e7aada8e25 (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
# 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='1.4'
pkgrel='2'
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/support/support_home.aspx'
license=('GPL')
depends=('glibc')
optdepends=('setserial: set RS-422 485 modes')
options=('!strip')
install="${pkgname}-install.sh"
_srcdir="${pkgname#*-}"
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")
sha256sums=('b9878842c3cd05f66647b584e10ed0689f7614b2b37ac31ba9c4da87d0bcba19')

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

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

# 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 -q "^${_ckline}"'$' "${startdir}/${install}"; then
      set +u
      msg "${install} must be fixed"
      echo "${_ckline}"
      false
    fi
  done
}

prepare() {
  set -u
  _install_check
  cd "${_srcdir}"

  # Fix /lib
  sed -e 's:/lib/:/usr/lib/:g' -i driver/*/Makefile driver/*/mxconf

  # Fix umbrella Makefile
  sed -e '# Disable silent' \
      -e '/make / s:\s\+-s::g' \
      -e '# Disable kernel 2.4 detection' \
      -e '/^KERNEL_VERSION_MAJOR_NUMBER/,/^$/ s:^.:#&:g' \
      -e '# Improve chdir technique' \
      -e 's:^\t@cd .*$:#&-:g' \
      -e 's:^\tmake:\t@make -C $(DRIVER_PATH):g' \
    -i 'Makefile'

  # Fix driver Makefile
  sed -e '# CentOS option is only for Kernel 3.10, its easier to redo blackisting than to fix it' \
      -e '/^TI_3410/,/^BLACKLIST_LINE/ s:^.:#&:g' \
      -e '# Ungroup make targets' \
      -e '/^module:/ s: envchk::g' \
      -e '/^install:/ s: module::g' \
      -e '# Extra file in gcc8' \
      -e 's/^clean_local:.*$/&\n\t@rm -f .cache.mk/g' \
      -e '# Make package compatible' \
      -e '/^install:/,/^$/ s:/usr:$(DESTDIR)&:g' \
      -e '# Fix install by removing every line' \
      -e '/^install:/,/^$/ s:^\t:#&:g' \
      -e '# Put back the lines we want' \
      -e '\:kernel/drivers/usb/serial: s:^#::g' \
      -e '# Fedora detection isnt used anywhere' \
      -e 's:^KDISVER:#&:g' \
      -e '/fc6/,/^$/ s:^.:#&:g' \
      -e '# Cut the noise' \
      -e '/^module:/,/^$/ s:\t@echo:#&:g' \
      -e 's:^DRV_VER:#&:g' \
      -e 's:^REL_DATE:#&:g' \
      -e '# Change to kernel built in make clean' \
      -e 's/^clean:/clean_orig:/g' \
      -e 's/^clean_orig:/clean:\n\t@$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean\n\n&/g' \
    -i 'driver/kernel2.6/Makefile'

  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
  install -Dm644 <(cat << EOF
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/

# This will kill other ti devices
#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
    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]="driver/kernel2.6"
# Using all processors doesn't compile this tiny module any faster.
MAKE[0]="make -j1 -C 'driver/kernel2.6'"
CLEAN[0]="make -j1 -C 'driver/kernel2.6' 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 'driver/' "${_dkms}/"
    rm -r "${_dkms}/driver/kernel2.4"
    rm "${_dkms}/driver/kernel2.6/mxconf"
    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' \
        -e '# DKMS sets KERNELRELEASE which accidentally launches phase 2 of this Makefile' \
        -e '# Fix by changing the detection var.' \
        -e '# SUBDIRS makes more sense to me because I can see it in the Makefile!' \
        -e 's:ifneq ($(KERNELRELEASE),):ifneq ($(SUBDIRS),):g' \
      -i "${_dkms}/driver/kernel2.6/Makefile"
    make -s -C "${_dkms}/driver/kernel2.6/" clean KERNELRELEASE="$(uname -r)"
  fi
  set +u
}

set +u