aboutsummaryrefslogtreecommitdiffstats
path: root/main/lua-sql/APKBUILD
blob: 2b6a7d8d54e6f6a8e5aeb993f9c1dfa40d290a64 (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
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_luaversions="5.1 5.2 5.3"
_drivers="mysql postgres sqlite3 odbc"

pkgname=lua-sql
_pkgname=luasql
pkgver=2.3.5
pkgrel=1
pkgdesc="Lua SQL drivers"
url="http://keplerproject.github.io/luasql/doc/us/"
arch="all"
license="MIT"
makedepends="mariadb-dev postgresql-dev sqlite-dev unixodbc-dev"
subpackages=""
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	for _d in $_drivers; do
		subpackages="$subpackages lua$_v-sql-$_d:_subpackage"
	done
done
for _d in $_drivers; do
	subpackages="$subpackages lua-sql-$_d:_meta_subpackage"
done

source="$_pkgname-$pkgver.tar.gz::https://github.com/keplerproject/$_pkgname/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

prepare() {
	default_prepare || return 1

	cd "$builddir"

	# The config has DRIVER_INCS but it seems like its not respected
	# so we just fix the .c file.
	sed -i 's:^\#include "mysql.h":\#include <mysql/mysql.h>:' \
		src/ls_mysql.c || return 1

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver" || return 1
	done
}

build() {
	local cflags lver

	for lver in $_luaversions; do
		cflags="$CFLAGS $(pkg-config lua$lver --cflags) -fPIC"

		msg "Building for Lua $lver..."
		cd "$builddir-$lver"

		make CFLAGS="$cflags" DRIVER_LIBS="-lmysqlclient" \
			mysql || return 1

		make CFLAGS="$cflags" DRIVER_LIBS="$(pkg-config --libs libpq)" \
			postgres || return 1

		make CFLAGS="$cflags" DRIVER_LIBS="$(pkg-config --libs sqlite3)" \
			sqlite3 || return 1

		make CFLAGS="$cflags -DUNIXODBC" DRIVER_LIBS="-lodbc" \
			odbc || return 1
	done
}

package() {
	mkdir -p "$pkgdir"
}

_meta_subpackage() {
	local driver="${subpkgname##*-}"
	pkgdesc="$pkgdesc for $driver"

	mkdir -p "$subpkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	local driver="${subpkgname##*-}"
	pkgdesc="Lua $lver SQL driver for $driver"
	depends="lua$lver"
	install_if="lua-sql-$driver=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$pkgver-1"

	cd "$builddir-$lver"
	local install_cmod="$(pkg-config --variable INSTALL_CMOD lua$lver)"
	install -D src/$driver.so \
		"$subpkgdir"/$install_cmod/luasql/$driver.so

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="28e25998366a2517cdd37933f0f00e0bb4b06bd9b6731209361777d6b755d62d763168dc78177cab5dfeee667deea04ff775912fb148ed145d64cea5407df4e7  luasql-2.3.5.tar.gz"