-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·3844 lines (3326 loc) · 135 KB
/
build.sh
File metadata and controls
executable file
·3844 lines (3326 loc) · 135 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# =============================================================================
# UniversalMolecule 0.15.21 Build Script - All Platforms
#
# Single self-contained script to build UniversalMolecule daemon and/or Qt wallet
# for Linux, macOS, Windows, and AppImage.
#
# Based on Bitcoin Core 0.15.2 - uses autotools (./configure + make).
# Windows cross-compilation still uses pre-built libraries in the Docker image.
# macOS cross-compilation now defaults to a depends + CONFIG_SITE flow inside
# the Docker image, with the older pre-built-libs path kept as a fallback.
#
# Usage: ./build.sh [PLATFORM] [TARGET] [OPTIONS]
# See ./build.sh --help for full usage.
#
# Docker Hub images (prebuilt):
# sidgrip/native-base:20.04 - Native Linux (Ubuntu 20.04, GCC 9, Boost 1.71)
# sidgrip/native-base:22.04 - Native Linux (Ubuntu 22.04, GCC 11, Boost 1.74)
# sidgrip/native-base:24.04 - Native Linux (Ubuntu 24.04, GCC 13, Boost 1.83)
# sidgrip/native-base:25.10 - Native Linux (Ubuntu 25.10, GCC 15, Boost 1.88)
# sidgrip/appimage-base:22.04 - AppImage builds (Ubuntu 22.04 + appimagetool)
# sidgrip/mxe-base:latest - Windows cross-compile (MXE + MinGW)
# sidgrip/osxcross-base:sdk-26.2 - macOS cross-compile (depends + osxcross SDK 26.2)
#
# Repository: https://github.com/BlueDragon747/UniversalMolecule (branch: master)
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUTPUT_BASE="${OUTPUT_BASE:-$SCRIPT_DIR/outputs}"
COIN_NAME="universalmolecule"
COIN_NAME_UPPER="UniversalMolecule"
DAEMON_NAME="universalmoleculed"
QT_NAME="universalmolecule-qt"
CLI_NAME="universalmolecule-cli"
TX_NAME="universalmolecule-tx"
VERSION="0.15.21"
REPO_URL="https://github.com/BlueDragon747/universalmol.git"
REPO_BRANCH="master"
QT_LINUX_LAUNCHER_SOURCE="$SCRIPT_DIR/contrib/linux-release/blakecoin-qt-launcher.c"
APPIMAGE_PUBLIC_NAME="${COIN_NAME_UPPER}-${VERSION}-x86_64.AppImage"
WINDOWS_ICON_SOURCE_PNG="$SCRIPT_DIR/src/qt/res/icons/bitcoin.png"
WINDOWS_ICON_SOURCE_TESTNET_PNG="$SCRIPT_DIR/src/qt/res/icons/bitcoin_testnet.png"
WINDOWS_EXE_ICON_ICO="$SCRIPT_DIR/src/qt/res/icons/universalmolecule_32.ico"
WINDOWS_EXE_ICON_TESTNET_ICO="$SCRIPT_DIR/src/qt/res/icons/universalmolecule_32_testnet.ico"
WINDOWS_INSTALLER_ICON_ICO="$SCRIPT_DIR/share/pixmaps/bitcoin.ico"
BDB_PACKAGE_MK="$SCRIPT_DIR/depends/packages/bdb.mk"
BDB_CACHE_ROOT="$SCRIPT_DIR/.cache/bdb"
NATIVE_LINUX_ALL_DEPS=()
NATIVE_LINUX_ALL_DEPS_STR=""
CURRENT_OUTPUT_DIR=""
GENERATE_CONFIG_AFTER_BUILD=0
# Network ports and config
RPC_PORT=5921
P2P_PORT=24785
EXPLORER_API_BASE="https://explorer.blakestream.io/api"
EXPLORER_COIN_ID="umo"
CONFIG_FILE="${COIN_NAME}.conf"
LISTEN='listen=1'
DAEMON='daemon=1'
SERVER='server=1'
TXINDEX='txindex=0'
# Docker images
DOCKER_NATIVE="${DOCKER_NATIVE:-sidgrip/native-base:24.04}"
DOCKER_APPIMAGE="${DOCKER_APPIMAGE:-sidgrip/appimage-base:22.04}"
DOCKER_WINDOWS="${DOCKER_WINDOWS:-sidgrip/mxe-base:latest}"
DOCKER_MACOS="${DOCKER_MACOS:-sidgrip/osxcross-base:sdk-26.2}"
# Cross-compile host triplets
WIN_HOST="x86_64-w64-mingw32.static"
MAC_HOST="" # Auto-detected from Docker image at build time
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
# =============================================================================
# HELPER FUNCTIONS
# =============================================================================
info() { echo -e "${CYAN}[INFO]${NC} $*"; }
success() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*"; }
# Fix execute permissions after copying source tree (rsync/cp can lose +x bits)
fix_permissions() {
local dir="$1"
find "$dir" -name '*.sh' -exec chmod +x {} + 2>/dev/null || true
find "$dir" -name 'config.guess' -o -name 'config.sub' -o -name 'install-sh' \
-o -name 'missing' -o -name 'compile' -o -name 'depcomp' \
-o -name 'build_detect_platform' -o -name 'autogen.sh' \
| xargs chmod +x 2>/dev/null || true
}
copy_source_tree_to_tempdir() {
local dest="$1"
rsync -a \
--exclude '.git' \
--exclude 'outputs' \
--exclude 'staging' \
--exclude '.cache' \
--exclude '.electrum-builds' \
--exclude '.ubuntu-builds' \
"$SCRIPT_DIR"/ "$dest/"
}
clean_stale_build_artifacts() {
local dir="$1"
# Container cross-builds copy the working tree as-is, so stale autotools and
# libtool outputs from prior native builds can make make believe targets are
# already satisfied even when their companion objects are missing.
find "$dir" -type d \( -name '.deps' -o -name '.libs' -o -name 'autom4te.cache' \) \
-prune -exec rm -rf {} + 2>/dev/null || true
find "$dir" -type f \( \
-name 'config.status' -o \
-name 'config.log' -o \
-name 'config.cache' -o \
-name 'libtool' -o \
-name '*.o' -o \
-name '*.lo' -o \
-name '*.la' -o \
-name '*.obj' -o \
-name '*.a' -o \
-name '*.exe' -o \
-name '*.res' -o \
-name '*.pdb' -o \
-name '*.Tpo' -o \
-name '*.Plo' -o \
-name '*.Po' -o \
-name '*.trs' -o \
-name '*.dirstamp' \
\) -delete 2>/dev/null || true
# Cross-builds should regenerate Qt/protobuf build products with the
# container's own moc/uic/rcc/protoc so host-generated files don't leak in.
find "$dir/src/qt" -maxdepth 1 -type f \( \
-name '*.moc' -o \
-name 'moc_*.cpp' -o \
-name 'paymentrequest.pb.cc' -o \
-name 'paymentrequest.pb.h' \
\) -delete 2>/dev/null || true
find "$dir/src/qt/forms" -maxdepth 1 -type f -name 'ui_*.h' \
-delete 2>/dev/null || true
}
# Portable sed -i wrapper (macOS BSD sed requires '' arg, GNU sed does not)
sedi() {
if [[ "$(uname -s)" == "Darwin" ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
sync_windows_icon_assets() {
if ! command -v python3 &>/dev/null; then
warn "python3 not found; using checked-in Windows icon assets."
return 0
fi
if ! python3 -c 'from PIL import Image' >/dev/null 2>&1; then
warn "python3-pil not found; using checked-in Windows icon assets."
return 0
fi
info "Regenerating Windows icon assets from repo bitcoin.png sources..."
python3 - <<PY
from PIL import Image
sizes = [(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)]
targets = [
("$WINDOWS_ICON_SOURCE_PNG", "$WINDOWS_EXE_ICON_ICO"),
("$WINDOWS_ICON_SOURCE_PNG", "$WINDOWS_INSTALLER_ICON_ICO"),
("$WINDOWS_ICON_SOURCE_TESTNET_PNG", "$WINDOWS_EXE_ICON_TESTNET_ICO"),
]
for src, dst in targets:
img = Image.open(src).convert("RGBA")
img.save(dst, format="ICO", sizes=sizes)
print(f" generated {dst} from {src}")
PY
}
ensure_windows_icon_assets() {
local missing=()
local path
sync_windows_icon_assets
for path in \
"$WINDOWS_ICON_SOURCE_PNG" \
"$WINDOWS_ICON_SOURCE_TESTNET_PNG" \
"$WINDOWS_EXE_ICON_ICO" \
"$WINDOWS_EXE_ICON_TESTNET_ICO" \
"$WINDOWS_INSTALLER_ICON_ICO"
do
[[ -f "$path" ]] || missing+=("$path")
done
if [[ ${#missing[@]} -gt 0 ]]; then
error "Missing required Windows icon asset(s):"
printf ' %s\n' "${missing[@]}"
exit 1
fi
info "Windows branding source (main): $WINDOWS_ICON_SOURCE_PNG"
info "Windows branding source (testnet): $WINDOWS_ICON_SOURCE_TESTNET_PNG"
info "Windows embedded exe icon (main): $WINDOWS_EXE_ICON_ICO"
info "Windows embedded exe icon (testnet): $WINDOWS_EXE_ICON_TESTNET_ICO"
info "Windows installer icon: $WINDOWS_INSTALLER_ICON_ICO"
}
ensure_macos_brew_env() {
local brew_bin=""
if command -v brew &>/dev/null; then
brew_bin=$(command -v brew)
else
for brew_bin in /opt/homebrew/bin/brew /usr/local/bin/brew "$HOME/homebrew/bin/brew"; do
[[ -x "$brew_bin" ]] && break
done
fi
if [[ -n "$brew_bin" && -x "$brew_bin" ]]; then
eval "$("$brew_bin" shellenv)" >/dev/null 2>&1 || true
export PATH="$(dirname "$brew_bin"):$PATH"
return 0
fi
return 1
}
prime_macos_sudo() {
if sudo -n true 2>/dev/null; then
return 0
fi
if [[ -n "${MACOS_SUDO_PASS:-}" ]]; then
printf '%s\n' "$MACOS_SUDO_PASS" | sudo -S -p '' -v
else
sudo -v
fi
}
ensure_macos_homebrew() {
if ensure_macos_brew_env; then
return 0
fi
info "Homebrew not found - installing it automatically..."
prime_macos_sudo
NONINTERACTIVE=1 CI=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if ! ensure_macos_brew_env; then
error "Homebrew installation completed but brew is still not available."
exit 1
fi
}
usage() {
cat <<'EOF'
Usage: build.sh [PLATFORM] [TARGET] [OPTIONS]
Platforms:
--native Build natively on this machine (Linux, macOS, or Windows)
--appimage Build portable Linux AppImage (requires Docker)
--windows Cross-compile for Windows from Linux (requires Docker)
--macos Cross-compile for macOS from Linux (requires Docker)
Targets:
--daemon Build daemon only (universalmoleculed + universalmolecule-cli + universalmolecule-tx)
--qt Build Qt wallet only (universalmolecule-qt)
--both Build daemon and Qt wallet (default)
Docker options (for --appimage, --windows, --macos, or --native on Linux):
--pull-docker Pull prebuilt Docker images from Docker Hub
--build-docker Build Docker images locally from repo Dockerfiles
--no-docker For --native on Linux: skip Docker, build directly on host
Other options:
--jobs N Parallel make jobs (default: CPU cores - 1)
-h, --help Show this help
Examples:
# Native builds (no Docker needed)
./build.sh --native --both # Build directly on host
./build.sh --native --daemon # Daemon only
# Native Linux with Docker
./build.sh --native --both --pull-docker # Use appimage-base from Docker Hub
./build.sh --native --both --build-docker # Same as --pull-docker (shared images)
# Cross-compile (Docker required - choose --pull-docker or --build-docker)
./build.sh --windows --qt --pull-docker # Pull mxe-base from Docker Hub
./build.sh --macos --qt --pull-docker # Pull osxcross-base from Docker Hub
./build.sh --appimage --pull-docker # Pull appimage-base from Docker Hub
Docker Hub images (used with --pull-docker):
sidgrip/native-base:20.04 Native Linux (Ubuntu 20.04, GCC 9)
sidgrip/native-base:22.04 Native Linux (Ubuntu 22.04, GCC 11)
sidgrip/native-base:24.04 Native Linux (Ubuntu 24.04, GCC 13) [default]
sidgrip/native-base:25.10 Native Linux (Ubuntu 25.10, GCC 15)
sidgrip/appimage-base:22.04 AppImage (Ubuntu 22.04 + appimagetool)
sidgrip/mxe-base:latest Windows cross-compile (MXE + MinGW)
sidgrip/osxcross-base:sdk-26.2 macOS cross-compile (depends + osxcross SDK 26.2) [default]
EOF
exit 0
}
detect_os() {
if [[ "${MSYSTEM:-}" =~ MINGW|MSYS ]]; then
echo "windows"
elif [[ "$(uname -s)" == "Darwin" ]]; then
echo "macos"
else
echo "linux"
fi
}
detect_os_version() {
local os="$1"
case "$os" in
linux)
if command -v lsb_release &>/dev/null; then
lsb_release -ds 2>/dev/null
elif [[ -f /etc/os-release ]]; then
. /etc/os-release && echo "${PRETTY_NAME:-$NAME $VERSION_ID}"
else
echo "Linux $(uname -r)"
fi
;;
macos)
echo "macOS $(sw_vers -productVersion 2>/dev/null || echo 'unknown')"
;;
windows)
if [[ -n "${MSYSTEM:-}" ]]; then
echo "$MSYSTEM / Windows $(uname -r 2>/dev/null || echo 'unknown')"
else
echo "Windows"
fi
;;
esac
}
normalize_ubuntu_output_label() {
local ubuntu_ver="${1:-unknown}"
case "$ubuntu_ver" in
20.04*) echo "Ubuntu-20" ;;
22.04*) echo "Ubuntu-22" ;;
24.04*) echo "Ubuntu-24" ;;
25.10*) echo "Ubuntu-25" ;;
*)
local major="${ubuntu_ver%%.*}"
if [[ -n "$major" && "$major" != "$ubuntu_ver" ]]; then
echo "Ubuntu-$major"
elif [[ "$ubuntu_ver" =~ ^[0-9]+$ ]]; then
echo "Ubuntu-$ubuntu_ver"
else
echo "Ubuntu"
fi
;;
esac
}
linux_output_dir() {
local ubuntu_ver="${1:-unknown}"
printf '%s/%s\n' "$OUTPUT_BASE" "$(normalize_ubuntu_output_label "$ubuntu_ver")"
}
windows_output_dir() {
printf '%s/Windows\n' "$OUTPUT_BASE"
}
macos_output_dir() {
printf '%s/Macosx\n' "$OUTPUT_BASE"
}
appimage_output_dir() {
printf '%s/AppImage\n' "$OUTPUT_BASE"
}
cleanup_target_output_dir() {
local output_dir="$1"
rm -rf "$output_dir"
mkdir -p "$output_dir"
}
cleanup_legacy_output_root() {
mkdir -p "$OUTPUT_BASE"
rm -f \
"$OUTPUT_BASE/$DAEMON_NAME" \
"$OUTPUT_BASE/$CLI_NAME" \
"$OUTPUT_BASE/$TX_NAME" \
"$OUTPUT_BASE/$QT_NAME" \
"$OUTPUT_BASE/${QT_NAME}-bin" \
"$OUTPUT_BASE/${DAEMON_NAME}.exe" \
"$OUTPUT_BASE/${CLI_NAME}.exe" \
"$OUTPUT_BASE/${TX_NAME}.exe" \
"$OUTPUT_BASE/${QT_NAME}.exe" \
"$OUTPUT_BASE/${DAEMON_NAME}-${VERSION}" \
"$OUTPUT_BASE/${CLI_NAME}-${VERSION}" \
"$OUTPUT_BASE/${TX_NAME}-${VERSION}" \
"$OUTPUT_BASE/${QT_NAME}-${VERSION}" \
"$OUTPUT_BASE/${DAEMON_NAME}-${VERSION}.exe" \
"$OUTPUT_BASE/${CLI_NAME}-${VERSION}.exe" \
"$OUTPUT_BASE/${TX_NAME}-${VERSION}.exe" \
"$OUTPUT_BASE/${QT_NAME}-${VERSION}.exe" \
"$OUTPUT_BASE/install-deps.sh" \
"$OUTPUT_BASE/${COIN_NAME}.desktop" \
"$OUTPUT_BASE/${COIN_NAME}-256.png" \
"$OUTPUT_BASE/universalmolecule.conf" \
"$OUTPUT_BASE/qt.conf" \
"$OUTPUT_BASE/README.md" \
"$OUTPUT_BASE/build-info.txt"
rm -rf \
"$OUTPUT_BASE/.runtime" \
"$OUTPUT_BASE/lib" \
"$OUTPUT_BASE/plugins" \
"$OUTPUT_BASE/platforms" \
"$OUTPUT_BASE/UniversalMolecule-Qt.app" \
"$OUTPUT_BASE/native" \
"$OUTPUT_BASE/windows" \
"$OUTPUT_BASE/macos" \
"$OUTPUT_BASE/windows-native" \
"$OUTPUT_BASE/macos-native" \
"$OUTPUT_BASE/daemon" \
"$OUTPUT_BASE/qt" \
"$OUTPUT_BASE/appimage" \
"$OUTPUT_BASE/release"
shopt -s nullglob
local stale_dlls=("$OUTPUT_BASE"/*.dll)
local stale_ubuntu_dirs=("$OUTPUT_BASE"/universalmolecule-v${VERSION}-ubuntu-*-x86_64 "$OUTPUT_BASE"/universalmolecule-v${VERSION}-ubuntu-*-x86_64-daemon "$OUTPUT_BASE"/universalmolecule-v${VERSION}-ubuntu-*-x86_64-qt)
local stale_ubuntu_archives=("$OUTPUT_BASE"/universalmolecule-v${VERSION}-ubuntu-*-x86_64.tar.gz)
shopt -u nullglob
if [[ ${#stale_dlls[@]} -gt 0 ]]; then
rm -f "${stale_dlls[@]}"
fi
if [[ ${#stale_ubuntu_dirs[@]} -gt 0 ]]; then
rm -rf "${stale_ubuntu_dirs[@]}"
fi
if [[ ${#stale_ubuntu_archives[@]} -gt 0 ]]; then
rm -f "${stale_ubuntu_archives[@]}"
fi
}
bdb_recipe_version() {
awk -F= '/^\$\(package\)_version=/{print $2}' "$BDB_PACKAGE_MK"
}
bdb_recipe_sha256() {
awk -F= '/^\$\(package\)_sha256_hash=/{print $2}' "$BDB_PACKAGE_MK"
}
sha256_file() {
local file="$1"
if command -v sha256sum &>/dev/null; then
sha256sum "$file" | awk '{print $1}'
elif command -v shasum &>/dev/null; then
shasum -a 256 "$file" | awk '{print $1}'
else
error "No SHA256 tool found (need sha256sum or shasum)"
exit 1
fi
}
native_bdb48_prefix() {
local host_id="$1"
printf '%s/4.8/%s\n' "$BDB_CACHE_ROOT" "$host_id"
}
ensure_repo_bdb48() {
local platform="$1"
local host_id="$2"
local jobs="$3"
local prefix=""
local prefix_tmp=""
local sources_dir=""
local build_root=""
local version=""
local sha256=""
local archive_name=""
local archive_path=""
local dist_name=""
local build_dir=""
local machine=""
local actual_sha=""
local configure_cmd=()
prefix="$(native_bdb48_prefix "$host_id")"
prefix_tmp="${prefix}.tmp"
sources_dir="$BDB_CACHE_ROOT/sources"
build_root="$BDB_CACHE_ROOT/work/$host_id"
version="$(bdb_recipe_version)"
sha256="$(bdb_recipe_sha256)"
archive_name="db-${version}.NC.tar.gz"
archive_path="$sources_dir/$archive_name"
dist_name="db-${version}.NC"
build_dir="$build_root/$dist_name/build_unix"
if [[ -f "$prefix/include/db_cxx.h" && -f "$prefix/lib/libdb_cxx-4.8.a" && -f "$prefix/lib/libdb-4.8.a" ]]; then
echo "$prefix"
return 0
fi
mkdir -p "$sources_dir" "$(dirname "$prefix")"
if [[ ! -f "$archive_path" ]]; then
info "Downloading Berkeley DB 4.8.30.NC source..." >&2
curl -L "https://download.oracle.com/berkeley-db/$archive_name" -o "${archive_path}.tmp"
mv "${archive_path}.tmp" "$archive_path"
fi
actual_sha="$(sha256_file "$archive_path")"
if [[ "$actual_sha" != "$sha256" ]]; then
error "Berkeley DB source hash mismatch for $archive_name" >&2
error "Expected: $sha256" >&2
error "Actual: $actual_sha" >&2
exit 1
fi
info "Bootstrapping Berkeley DB 4.8.30.NC for $host_id..." >&2
rm -rf "$build_root" "$prefix_tmp"
mkdir -p "$build_root"
tar -xzf "$archive_path" -C "$build_root"
pushd "$build_dir" >/dev/null
sed -i.bak 's/__atomic_compare_exchange/__atomic_compare_exchange_db/g' ../dbinc/atomic.h
while IFS= read -r -d '' source_file; do
sed -i.bak 's/\batomic_init\b/bdb_atomic_init/g' "$source_file"
done < <(find .. \( -name '*.h' -o -name '*.c' -o -name '*.cpp' \) -print0)
find .. -name '*.bak' -delete 2>/dev/null || true
cp -f "$SCRIPT_DIR/depends/config.guess" "$SCRIPT_DIR/depends/config.sub" ../dist/
configure_cmd=(
../dist/configure
--prefix="$prefix_tmp"
--enable-cxx
--disable-shared
--disable-replication
--disable-atomicsupport
)
case "$platform" in
linux)
configure_cmd+=(--with-pic --with-mutex=POSIX/pthreads)
;;
mingw)
machine="$(gcc -dumpmachine 2>/dev/null || true)"
[[ -n "$machine" ]] && configure_cmd+=(--host="$machine")
configure_cmd+=(--enable-mingw)
;;
*)
error "Unsupported Berkeley DB bootstrap platform: $platform" >&2
exit 1
;;
esac
env CFLAGS="-O2" CXXFLAGS="-O2 -std=c++11" "${configure_cmd[@]}" >&2
make -j"$jobs" libdb_cxx-4.8.a libdb-4.8.a >&2
mkdir -p "$prefix_tmp/lib" "$prefix_tmp/include"
if [[ ! -f db.h || ! -f db_cxx.h ]]; then
error "Failed to locate Berkeley DB headers in $build_dir" >&2
exit 1
fi
cp -f db.h "$prefix_tmp/include/db.h"
cp -f db_cxx.h "$prefix_tmp/include/db_cxx.h"
cp -f libdb-4.8.a "$prefix_tmp/lib/libdb-4.8.a"
cp -f libdb_cxx-4.8.a "$prefix_tmp/lib/libdb_cxx-4.8.a"
if [[ -f libdb.a ]]; then
cp -f libdb.a "$prefix_tmp/lib/libdb.a"
else
cp -f libdb-4.8.a "$prefix_tmp/lib/libdb.a"
fi
if [[ -f libdb_cxx.a ]]; then
cp -f libdb_cxx.a "$prefix_tmp/lib/libdb_cxx.a"
else
cp -f libdb_cxx-4.8.a "$prefix_tmp/lib/libdb_cxx.a"
fi
popd >/dev/null
rm -rf "$prefix"
mv "$prefix_tmp" "$prefix"
rm -rf "$build_root"
echo "$prefix"
}
verify_bdb48_prefix() {
local prefix="$1"
local label="$2"
if [[ ! -f "$prefix/include/db_cxx.h" ]]; then
error "$label is missing Berkeley DB 4.8 headers at $prefix/include/db_cxx.h"
return 1
fi
if ! compgen -G "$prefix/lib/libdb_cxx-4.8*" >/dev/null; then
error "$label is missing Berkeley DB 4.8 C++ libraries under $prefix/lib"
return 1
fi
if ! compgen -G "$prefix/lib/libdb-4.8*" >/dev/null; then
error "$label is missing Berkeley DB 4.8 libraries under $prefix/lib"
return 1
fi
}
native_linux_link_command() {
local target="$1"
local cmd=""
pushd "$SCRIPT_DIR/src" >/dev/null
cmd="$(make -n V=1 "$target" 2>/dev/null | awk '/\/libtool[[:space:]].*--mode=link/ { line=$0 } END { if (line != "") print line; else exit 1 }')"
popd >/dev/null
[[ -n "$cmd" ]] || return 1
printf '%s\n' "$cmd"
}
relink_native_linux_target() {
local target="$1"
local artifact="$2"
local cmd=""
cmd="$(native_linux_link_command "$target")" || {
error "Failed to capture native Linux link command for $target"
return 1
}
pushd "$SCRIPT_DIR/src" >/dev/null
bash -lc "$cmd" >/dev/null
popd >/dev/null
if objdump -p "$artifact" 2>/dev/null | grep -Eq 'libdb(_cxx)?-5\.3\.so'; then
error "Native Linux post-link verification failed for $artifact"
return 1
fi
}
ensure_windows_native_shell() {
local target="$1"
local jobs="$2"
local msys_root="/c/msys64"
local msys_bash="$msys_root/usr/bin/bash.exe"
local msys_env="$msys_root/usr/bin/env.exe"
local target_flag="--both"
local reexec_cmd=""
case "$target" in
daemon) target_flag="--daemon" ;;
qt) target_flag="--qt" ;;
both) target_flag="--both" ;;
esac
if [[ "${MSYSTEM:-}" == "MINGW64" ]] && command -v pacman &>/dev/null; then
return 0
fi
if ! command -v powershell.exe &>/dev/null; then
error "PowerShell is required to bootstrap native Windows builds."
exit 1
fi
if [[ ! -x "$msys_bash" || ! -x "$msys_env" ]]; then
info "MSYS2 not found - installing it automatically..."
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
$ErrorActionPreference = "Stop"
$msysUrl = "https://github.com/msys2/msys2-installer/releases/download/nightly-x86_64/msys2-base-x86_64-latest.sfx.exe"
$msysExe = "$env:TEMP\msys2-base-x86_64-latest.sfx.exe"
Invoke-WebRequest -UseBasicParsing -Uri $msysUrl -OutFile $msysExe
& $msysExe "-y" "-oC:\"
'
fi
if [[ ! -x "$msys_bash" || ! -x "$msys_env" ]]; then
error "MSYS2 installation did not produce $msys_bash"
exit 1
fi
info "Initializing MSYS2..."
"$msys_env" MSYSTEM=MINGW64 CHERE_INVOKING=yes MSYS2_PATH_TYPE=inherit \
"$msys_bash" -lc '
set +e
pacman-key --init >/dev/null 2>&1
pacman-key --populate msys2 >/dev/null 2>&1
pacman --noconfirm -Sy >/dev/null 2>&1
pacman --noconfirm -Syuu >/dev/null 2>&1
pacman --noconfirm -Syuu >/dev/null 2>&1
exit 0
'
printf -v reexec_cmd 'cd %q && ./build.sh --native %s --jobs %q' "$SCRIPT_DIR" "$target_flag" "$jobs"
info "Re-entering build.sh inside MSYS2 MINGW64..."
exec "$msys_env" MSYSTEM=MINGW64 CHERE_INVOKING=yes MSYS2_PATH_TYPE=inherit \
"$msys_bash" -lc "$reexec_cmd"
}
write_build_info() {
local output_dir="$1"
local platform="$2"
local target="$3"
local os_version="$4"
mkdir -p "$output_dir"
cat > "$output_dir/build-info.txt" <<EOF
Coin: $COIN_NAME_UPPER 0.15.21
Target: $target
Platform: $platform
OS: $os_version
Date: $(date -u '+%Y-%m-%d %H:%M:%S UTC')
Branch: $REPO_BRANCH
Script: build.sh
EOF
}
copy_runtime_libs() {
local binary="$1"
local dest_dir="$2"
mkdir -p "$dest_dir"
while IFS= read -r lib; do
[[ -n "$lib" && -r "$lib" ]] || continue
case "$(basename "$lib")" in
ld-linux-*|libc.so.*|libdl.so.*|libm.so.*|libpthread.so.*|librt.so.*|libresolv.so.*|libutil.so.*|libnsl.so.*|libanl.so.*)
continue
;;
esac
cp -Lf "$lib" "$dest_dir/"
done < <(
ldd "$binary" 2>/dev/null | awk '
/=> \// {print $3}
/^\// {print $1}
' | sort -u
)
}
is_macos_system_dylib() {
case "$1" in
/System/Library/*|/usr/lib/*)
return 0
;;
esac
return 1
}
resolve_macos_bundle_dep_target() {
local dep="$1"
local subject="$2"
local main_exe_dir="$3"
local frameworks_dir="$4"
case "$dep" in
@executable_path/*)
printf '%s\n' "$main_exe_dir/${dep#@executable_path/}"
;;
@loader_path/*)
printf '%s\n' "$(dirname "$subject")/${dep#@loader_path/}"
;;
@rpath/*)
local rel="${dep#@rpath/}"
if [[ -e "$frameworks_dir/$rel" ]]; then
printf '%s\n' "$frameworks_dir/$rel"
else
printf '%s\n' "$frameworks_dir/$(basename "$dep")"
fi
;;
*)
printf '%s\n' "$dep"
;;
esac
}
find_macos_source_dylib() {
local dylib_name="$1"
shift
local search_dir=""
for search_dir in "$@"; do
[[ -n "$search_dir" && -d "$search_dir" ]] || continue
if [[ -f "$search_dir/$dylib_name" ]]; then
printf '%s\n' "$search_dir/$dylib_name"
return 0
fi
done
return 1
}
bundle_macos_transitive_dylibs() {
local app_dir="$1"
shift
local frameworks_dir="$app_dir/Contents/Frameworks"
local main_exe_dir="$app_dir/Contents/MacOS"
local main_exe="$main_exe_dir/UniversalMolecule-Qt"
local search_dirs=("$@")
local pass=0
local changed=1
[[ -f "$main_exe" && -d "$frameworks_dir" ]] || return 0
while [[ $changed -eq 1 && $pass -lt 10 ]]; do
changed=0
pass=$((pass + 1))
local subject=""
local dep=""
local dep_target=""
local dep_name=""
local source_lib=""
local bundled_lib=""
local new_ref=""
while IFS= read -r subject; do
[[ -f "$subject" ]] || continue
while IFS= read -r dep; do
[[ -n "$dep" ]] || continue
if is_macos_system_dylib "$dep"; then
continue
fi
dep_target=$(resolve_macos_bundle_dep_target "$dep" "$subject" "$main_exe_dir" "$frameworks_dir")
if [[ -n "$dep_target" && -e "$dep_target" ]]; then
continue
fi
dep_name=$(basename "$dep")
source_lib=$(find_macos_source_dylib "$dep_name" "${search_dirs[@]}" || true)
[[ -n "$source_lib" ]] || continue
bundled_lib="$frameworks_dir/$dep_name"
if [[ ! -f "$bundled_lib" ]]; then
cp -f "$source_lib" "$bundled_lib"
chmod u+w "$bundled_lib" 2>/dev/null || true
install_name_tool -id "@executable_path/../Frameworks/$dep_name" "$bundled_lib" 2>/dev/null || true
changed=1
fi
if [[ "$subject" == "$main_exe" ]]; then
new_ref="@executable_path/../Frameworks/$dep_name"
else
new_ref="@loader_path/$dep_name"
fi
install_name_tool -change "$dep" "$new_ref" "$subject" 2>/dev/null || true
done < <(otool -L "$subject" 2>/dev/null | tail -n +2 | awk '{print $1}')
done < <(
printf '%s\n' "$main_exe"
find "$frameworks_dir" -maxdepth 1 -type f -name '*.dylib' | sort
)
done
}
compile_linux_qt_launcher() {
local output_path="$1"
local target_rel="${2:-.runtime/${QT_NAME}-bin}"
local use_runtime_env="${3:-1}"
local launcher_cc="${CC:-}"
local output_dir=""
local output_name=""
local gcc_args=(
-O2
-s
-Wall
-Wextra
-no-pie
"-DBLAKECOIN_QT_LAUNCH_TARGET=\"${target_rel}\""
"-DBLAKECOIN_QT_USE_RUNTIME_ENV=${use_runtime_env}"
)
[[ -f "$QT_LINUX_LAUNCHER_SOURCE" ]] || {
error "Linux Qt launcher source not found: $QT_LINUX_LAUNCHER_SOURCE"
exit 1
}
if [[ -z "$launcher_cc" ]]; then
for candidate in gcc cc clang; do
if command -v "$candidate" >/dev/null 2>&1; then
launcher_cc="$candidate"
break
fi
done
fi
[[ -n "$launcher_cc" ]] || {
if command -v docker >/dev/null 2>&1 && [[ -n "${DOCKER_NATIVE:-}" ]]; then
output_dir="$(cd "$(dirname "$output_path")" && pwd)"
output_name="$(basename "$output_path")"
docker run --rm \
-u "$(id -u):$(id -g)" \
-e BLAKECOIN_QT_LAUNCH_TARGET="$target_rel" \
-e BLAKECOIN_QT_USE_RUNTIME_ENV="$use_runtime_env" \
-e BLAKECOIN_QT_LAUNCH_OUTPUT="$output_name" \
-v "$SCRIPT_DIR:/repo:ro" \
-v "$output_dir:/out" \
"$DOCKER_NATIVE" \
/bin/bash -lc '
set -e
compiler=""
for candidate in "${CC:-}" gcc cc clang; do
if [[ -n "$candidate" ]] && command -v "$candidate" >/dev/null 2>&1; then
compiler="$candidate"
break
fi
done
[[ -n "$compiler" ]] || {
echo "No usable C compiler found in Linux launcher fallback container" >&2
exit 1
}
"$compiler" -O2 -s -Wall -Wextra -no-pie \
"-DBLAKECOIN_QT_LAUNCH_TARGET=\"${BLAKECOIN_QT_LAUNCH_TARGET}\"" \
"-DBLAKECOIN_QT_USE_RUNTIME_ENV=${BLAKECOIN_QT_USE_RUNTIME_ENV}" \
/repo/contrib/linux-release/universalmolecule-qt-launcher.c \
-o "/out/${BLAKECOIN_QT_LAUNCH_OUTPUT}"
'
else
error "No usable C compiler found for the Linux Qt launcher helper"
exit 1
fi
chmod +x "$output_path"
return
}
# Ubuntu 20's default PIE launcher gets classified as application/x-sharedlib
# in GNOME, so force a normal executable for release-click behavior.
"$launcher_cc" "${gcc_args[@]}" "$QT_LINUX_LAUNCHER_SOURCE" -o "$output_path"
chmod +x "$output_path"
}
write_linux_release_desktop() {
local desktop_path="$1"
cat > "$desktop_path" <<EOF
[Desktop Entry]
Type=Application
Name=UniversalMolecule Qt
Comment=UniversalMolecule Cryptocurrency Wallet
Exec=universalmolecule-qt
Icon=universalmolecule-qt
Terminal=false
Categories=Finance;Network;
EOF
}
resolve_native_linux_packages() {
local target="$1"
local qt_deps=()
NATIVE_LINUX_ALL_DEPS=(
build-essential
libtool-bin
autotools-dev
automake
pkg-config
curl
libssl-dev
libevent-dev
libminiupnpc-dev
libprotobuf-dev
protobuf-compiler
libboost-all-dev
)
if [[ "$target" == "qt" || "$target" == "both" ]]; then
qt_deps=(qtbase5-dev qttools5-dev qttools5-dev-tools libqrencode-dev)
NATIVE_LINUX_ALL_DEPS+=("${qt_deps[@]}")
fi
NATIVE_LINUX_ALL_DEPS_STR="${NATIVE_LINUX_ALL_DEPS[*]}"
}
write_linux_install_deps_script() {
local script_path="$1"
local install_packages="$2"