-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_sqlite3-ruby
More file actions
executable file
·141 lines (123 loc) · 3.92 KB
/
build_sqlite3-ruby
File metadata and controls
executable file
·141 lines (123 loc) · 3.92 KB
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
#!/bin/bash
# ADD ./build-sqlite3-ruby /build-sqlite3-ruby
# docker run -v /root/linux:/build sqlite3-ruby-build:i386 /build-sqlite3-ruby i386 /build
ARCH=$1
INSTALL=$2
SQLITE3_DIR=
######################################################################
## Download SQLite amalgamation archive (zip)
######################################################################
build_sqlite() {
local gcc="gcc"
local ar="ar"
# MinGW envirnoment
if [ $ARCH = "i386-mingw32" ]; then
# x86 (win32)
gcc="i686-w64-mingw32-gcc"
ar="i686-w64-mingw32-ar"
fi
if [ $ARCH = "x64-mingw32" ]; then
# x86_64 (win32)
gcc="x86_64-w64-mingw32-gcc"
ar="x86_64-w64-mingw32-ar"
fi
local sqlite3_rel=$(curl -s 'http://www.sqlite.org/download.html' | \
grep -o '[0-9]*/sqlite-amalgamation-3[0-9]*.zip' | head -n 1)
curl -sO "http://www.sqlite.org/$sqlite3_rel"
unzip -q $(basename $sqlite3_rel)
SQLITE3_DIR=$PWD/$(basename ${sqlite3_rel%.zip})
pushd $SQLITE3_DIR
$gcc $CFLAGS \
-fPIC -Wall -O2 -DSQLITE_ENABLE_COLUMN_METADATA \
-c sqlite3.c -o sqlite3.o $LDFLAGS && \
$ar rv sqlite3.a sqlite3.o
popd
}
######################################################################
## Bulid sqlite3-ruby extension
######################################################################
mingw_rakefile() {
local extoption="$1"
local rbver="$2"
local extarch=""
local rakebin=""
if [ $ARCH = "i386-mingw32" -o $ARCH = "x64-mingw32" ]; then
extarch=$ARCH
fi
if [ $ARCH = "i386-mingw32" ]; then
rakebin=i686-w64-mingw32/ruby-$rbver*
elif [ $ARCH = "x64-mingw32" ]; then
rakebin=x86_64-w64-mingw32/ruby-$rbver*
fi
# Exist check
if [ ! -d $HOME/.rake-compiler/builds/$rakebin ]; then
return 1
fi
cat << _EOT_ > Rakefile
# coding: utf-8
require "rake/extensiontask"
Rake::ExtensionTask.new do |e|
e.cross_compile = true
e.cross_platform = "$extarch"
e.cross_config_options << "$extoption"
e.name = "sqlite3_native"
e.ext_dir = "./"
e.lib_dir = "./"
e.tmp_dir = "./"
end
_EOT_
return 0
}
build_sqlite_ruby() {
local path="$1"
local dest="$2"
local gccstrip="strip"
local gccoption="--enable-local --enable-static --with-sqlite3-include=$SQLITE3_DIR"
local rbver=`PATH="$path" ruby -e 'puts RUBY_VERSION'`
# MinGW envirnoment (use rake-compiler gem)
if [ $ARCH = "i386-mingw32" ]; then
# x86 (win32)
gccstrip="i686-w64-mingw32-strip"
elif [ $ARCH = "x86-mingw32" ]; then
# x86_64 (win32)
gccstrip="x86_64-w64-mingw32-strip"
fi
if [ -f Makefile ]; then
make clean
fi
if [ $ARCH = "i386-mingw32" -o $ARCH = "x64-mingw32" ]; then
mingw_rakefile "$gccoption" $rbver
if [ $? -ne 0 ]; then
echo Skip compile: $ARCH $rbver
return 1
fi
PATH="$path" rake cross clean && \
PATH="$path" LDFLAGS="$LDFLAGS -static-libgcc $SQLITE3_DIR/sqlite3.a" \
rake cross compile
else
PATH="$path" LDFLAGS="$LDFLAGS $SQLITE3_DIR/sqlite3.a" \
ruby extconf.rb $gccoption && \
make clean && \
make
fi
$gccstrip ./sqlite3_native.so && \
mkdir -p $dest && \
cp -p ./sqlite3_native.so $dest/sqlite3_native.so
return 0
}
if [ ! -d $INSTALL ]; then
mkdir -p $INSTALL
fi
pushd /tmp
master=sqlite3-ruby
branch=1.8.5-support
build_sqlite
curl -ksOL https://github.com/sh4/sqlite3-ruby/archive/${branch}.zip
unzip -q ${branch}.zip
pushd ${master}-$branch/ext/sqlite3
build_sqlite_ruby "/ruby-1.8/bin:$PATH" "${INSTALL}/1.8/${ARCH}"
build_sqlite_ruby "/ruby-1.9/bin:$PATH" "${INSTALL}/1.9/${ARCH}"
build_sqlite_ruby "/ruby-2.0/bin:$PATH" "${INSTALL}/2.0/${ARCH}"
build_sqlite_ruby "/ruby-2.1/bin:$PATH" "${INSTALL}/2.1/${ARCH}"
popd
popd