-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild_linux.sh
More file actions
executable file
·204 lines (184 loc) · 6.69 KB
/
build_linux.sh
File metadata and controls
executable file
·204 lines (184 loc) · 6.69 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
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
#!/bin/bash
# build_linux.sh - Build HarbourBuilder IDE for Linux using Harbour + GTK3 + Scintilla
#
# Prerequisites:
# sudo apt install libgtk-3-dev
# Harbour compiler installed (default: ~/harbour)
# Scintilla/Lexilla shared libs in resources/ (see build_scintilla.sh)
#
# Usage: ./build_linux.sh [program]
# ./build_linux.sh - builds hbbuilder_linux (full IDE)
# ./build_linux.sh test_design_gtk - builds test_design_gtk (simple demo)
set -e
HBDIR="${HBDIR:-$HOME/harbour}"
PROJDIR="$(cd "$(dirname "$0")" && pwd)"
PROG="${1:-hbbuilder_linux}"
RESDIR="$PROJDIR/resources"
cd "$PROJDIR/source"
# Check Harbour is installed
if [ ! -d "$HBDIR/include" ]; then
echo "ERROR: Harbour not found at $HBDIR"
echo "Run HbBuilder and press F9 — it will download Harbour automatically."
echo "Or install manually: git clone https://github.com/harbour/core /tmp/harbour-src"
echo " cd /tmp/harbour-src && HB_INSTALL_PREFIX=$HBDIR make install"
exit 1
fi
# Detect Harbour directory layout (bin/linux/gcc/ vs bin/)
if [ -f "$HBDIR/bin/linux/gcc/harbour" ]; then
HBBIN="$HBDIR/bin/linux/gcc"
HBLIB="$HBDIR/lib/linux/gcc"
elif [ -f "$HBDIR/bin/harbour" ]; then
HBBIN="$HBDIR/bin"
HBLIB="$HBDIR/lib"
else
echo "ERROR: Harbour compiler not found in $HBDIR"
echo " Run the IDE first - it will auto-download and build Harbour."
exit 1
fi
HBINC="$HBDIR/include"
echo "Using Harbour: $HBDIR"
echo "Building: $PROG"
echo ""
# Helper: rebuild if any source content changed (sha1-based, mtime-proof).
# Survives git pulls preserving mtime, manual .o copies, clock skew.
# Usage: needs_rebuild <obj> <src1> [<src2> ...]
# Sidecar <obj>.sha stores combined hash of all sources used to build <obj>.
needs_rebuild() {
local obj="$1"; shift
local stamp="${obj}.sha"
[ ! -f "$obj" ] && { sha1sum "$@" | sha1sum | awk '{print $1}' > "$stamp"; return 0; }
local cur
cur="$(sha1sum "$@" | sha1sum | awk '{print $1}')"
if [ ! -f "$stamp" ] || [ "$cur" != "$(cat "$stamp")" ]; then
echo "$cur" > "$stamp"
return 0
fi
return 1
}
NEED_LINK=0
# === Step 0: Build Scintilla/Lexilla .so if not present ===
if [ ! -f "$RESDIR/libscintilla.so" ] || [ ! -f "$RESDIR/liblexilla.so" ]; then
echo "[0/6] Building Scintilla + Lexilla shared libraries..."
if [ -f "$PROJDIR/build_scintilla.sh" ]; then
bash "$PROJDIR/build_scintilla.sh"
else
echo "WARNING: libscintilla.so / liblexilla.so not found in resources/"
echo " The code editor will fall back to system libraries or fail."
echo " Run build_scintilla.sh to build from source, or install system packages."
fi
fi
# [1/6] Harbour -> C (only if .prg changed)
if needs_rebuild "${PROG}.c" \
"${PROG}.prg" \
"$PROJDIR/source/core/classes.prg" \
"$PROJDIR/source/inspector/inspector_gtk.prg" \
"$PROJDIR/include/hbbuilder.ch"; then
echo "[1/6] Compiling ${PROG}.prg..."
"$HBBIN/harbour" ${PROG}.prg -n -w -q \
-I"$HBINC" \
-I"$PROJDIR/include" \
-I"$PROJDIR/source" \
-o${PROG}.c
NEED_LINK=1
else
echo "[1/6] ${PROG}.prg — up to date"
fi
# [2/6] C -> Object (only if .c changed)
if needs_rebuild "${PROG}.o" "${PROG}.c"; then
echo "[2/6] Compiling ${PROG}.c..."
gcc -c -g -Wno-unused-value \
-I"$HBINC" \
$(pkg-config --cflags gtk+-3.0) \
${PROG}.c -o ${PROG}.o
NEED_LINK=1
else
echo "[2/6] ${PROG}.o — up to date"
fi
# Detect WebKit2GTK (try 4.1 first, then 4.0)
WEBKIT_CFLAGS=""
WEBKIT_LIBS=""
WEBKIT_DEFINE=""
if pkg-config --exists webkit2gtk-4.1 2>/dev/null; then
WEBKIT_CFLAGS="$(pkg-config --cflags webkit2gtk-4.1)"
WEBKIT_LIBS="$(pkg-config --libs webkit2gtk-4.1)"
WEBKIT_DEFINE="-DHAVE_WEBKIT2GTK"
echo " WebKit2GTK 4.1 detected — WebView enabled"
elif pkg-config --exists webkit2gtk-4.0 2>/dev/null; then
WEBKIT_CFLAGS="$(pkg-config --cflags webkit2gtk-4.0)"
WEBKIT_LIBS="$(pkg-config --libs webkit2gtk-4.0)"
WEBKIT_DEFINE="-DHAVE_WEBKIT2GTK"
echo " WebKit2GTK 4.0 detected — WebView enabled"
else
echo " WebKit2GTK not found — WebView will show placeholder"
echo " Install with: sudo apt install libwebkit2gtk-4.1-dev"
fi
# [3/6] GTK3 core (only if .c changed)
if needs_rebuild gtk3_core.o "$PROJDIR/source/backends/gtk3/gtk3_core.c"; then
echo "[3/6] Compiling GTK3 core..."
gcc -c -g \
-I"$HBINC" \
$(pkg-config --cflags gtk+-3.0) \
$WEBKIT_CFLAGS $WEBKIT_DEFINE \
"$PROJDIR/source/backends/gtk3/gtk3_core.c" -o gtk3_core.o
NEED_LINK=1
else
echo "[3/6] gtk3_core.o — up to date"
fi
# [4/6] GTK3 inspector (only if .c changed)
if needs_rebuild gtk3_inspector.o "$PROJDIR/source/backends/gtk3/gtk3_inspector.c"; then
echo "[4/6] Compiling GTK3 inspector..."
gcc -c -g \
-I"$HBINC" \
$(pkg-config --cflags gtk+-3.0) \
"$PROJDIR/source/backends/gtk3/gtk3_inspector.c" -o gtk3_inspector.o
NEED_LINK=1
else
echo "[4/6] gtk3_inspector.o — up to date"
fi
# [4b/6] DB bindings via runtime dlopen — no -dev headers needed at build
# time. Mirrors Win hb_db_real.cpp pattern. libmysqlclient.so / libpq.so
# resolved at launch; missing libs return safe defaults.
rm -f hbmysql.o hbpgsql.o hbdb_stub.o
if needs_rebuild hbdb_real.o "$PROJDIR/source/backends/gtk3/gtk3_db_real.c"; then
echo "[4b] Compiling DB bindings (dlopen-based)..."
gcc -c -O2 -I"$HBINC" \
"$PROJDIR/source/backends/gtk3/gtk3_db_real.c" -o hbdb_real.o
NEED_LINK=1
fi
# Skip link if nothing changed
if [ "$NEED_LINK" -eq 0 ] && [ -f "${PROG}" ]; then
echo "[5/6] ${PROG} — up to date (nothing changed)"
echo ""
echo "-- ${PROG} is up to date (incremental build) --"
echo "Run with: cd $PROJDIR/bin && LD_LIBRARY_PATH=. ./${PROG}"
exit 0
fi
# [5/6] Link
echo "[5/6] Linking ${PROG}..."
EXTRA_OBJS=""
[ -f hbdb_real.o ] && EXTRA_OBJS="$EXTRA_OBJS hbdb_real.o"
gcc ${PROG}.o gtk3_core.o gtk3_inspector.o $EXTRA_OBJS -g -o ${PROG} \
-L"$HBLIB" \
-Wl,--start-group \
-lhbcommon -lhbvm -lhbrtl -lhbrdd -lhbmacro -lhblang -lhbcpage -lhbpp \
-lhbcplr -lrddntx -lrddcdx -lrddfpt -lhbsix -lhbusrrdd -lhbct \
-lhbsqlit3 -lsddsqlt3 -lrddsql \
-lgttrm -lhbdebug -lhbpcre \
$(pkg-config --libs gtk+-3.0) \
$WEBKIT_LIBS \
-lm -lpthread -ldl -lrt -lsqlite3 \
-L/usr/lib/x86_64-linux-gnu -l:libncurses.so.6 \
-Wl,--end-group
# [6/6] Install to bin/
echo "[6/6] Installing to bin/..."
BINDIR="$PROJDIR/bin"
mkdir -p "$BINDIR"
cp -f "${PROG}" "$BINDIR/"
if [ -f "$RESDIR/libscintilla.so" ]; then
cp -u "$RESDIR/libscintilla.so" "$BINDIR/"
cp -u "$RESDIR/liblexilla.so" "$BINDIR/"
echo " Copied libscintilla.so + liblexilla.so to bin/"
fi
echo ""
echo "-- ${PROG} built successfully --"
echo "Run with: cd $BINDIR && LD_LIBRARY_PATH=. ./${PROG}"