-
Notifications
You must be signed in to change notification settings - Fork 44
/
build.sh
executable file
·3393 lines (2791 loc) · 78.6 KB
/
build.sh
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/sh
set -e
trap 'echo E: build failed with error on ${LINENO}; exit 1' ERR
# Ensure our subshells inherit our "set -e".
export SHELLOPTS
# Currently, we build gnuradio 3.8.1.0 for Python3.7.
GNURADIO_BRANCH=v3.8.1.0
GNURADIO_COMMIT_HASH=git:867b0ab9191ff6c6d5d8f49b5b95fdd884e92a07
GENTOO_MIRROR=https://mirrors.evowise.com/gentoo/distfiles
# default os x path minus /usr/local/bin, which could have pollutants
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# Provide a list of the extensions we consider archives.
EXTS="zip tar.gz tgz tar.bz2 tbz2 tar.xz"
# Provide some basic defaults.
SKIP_FETCH=true
SKIP_AUTORECONF=
SKIP_LIBTOOLIZE=
KEEP_ON_MISMATCH=
COPY_HASH_ON_MISMATCH=true
# Uncomment the following line to enable more verbose build output.
DEBUG=true
function top_srcdir() {
local r
pushd "$(dirname "${0}")" > /dev/null
r="$(pwd -P)"
popd > /dev/null
echo "${r}"
}
function I() {
echo "I: ${@}" || true
}
function E() {
echo "E: ${@}" > /dev/stderr
exit 1;
}
function F() {
E Failed to build package.
}
function D() {
if [ "" != "$DEBUG" ]; then
echo "D: ${@}"
fi
}
function ncpus() {
sysctl -n hw.ncpu
}
[[ "$(uname)" = "Darwin" ]] \
|| E "This script is only intended to be run on Mac OS X"
XQUARTZ_APP_DIR=/Applications/Utilities/XQuartz.app
BUILD_DIR="$(top_srcdir)"
TMP_DIR=${BUILD_DIR}/tmp
APP_DIR="${APP_DIR:-"/Applications/GNURadio.app"}"
CONTENTS_DIR=${APP_DIR}/Contents
RESOURCES_DIR=${CONTENTS_DIR}/Resources
INSTALL_DIR=${CONTENTS_DIR}/MacOS
MAKE="${MAKE:-"make -j$(ncpus)"}"
PYTHON_VERSION=3.7
PYTHON_FRAMEWORK_DIR="/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}"
PYTHON="${PYTHON_FRAMEWORK_DIR}/Resources/Python.app/Contents/MacOS/Python"
PYTHON_CONFIG="${PYTHON_FRAMEWORK_DIR}/lib/python3.7/config-3.7m-darwin/python-config.py"
INSTALL_LIB_DIR="${INSTALL_DIR}/usr/lib"
INSTALL_LIB_DIR="${INSTALL_DIR}/usr/lib"
INSTALL_PYTHON_DIR="${INSTALL_LIB_DIR}/python${PYTHON_VERSION}/site-packages"
INSTALL_GNURADIO_PYTHON_DIR="${INSTALL_DIR}/usr/share/gnuradio/python/site-packages"
export PYTHONPATH=${INSTALL_DIR}/usr/lib/python${PYTHON_VERSION}/site-packages
export SDLDIR=${INSTALL_DIR}/usr
function check_prerequisites() {
XCODE_DEVELOPER_DIR_CMD="xcode-select -p"
[[ "" = "$(${XCODE_DEVELOPER_DIR_CMD} 2>/dev/null)" ]] \
&& E "Xcode command-line developer tools are not installed. You can install them with 'xcode-select --install'"
[[ -d ${XQUARTZ_APP_DIR} ]] \
|| E "XQuartz is not installed. Download it at http://www.xquartz.org/"
[[ -d ${PYTHON_FRAMEWORK_DIR} ]] \
|| E "Python 3.7 is not installed. Download it here: https://www.python.org/downloads/"
}
function gen_version() {
local dirty
local last_tag
local last_tag_commit
local last_commit
local short_last_commit
local ver
cd ${BUILD_DIR}
last_commit="$(git rev-parse --verify HEAD)"
short_last_commit="$(git rev-parse --short HEAD)"
last_tag="$(git describe --abbrev=0 --tags)"
if git diff-index --quiet HEAD --; then
dirty=""
else
dirty="-dirty"
fi
if [ "" = "${last_tag}" ]; then
ver="${short_last_commit}"
else
last_tag_commit="$(git rev-list -n 1 ${last_tag})"
if [ "${last_tag_commit}" = "${last_commit}" -a "" = "${dirty}" ]; then
ver="${last_tag}"
else
ver="${short_last_commit}"
fi
fi
ver+=${dirty}
echo "${ver}"
}
function xpath_contains() {
local x=${1}
local y=${2}
for p in ${x/:/ }; do
if [ "${y}" = "${p}" ]; then
return 0
fi
done
return 1
}
function path_contains() {
xpath_contains ${PATH} ${1}
}
function dyldlibpath_contains() {
xpath_contains ${DYLD_LIBRARY_PATH} ${1}
}
function prefix_dyldlibpath_if_not_contained() {
local x=${1}
dyldlibpath_contains ${1} && return 0
export DYLD_LIBRARY_PATH=${1}:${DYLD_LIBRARY_PATH}
}
function prefix_path_if_not_contained() {
local x=${1}
path_contains ${1} && return 0
export PATH=${1}:${PATH}
}
function handle_hash_mismatch() {
local FILETYPE=$(file "${1}")
# Remove the mismatching file, unless we're explicitly keeping it.
[ ${KEEP_ON_MISMATCH} ] || rm -f "${1}"
# For convenience, copy the hash line to the clipboard, if desired.
[ ${COPY_HASH_ON_MISMATCH} ] && (echo "CKSUM=sha256:${3}" | pbcopy)
# And error out.
E "File '${1}' does not match '${2}'.\nActual sha256 is '${3}'.\nFile is of type '${FILETYPE}'."
}
function verify_sha256() {
#local FILENAME="${1}"
#local CKSUM="${2}"
local CKSUM="$(shasum -a 256 -- "${1}" | cut -d' ' -f1)"
test "${CKSUM}" = "${2}" \
&& D "File '${1}' matches '${2}'" \
|| handle_hash_mismatch "${1}" "${2}" "${CKSUM}" "sha256"
}
function verify_git() {
#local FILENAME="${1}"
#local CKSUM="${2}"
# Verify the hash refers to a commit.
# http://stackoverflow.com/questions/18515488/how-to-check-if-the-commit-exists-in-a-git-repository-by-its-sha-1
test "$( git -C "${1}" cat-file -t "${2}" 2>/dev/null )" = commit \
|| E "Repository '${1}' does not match '${2}'"
# Then verify the hash is in the current branch. (The branch may have newer commits.)
# http://stackoverflow.com/questions/4127967/validate-if-commit-exists
test "$( git -C "${1}" rev-list HEAD.."${2}" | wc -l )" -eq 0 \
|| E "Repository '${1}' does not match '${2}'"
}
function verify_checksum() {
#local FILENAME="${1}"
#local CKSUM="${2}"
test -e "${1}" || E "Missing: '${1}'"
if [ -z "${2}" ]; then
# Nag someone to get a checksum for this thing.
I "No checksum: '${1}'"
return 0
fi
# CKSUM is in the form of "format:data"
# (We allow additional colons in data for future whatever, format:data0:data1:...)
# Check the leading "format:" portion
case "${2%%:*}" in
"sha256")
# Remove leading "sha256:", and invoke the correct function:
verify_sha256 "${1}" "${2#*:}"
;;
"git")
# Remove leading "git:", and invoke the correct function:
verify_git "${1}" "${2#*:}"
;;
*)
E "Unrecognized checksum format: ${2}"
;;
esac
}
# XXX: @CF: use hash-checking for compressed archives
function fetch() {
local P=${1}
local URL=${2}
local T=${3}
local BRANCH=${4}
local CKSUM=${5}
local MVFROM=${6}
I "fetching ${P} from ${URL}"
if [ "git" = "${URL:0:3}" -o "" != "${BRANCH}" ]; then
D "downloading to ${TMP_DIR}/${T}"
if [ ! -d ${TMP_DIR}/${T} ]; then
git clone ${URL} ${TMP_DIR}/${T} \
|| ( rm -Rf ${TMP_DIR}/${T}; E "failed to clone from ${URL}" )
fi
cd ${TMP_DIR}/${T} \
&& git reset \
&& git checkout . \
&& git checkout master \
&& git fetch \
&& git pull \
&& git ls-files --others --exclude-standard | xargs rm -Rf \
|| ( rm -Rf ${TMP_DIR}/${T}; E "failed to pull from ${URL}" )
if [ "" != "${BRANCH}" ]; then
git branch -D local-${BRANCH} &> /dev/null || true
git checkout -b local-${BRANCH} ${BRANCH} \
|| ( rm -Rf ${TMP_DIR}/${T}; E "failed to checkout ${BRANCH}" )
fi
verify_checksum "${TMP_DIR}/${T}" "${CKSUM}"
else
if [ "" != "${SKIP_FETCH}" ]; then
local Z=
for zz in $EXTS; do
D "checking for ${TMP_DIR}/${P}.${zz}"
if [ -f ${TMP_DIR}/${P}.${zz} ]; then
Z=${P}.${zz}
D "already downloaded ${Z}"
verify_checksum "${TMP_DIR}/${Z}" "${CKSUM}"
return
fi
done
fi
cd ${TMP_DIR} \
&& curl -L --insecure -k -O ${URL} \
|| E "failed to download from ${URL}"
verify_checksum "${URL##*/}" "${CKSUM}"
fi
}
function unpack() {
local P=${1}
local URL=${2}
local T=${3}
local MVFROM="${4}"
local NAME="${5}"
if [ "" = "${T}" ]; then
T=${P}
fi
if [ "" = "${NAME}" ]; then
if [ "" = "${MVFROM}" ]; then
NAME=${P}
else
NAME=${MVFROM}
fi
fi
D "Looking for an archive matching '${NAME}'"
if [ "git" = "${URL:0:3}" -o "" != "${BRANCH}" ]; then
I "git repository has been refreshed"
else
local opts=
local cmd=
local Z=
if [ 1 -eq 0 ]; then
echo
elif [ -e ${TMP_DIR}/${NAME}.zip ]; then
Z=${NAME}.zip
cmd=unzip
elif [ -e ${TMP_DIR}/${NAME}.tar.gz ]; then
Z=${NAME}.tar.gz
cmd=tar
opts=xpzf
elif [ -e ${TMP_DIR}/${NAME}.tgz ]; then
Z=${NAME}.tgz
cmd=tar
opts=xpzf
elif [ -e ${TMP_DIR}/${NAME}.tar.bz2 ]; then
Z=${NAME}.tar.bz2
cmd=tar
opts=xpjf
elif [ -e ${TMP_DIR}/${NAME}.tbz2 ]; then
Z=${NAME}.tbz2
cmd=tar
opts=xpjf
elif [ -e ${TMP_DIR}/${NAME}.tar.xz ]; then
Z=${NAME}.tar.xz
cmd=tar
opts=xpJf
fi
I "Extracting ${Z} to ${T}"
rm -Rf ${TMP_DIR}/${T}
cd ${TMP_DIR} \
&& echo "${cmd} ${opts} ${Z}" \
&& ${cmd} ${opts} ${Z} \
|| E "failed to extract ${Z}"
fi
if [ z"${MVFROM}" != z"" ]; then
mv "${TMP_DIR}/${MVFROM}" "${TMP_DIR}/${T}"
fi
local PATCHES="$(ls -1 ${BUILD_DIR}/patches/${P}-*.patch 2>/dev/null)"
if [ "" != "${PATCHES}" ]; then
if [ ! -d ${TMP_DIR}/${T}/.git ]; then
cd ${TMP_DIR}/${T} \
&& git init \
&& git add . \
&& git commit -m 'initial commit' \
|| E "failed to initialize local git (to make patching easier)"
fi
for PP in $PATCHES; do
if [ "${PP%".sh.patch"}" != "${PP}" ]; then
# This ends with .sh.patch, so source it:
I "applying script ${PP}"
cd ${TMP_DIR}/${T} \
&& . ${PP} \
|| E "sh ${PP} failed"
else
I "applying patch ${PP}"
cd ${TMP_DIR}/${T} \
&& git apply ${PP} \
|| E "git apply ${PP} failed"
fi
done
fi
}
function build_and_install_cmake() {
set -e
local P=${1}
local URL=${2}
local CKSUM=${3}
local T=${4}
local BRANCH=${5}
local MVFROM=${6}
local NAME=${7}
export -n SHELLOPTS
if [ "" = "${T}" ]; then
T=${P}
fi
if [ -f ${TMP_DIR}/.${P}.done ]; then
I "already installed ${P}"
else
fetch "${P}" "${URL}" "${T}" "${BRANCH}" "${CKSUM}"
unpack ${P} ${URL} "${T}" "${MVFROM}" "${NAME}"
# Create our working directory, and build things there.
(
set -e
rm -Rf ${TMP_DIR}/${T}-build
mkdir ${TMP_DIR}/${T}-build
cd ${TMP_DIR}/${T}-build
# Configure and make.
cmake ${EXTRA_OPTS}
${MAKE}
${MAKE} install
) || E "failed to build ${P}"
I "finished building and installing ${P}"
touch ${TMP_DIR}/.${P}.done
fi
}
function build_and_install_meson() {
set -e
local P=${1}
local URL=${2}
local CKSUM=${3}
local T=${4}
local BRANCH=${5}
local PATHNAME=${6}
export -n SHELLOPTS
export AR="/usr/bin/ar"
if [ "" = "${T}" ]; then
T=${P}
fi
if [ -f ${TMP_DIR}/.${P}.done ]; then
I "already installed ${P}"
else
fetch "${P}" "${URL}" "${T}" "${BRANCH}" "${CKSUM}" "${PATHNAME}"
unpack ${P} ${URL} ${T} ${BRANCH} "${PATHNAME}"
rm -Rf ${TMP_DIR}/${T}-build
mkdir ${TMP_DIR}/${T}-build
cd ${TMP_DIR}/${T}
meson --prefix="${INSTALL_DIR}/usr" --buildtype=plain ${TMP_DIR}/${T}-build ${EXTRA_OPTS} && \
ninja -v -C ${TMP_DIR}/${T}-build && \
ninja -C ${TMP_DIR}/${T}-build install \
|| E "failed to build ${P}"
I "finished building and installing ${P}"
touch ${TMP_DIR}/.${P}.done
fi
}
function build_and_install_waf() {
set -e
local P=${1}
local URL=${2}
local CKSUM=${3}
local T=${4}
local BRANCH=${5}
export -n SHELLOPTS
if [ "" = "${T}" ]; then
T=${P}
fi
if [ -f ${TMP_DIR}/.${P}.done ]; then
I "already installed ${P}"
else
fetch "${P}" "${URL}" "${T}" "${BRANCH}" "${CKSUM}"
unpack ${P} ${URL} ${T} ${BRANCH}
rm -Rf ${TMP_DIR}/${T}-build \
&& mkdir ${TMP_DIR}/${T}-build \
&& cd ${TMP_DIR}/${T} \
&& ${PYTHON} ./waf configure --prefix="${INSTALL_DIR}" \
&& ${PYTHON} ./waf build \
&& ${PYTHON} ./waf install \
|| E "failed to build ${P}"
I "finished building and installing ${P}"
touch ${TMP_DIR}/.${P}.done
fi
}
function build_and_install_setup_py() {
set -e
local P=${1}
local URL=${2}
local CKSUM=${3}
local T=${4}
local BRANCH=${5}
export -n SHELLOPTS
if [ "" = "${T}" ]; then
T=${P}
fi
if [ -f ${TMP_DIR}/.${P}.done ]; then
I "already installed ${P}"
else
fetch "${P}" "${URL}" "${T}" "${BRANCH}" "${CKSUM}"
unpack ${P} ${URL} ${T}
if [ ! -d ${PYTHONPATH} ]; then
mkdir -p ${PYTHONPATH} \
|| E "failed to mkdir -p ${PYTHONPATH}"
fi
I "Configuring and building in ${T}"
cd ${TMP_DIR}/${T} \
&& \
${PYTHON} setup.py install --prefix=${INSTALL_DIR}/usr \
|| E "failed to configure and install ${P}"
I "finished building and installing ${P}"
touch ${TMP_DIR}/.${P}.done
fi
}
function build_and_install_autotools() {
set -e
local P=${1}
local URL=${2}
local CKSUM=${3}
local T=${4}
local BRANCH=${5}
local CONFIGURE_CMD=${6}
local MVFROM=${7}
export -n SHELLOPTS
if [ "" = "${CONFIGURE_CMD}" ]; then
CONFIGURE_CMD="./configure --prefix=${INSTALL_DIR}/usr"
fi
if [ "" = "${T}" ]; then
T=${P}
fi
if [ -f ${TMP_DIR}/.${P}.done ]; then
I "already installed ${P}"
else
fetch "${P}" "${URL}" "${T}" "${BRANCH}" "${CKSUM}"
unpack ${P} ${URL} ${T} ${MVFROM}
if [[ ( "" = "${SKIP_AUTORECONF}" && "" != "$(which autoreconf)" ) || ! -f ${TMP_DIR}/${T}/configure ]]; then
I "Running autoreconf in ${T}"
(
cd ${TMP_DIR}/${T}
autoreconf -if
) || E "autoreconf failed for ${P}"
fi
if [[ "" = "${SKIP_LIBTOOLIZE}" && "" != "$(which libtoolize)" ]]; then
I "Running libtoolize in ${T}"
(
cd ${TMP_DIR}/${T}
libtoolize -if
) || E "libtoolize failed for ${P}"
fi
I "Configuring and building in ${T}"
(
cd ${TMP_DIR}/${T}
I "${CONFIGURE_CMD} ${EXTRA_OPTS}"
${CONFIGURE_CMD} ${EXTRA_OPTS}
${MAKE}
${MAKE} install
) || E "failed to configure, make, and install ${P}"
I "finished building and installing ${P}"
touch ${TMP_DIR}/.${P}.done
fi
}
function build_and_install_qmake() {
set -e
local P=${1}
local URL=${2}
local CKSUM=${3}
local T=${4}
local BRANCH=${5}
export -n SHELLOPTS
if [ "" = "${T}" ]; then
T=${P}
fi
if [ -f ${TMP_DIR}/.${P}.done ]; then
I "already installed ${P}"
else
fetch "${P}" "${URL}" "${T}" "${BRANCH}" "${CKSUM}"
unpack ${P} ${URL} ${T} ${BRANCH}
I "Configuring and building in ${T}"
cd ${TMP_DIR}/${T} \
&& I "qmake ${EXTRA_OPTS}" \
&& qmake ${EXTRA_OPTS} \
&& ${MAKE} \
&& ${MAKE} install \
|| E "failed to make and install ${P}"
I "finished building and installing ${P}"
touch ${TMP_DIR}/.${P}.done
fi
}
#
# Function that builds and installs a given SoapySDR plugin as needed.
#
function install_soapy_plugin_if_needed() {
P=Soapy${1}
COMMIT=${2}
EXTRA_ARGS=${3}
URL="git://github.com/pothosware/${P}.git"
EXTRA_OPTS="\
-DCMAKE_MACOSX_RPATH=OLD \
-DCMAKE_INSTALL_NAME_DIR=${INSTALL_DIR}/usr/lib \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}/usr \
-DPYTHON3_EXECUTABLE=$(which ${PYTHON}) \
-DPYTHON3_CONFIG_EXECUTABLE=${PYTHON_CONFIG} \
-DPYTHON_EXECUTABLE=$(which ${PYTHON}) \
-DCMAKE_IGNORE_PATH=/usr/local/lib;/usr/local/include \
${EXTRA_ARGS} \
${TMP_DIR}/${P}" \
build_and_install_cmake \
${P} \
${URL} \
git:${COMMIT} \
${P} \
${COMMIT}
}
#
# Function that installs a bladeRF FPGA bitstream to the appropriate target location.
#
function install_bladerf_bitstream_if_needed() {
P=bladeRF-bitstream-${1}
T="hosted${1}-latest.rbf"
URL="https://www.nuand.com/fpga/${T}"
CKSUM="sha256:${2}"
# Install to a location where libbladerf will look.
INSTALL_TO="${INSTALL_DIR}/usr/share/Nuand/bladeRF"
if [ -f ${TMP_DIR}/.${P}.done ]; then
I already installed ${P}
else
I installing bladeRF bitstream ${P}
# Fetch the bitstream, and install it.
fetch "${P}" "${URL}" "${P}" "" "${CKSUM}"
mkdir -p "${INSTALL_TO}"
cp "${TMP_DIR}/${T}" "${INSTALL_TO}/hosted${1}.rbf"
# Mark the package as installed.
touch ${TMP_DIR}/.${P}.done
fi
}
#
# Function that replaces malformed/bad dylib paths with fully-resolved one.
# Many of these tools require extensive patching to get @rpaths to be generated
# correctly on macOS. Instead of carrying around a huge patch weight, we'll taken
# on the Cursed (TM) solution of manually resolving the dylib paths ourselves.
#
function replace_bad_dylib_paths() {
(
set -e
local new_working_directory=${1}
# If we have a directory to apply to, CD to it first.
if [ "" != "${new_working_directory}" ]; then
cd ${new_working_directory}
fi
# Grab a set of files that could be our messed-up libraries.
potential_files=$(find . -name '*.dylib' -o -name '*.so' -o \( -perm "+111" -type f \))
# Iterate over our files...
for file in $potential_files; do
# Grab the file's type...
file_type=$(file ${file})
# ... and skip the file if it's not a Mach-O library.
if [[ ${file_type} != *"Mach-O 64-bit"* ]]; then
continue
fi
# Grab a list of library paths that may have issues.
# Note that this works even for files that aren't libraries; as they just report "not an object file".
otool_paths=$(otool -L ${file} || true)
# Check each of the paths for @rpath, and then replace it accordingly.
IFS=$'\n'
for path in $otool_paths; do
name=$(basename ${path})
# Grab the path section of the otool output.
original_path=$(echo $path | cut -d ' ' -f 1 | tr -d '[:space:]:')
# Replace the problematic section of any @rpath-containing lines with a correct prefix.
if [[ $path == *"@rpath"* ]] || [[ $path == "@rpath"* ]]; then
new_path=${original_path/@rpath/"${INSTALL_DIR}/usr/lib"}
D Replacing @rpath references in "${name} (${original_path} -> ${new_path}"
install_name_tool -change "${original_path}" "${new_path}" ${file}
fi
# If the path doesn't start with "/", it's relative. We'll assueme the relevant
# library is in our standard library path, and add that as a prefix.
if [[ ${original_path} != "/"* ]]; then
new_path="${INSTALL_DIR}/usr/lib/${original_path}"
# Remove a leading "./" in the relevant path, for cleanliness.
new_path=$(echo ${new_path} | sed "s|\\./||")
D Replacing relative references in "${name} (${original_path} -> ${new_path}"
install_name_tool -change "${original_path}" "${new_path}" ${file}
fi
done
done
)
}
#function create_icns_via_cairosvg() {
# local input="${1}"
# local output="${2}"
# local T="$(dirname ${output})/iconbuilder.iconset"
#
# mkdir -p ${T} \
# && cd ${T} \
# && for i in 16 32 128 256 512; do
# j=$((2*i)) \
# && I creating icon_${i}x${i}.png \
# && cairosvg ${input} -W ${i} -H ${i} -o ${T}/icon_${i}x${i}.png \
# && I creating icon_${i}x${i}@2x.png \
# && cairosvg ${input} -W ${j} -H ${j} -o ${T}/icon_${i}x${i}@2x.png \
# || E failed to create ${i}x${i} or ${i}x${i}@2x icons; \
# done \
# && iconutil -c icns -o ${output} ${T} \
# && I done creating ${output} \
# || E failed to create ${output} from ${input}
#}
#function create_icns_via_rsvg() {
# local input="${1}"
# local output="${2}"
# local T="$(dirname ${output})/iconbuilder.iconset"
#
# mkdir -p ${T} \
# && cd ${T} \
# && for i in 16 32 128 256 512; do
# j=$((2*i)) \
# && I creating icon_${i}x${i}.png \
# && rsvg-convert ${input} -W ${i} -H ${i} -o ${T}/icon_${i}x${i}.png \
# && I creating icon_${i}x${i}@2x.png \
# && rsvg-convert ${input} -W ${j} -H ${j} -o ${T}/icon_${i}x${i}@2x.png \
# || E failed to create ${i}x${i} or ${i}x${i}@2x icons; \
# done \
# && iconutil -c icns -o ${output} ${T} \
# && I done creating ${output} \
# || E failed to create ${output} from ${input}
#}
#
# main
#
I "BUILD_DIR = '${BUILD_DIR}'"
I "INSTALL_DIR = '${INSTALL_DIR}'"
I "TMP_DIR = '${TMP_DIR}'"
check_prerequisites
#rm -Rf ${TMP_DIR}
mkdir -p ${BUILD_DIR} ${TMP_DIR} ${INSTALL_DIR}
cd ${TMP_DIR}
prefix_path_if_not_contained ${INSTALL_DIR}/usr/bin
# Update our general compiler flags to reference our local include paths.
export CFLAGS="-I${INSTALL_DIR}/usr/include -I/opt/X11/include"
export CPPFLAGS=${CFLAGS}
export CXXFLAGS=${CFLAGS}
export CC="clang -mmacosx-version-min=10.7"
export CXX="clang++ -mmacosx-version-min=10.7 -stdlib=libc++"
export LDFLAGS="-Wl,-undefined,error -L${INSTALL_DIR}/usr/lib -L/opt/X11/lib -Wl,-rpath,${INSTALL_DIR}/usr/lib -Wl,-rpath,/opt/X11/lib"
export PKG_CONFIG_PATH="${INSTALL_DIR}/usr/lib/pkgconfig:/opt/X11/lib/pkgconfig"
unset DYLD_LIBRARY_PATH
#
# Provide several optional tools for debugging.
# build.sh can be invoked with these to help debug our output.
#
if [ "${1}" == "setup-environment" ]; then
I "Environment set up; aborting now."
return
fi
if [ "${1}" == "shell" ]; then
I "Running an in-envrionment shell."
# Set up our environment, a little.
export PYTHONPATH="${PYTHONPATH}:${INSTALL_DIR}/usr/share/gnuradio/python/site-packages/"
export XDG_DATA_DIRS="${INSTALL_DIR}/usr/share"
export -n SHELLOPTS
cd ${TMP_DIR}
bash
exit 0
fi
if [ "${1}" == "python" ]; then
I "Running an in-environment python shell."
shift
${PYTHON} "$@"
exit 0
fi
if [ "${1}" == "grc" ]; then
I "Attempting to start gnuradio-companion from the build tree."
# Set up our environment, a little.
export PYTHONPATH="${PYTHONPATH}:${INSTALL_DIR}/usr/share/gnuradio/python/site-packages/"
export XDG_DATA_DIRS="${INSTALL_DIR}/usr/share"
gnuradio-companion
exit 0
fi
if [ "${1}" == "post-build" ]; then
I "Clearing the completion status of our post-build tasks."
rm -f ${TMP_DIR}/.post-build-fixes.done
fi
if [ "${1}" == "rebuild" ]; then
I "Rebuilding any packages called ${2}."
rm -f ${TMP_DIR}/.${2}.done
fi
if [ "${1}" == "hard-rebuild" ]; then
I "Clean rebuilding any packages called ${2}."
rm -f ${TMP_DIR}/.${2}.done
rm -rf ${TMP_DIR}/${2}
rm -rf ${TMP_DIR}/${2}-build
fi
# install wrappers for ar and ranlib, which prevent autotools from working
mkdir -p ${INSTALL_DIR}/usr/bin \
&& cp ${BUILD_DIR}/scripts/ar-wrapper.sh ${INSTALL_DIR}/usr/bin/ar \
&& chmod +x ${INSTALL_DIR}/usr/bin/ar \
&& \
cp ${BUILD_DIR}/scripts/ranlib-wrapper.sh ${INSTALL_DIR}/usr/bin/ranlib \
&& chmod +x ${INSTALL_DIR}/usr/bin/ranlib \
|| E "failed to install ar and ranlib wrappers"
[[ $(which ar) = ${INSTALL_DIR}/usr/bin/ar ]] \
|| E "sanity check failed. ar-wrapper is not in PATH"
# Create symlinks that ensure we only ever build with the user-installed python3;
# and put python3 where things expect it to be.
ln -sf ${PYTHON} ${INSTALL_DIR}/usr/bin/python
ln -sf ${PYTHON} ${INSTALL_DIR}/usr/bin/python3
ln -sf ${PYTHON_CONFIG} ${INSTALL_DIR}/usr/bin/python-config
#
# Install autoconf
#
(
P=autoconf-2.69
URL=http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
CKSUM=sha256:954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969
SKIP_AUTORECONF=yes \
SKIP_LIBTOOLIZE=yes \
build_and_install_autotools \
${P} \
${URL} \
${CKSUM}
)
#
# Install automake
#
(
P=automake-1.16
URL=http://ftp.gnu.org/gnu/automake/${P}.tar.gz
CKSUM=sha256:80da43bb5665596ee389e6d8b64b4f122ea4b92a685b1dbd813cd1f0e0c2d83f
SKIP_AUTORECONF=yes
SKIP_LIBTOOLIZE=yes
build_and_install_autotools \
${P} \
${URL} \
${CKSUM}
)
#
# Install libtool
#
(
P=libtool-2.4.6
URL="http://gnu.spinellicreations.com/libtool/${P}.tar.xz"
CKSUM=sha256:7c87a8c2c8c0fc9cd5019e402bed4292462d00a718a7cd5f11218153bf28b26f
SKIP_AUTORECONF=yes
SKIP_LIBTOOLIZE=yes
build_and_install_autotools \
${P} \
${URL} \
${CKSUM} \
"" \
"" \
"./configure --prefix=${INSTALL_DIR}/usr"
)
#
# Install sed
#
(
P=sed-4.7
URL=http://ftp.gnu.org/pub/gnu/sed/${P}.tar.xz
CKSUM=sha256:2885768cd0a29ff8d58a6280a270ff161f6a3deb5690b2be6c49f46d4c67bd6a
SKIP_AUTORECONF=true
SKIP_LIBTOOLIZE=true
build_and_install_autotools \
${P} \
${URL} \
${CKSUM}
)
#
# Install libunistring
#
(
V=0.9.10
P=libunistring-${V}
URL=http://ftp.gnu.org/pub/gnu/libunistring/${P}.tar.xz
CKSUM=sha256:eb8fb2c3e4b6e2d336608377050892b54c3c983b646c561836550863003c05d7
build_and_install_autotools \
${P} \
${URL} \
${CKSUM}
)