# 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