forked from part-cw/lambdanative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·1687 lines (1617 loc) · 46.3 KB
/
make.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
# LambdaNative - a cross-platform Scheme framework
# Copyright (c) 2009-2013, University of British Columbia
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the
# following conditions are met:
#
# * Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# * Neither the name of the University of British Columbia nor
# the names of its contributors may be used to endorse or
# promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# application building, packaging and installation
. ./config.cache
. ./SETUP
evallog=`pwd`"/eval.log"
if [ -f $evallog ]; then
rm $evallog
fi
#########################
# general functions
# since os x doesn't have md5sum
md5summer=md5sum
if [ "X"`which md5sum 2> /dev/null` = "X" ]; then
md5summer="md5 -r"
fi
veval()
{
if [ $SYS_VERBOSE ]; then
echo "$1"
eval $1
else
echo "$1" > $evallog
eval $1 >> $evallog 2>&1
fi
}
vecho()
{
if [ $SYS_VERBOSE ]; then
echo "$1"
fi
}
getparam()
{
if [ "$1" = "1" ]; then echo "$2"; fi
if [ "$1" = "2" ]; then echo "$3"; fi
if [ "$1" = "3" ]; then echo "$4"; fi
if [ "$1" = "4" ]; then echo "$5"; fi
if [ "$1" = "5" ]; then echo "$6"; fi
}
rmifexists()
{
if [ "$1" ]; then
if [ -e "$1" ]; then
vecho " => removing old $1.."
rm -rf "$1"
fi
fi
}
###############################
# keep track of state to reset partial builds
statefile=`pwd`"/make.state"
setstate()
{
echo "state=$1" > $statefile
}
resetstate()
{
state=
if [ -f $statefile ]; then
. $statefile
rm $statefile
fi
if [ ! "X$state" = "X" ]; then
echo " ** WARNING: previous build aborted unexpectantly in state: $state"
case $state in
ARTWORK)
file=`locatefile apps/$SYS_APPNAME/artwork.eps silent`
if [ -f $file ]; then
touch $file
fi
;;
STRINGS)
file="$SYS_PREFIXROOT/build/$SYS_APPNAME/strings/strings_include.scm"
rmifexists $file
;;
FONTS)
file="$SYS_PREFIXROOT/build/$SYS_APPNAME/fonts/fonts_include.scm"
rmifexists $file
;;
TEXTURES)
file="$SYS_PREFIXROOT/build/$SYS_APPNAME/textures/textures_include.scm"
rmifexists $file
;;
esac
fi
}
#################################
# abort on missing files and errors
assertfile()
{
if [ ! -e "$1" ]; then
if [ -f $evallog ]; then
cat $evallog | sed '/^$/d'
fi
echo "ERROR: failed on file $1" 1>&2
exit 1
fi
}
asserterror()
{
if [ ! $1 = 0 ]; then
if [ -f $evallog ]; then
cat $evallog | sed '/^$/d'
fi
echo "ERROR: failed with exit code $1" 1>&2
exit 1
fi
}
#################################
# misc file and directory support
stringhash()
{
echo "$1" | $md5summer | cut -f 1 -d " "
}
isnewer()
{
result=no
if [ ! -e "$2" ]; then
result=yes
else
if `test "$1" -nt "$2"`; then
result=yes
fi
fi
echo $result
}
newersourceindir()
{
result="no"
tgt="$2"
dir=`dirname $1`
srcfiles=`ls -1 $dir/*.scm`
for src in $srcfiles; do
if `test "$src" -nt "$tgt"`; then
result="yes"
fi
done
echo $result
}
newerindir()
{
result="no"
tgt="$2"
if [ -d $1 ]; then
dir=$1
else
dir=`dirname $1`
fi
srcfiles=`ls -1 $dir/*`
for src in $srcfiles; do
if `test "$src" -nt "$tgt"`; then
result="yes"
fi
done
echo $result
}
locatetest()
{
here=`pwd`
file=
dirs=$(echo "$SYS_PATH" | tr ":" "\n")
for dir in $dirs; do
tmp="$dir/$2"
if [ ! "X$tmp" = "X" ]; then
if [ $1 $tmp ]; then
if [ "X$file" = "X" ]; then
file=$tmp
else
if [ ! "X$3" = "Xsilent" ]; then
echo "WARNING: $file shadows $tmp" 1>&2
fi
fi
fi
fi
done
if [ "X$file" = "X" ]; then
if [ ! "X$3" = "Xsilent" ]; then
echo "WARNING: [$2] not found" 1>&2
fi
fi
if [ ! -e $file ]; then
if [ ! "X$3" = "Xsilent" ]; then
echo "WARNING: [$2] not found" 1>&2
fi
fi
cd "$here"
echo $file
}
locatedir()
{
locatetest "-d" $@
}
locatefile()
{
locatetest "-f" $@
}
wildcard_dir()
{
find $1 -maxdepth 0 -print |sort -r| head -n 1
}
#################################
# autoconf-like parameter substitution
ac_sedsub=
ac_subst()
{
newcmd="echo \"s|@${1}@|\$${1}|g;\""
newsub=`eval $newcmd`
ac_sedsub="${ac_sedsub}${newsub}"
}
ac_output()
{
infile=`echo "${1}" | sed 's/\.in$//'`.in
if [ "X$2" = "X" ]; then
outfile=$1
else
outfile=$2
fi
assertfile $infile
cat $infile | sed "$ac_sedsub" > $outfile
assertfile $outfile
}
#################################
# misc source code checks
has_module()
{
res=no
modfile=`locatefile apps/$SYS_APPNAME/MODULES`
if [ -f "$modfile" ]; then
if [ ! "X"`cat "$modfile" | grep "$1" | cut -c 1` = "X" ]; then
res=yes
fi
fi
echo $res
}
is_gui_app()
{
res=`has_module ln_glcore`
if [ "$res" = "no" ]; then
res=`has_module glcore`
fi
echo "$res"
}
is_standalone_app()
{
neg=`has_module eventloop`
if [ $neg = no ]; then
neg=yes
else
neg=no
fi
echo $neg
}
###########################
# general compiler functions
compile()
{
if [ $SYS_MODE = "debug" ]; then
opts="(declare (block)(not safe)(debug)(debug-location))"
optc="-g -Wall -Wno-unused-variable -Wno-unused-label -Wno-unused-parameter"
else
opts="(declare (block)(not safe))"
optc="-O2 -Wall -Wno-unused-variable -Wno-unused-label -Wno-unused-parameter"
fi
src="$1"
ctgt="$2"
otgt="$3"
defs="$4"
path=`dirname $src`
here=`pwd`
cd $path
rmifexists "$ctgt"
echo " => $src.."
veval "$SYS_GSC -prelude \"$opts\" -c -o $ctgt $src"
assertfile "$ctgt"
rmifexists "$otgt"
veval "$SYS_CC $SYS_CPPFLAGS $SYS_CFLAGS $defs -c -o $otgt $ctgt -I$SYS_PREFIX/include"
assertfile "$otgt"
cd $here
}
compile_payload()
{
name=$1
srcs="$2"
csrcs=
libs="$3"
objs=
defs="-D___SINGLE_HOST -D___LIBRARY -D___PRIMAL"
echo "==> creating payload needed for $name.."
mkdir -p "$SYS_PREFIX/build"
dirty=
for src in $srcs; do
chsh=`stringhash "$src"`
ctgt="$SYS_PREFIX/build/$chsh.c"
csrcs="$csrcs $ctgt"
otgt=`echo "$ctgt" | sed 's/c$/o/'`
objs="$objs $otgt"
flag=
if [ ! -f "$otgt" ]; then
flag=yes
else
if [ `newersourceindir "$src" "$otgt"` = "yes" ]; then
flag=yes
fi
fi
if [ $flag ]; then
dirty=yes
compile "$src" "$ctgt" "$otgt" "$defs"
fi
done
lctgt=`echo "$ctgt" | sed 's/\.c$/\_\.c/'`
lotgt=`echo "$lctgt" | sed 's/c$/o/'`
if [ ! -f "$lotgt" ]; then
dirty=yes
fi
if [ $dirty ]; then
echo " => creating gsc link.."
vecho "$SYS_GSC -link $csrcs"
$SYS_GSC -link $csrcs
assertfile $lctgt
veval "$SYS_CC $SYS_CPPFLAGS $SYS_CFLAGS $defs -o $lotgt -c $lctgt -I$SYS_PREFIX/include"
assertfile $lotgt
fi
objs="$objs $lotgt"
hookhash=`stringhash "apps/$SYS_APPNAME/hook.c"`
hctgt="$SYS_PREFIX/build/$hookhash.c"
hotgt=`echo "$hctgt" | sed 's/c$/o/'`
if [ ! -f "$hotgt" ]; then
dirty=yes
fi
if [ $dirty ]; then
echo " => generating hook.."
linker=`echo $chsh"__"`
cat > $hctgt << _EOF
// automatically generated. Do not edit.
#include <stdlib.h>
#include <CONFIG.h>
#define ___VERSION 407000
#include <gambit.h>
#define LINKER ____20_$linker
___BEGIN_C_LINKAGE
extern ___mod_or_lnk LINKER (___global_state_struct*);
___END_C_LINKAGE
___setup_params_struct setup_params;
int debug_settings = ___DEBUG_SETTINGS_INITIAL;
#ifdef STANDALONE
char *cmd_arg1=0;
int main(int argc, char *argv[])
{
if (argc>1) cmd_arg1=argv[1];
___setup_params_reset (&setup_params);
setup_params.version = ___VERSION;
setup_params.linker = LINKER;
debug_settings = (debug_settings & ~___DEBUG_SETTINGS_REPL_MASK) |
(___DEBUG_SETTINGS_REPL_STDIO << ___DEBUG_SETTINGS_REPL_SHIFT);
setup_params.debug_settings = debug_settings;
___setup(&setup_params);
___cleanup();
return 0;
}
#else
void ffi_event(int t, int x, int y)
{
static int lock=0;
static int gambitneedsinit=1;
if (lock) { return; } else { lock=1; }
if (gambitneedsinit) {
___setup_params_reset (&setup_params);
setup_params.version = ___VERSION;
setup_params.linker = LINKER;
debug_settings = (debug_settings & ~___DEBUG_SETTINGS_REPL_MASK) |
(___DEBUG_SETTINGS_REPL_STDIO << ___DEBUG_SETTINGS_REPL_SHIFT);
setup_params.debug_settings = debug_settings;
___setup(&setup_params);
gambitneedsinit=0;
}
if (!gambitneedsinit) scm_event(t,x,y);
if (t==EVENT_TERMINATE) { ___cleanup(); exit(0); }
lock=0;
}
#endif
_EOF
if [ `is_standalone_app` = "yes" ]; then
defs="$defs -DSTANDALONE"
fi
veval "$SYS_CC $SYS_CPPFLAGS $SYS_CFLAGS $defs -c -o $hotgt $hctgt -I$SYS_PREFIX/include"
assertfile $hotgt
fi
objs="$objs $hotgt"
for lib in $libs; do
objs=`ls -1 $SYS_PREFIX/build/$lib/*.o`" $objs"
done
tgtlib="$SYS_PREFIX/lib/libpayload.a"
echo " => assembling payload.."
sobjs=
for obj in $objs; do
sobjs="$sobjs $obj"
done
rmifexists "$tgtlib"
vecho "$SYS_AR rc $tgtlib $sobjs"
$SYS_AR rc $tgtlib $sobjs 2> /dev/null
vecho "$SYS_RANLIB $tgtlib"
$SYS_RANLIB $tgtlib 2> /dev/null
assertfile "$tgtlib"
}
##################################
# extract object files from static library
explode_library()
{
libname=$1
libfile="$SYS_PREFIX/lib/$libname.a"
libdir="$SYS_PREFIX/build/$libname"
assertfile $libfile
if [ `isnewer $libfile $libdir` = "yes" ]; then
rmifexists "$libdir"
echo " => exploding library $libname.."
mkdir -p "$libdir"
here=`pwd`
cd "$libdir"
$SYS_AR -x $libfile
cd "$here"
fi
}
###################################
# artwork & texture generation
make_artwork()
{
setstate ARTWORK
echo "==> creating artwork needed for $SYS_APPNAME.."
objsrc=`locatefile "apps/$SYS_APPNAME/artwork.obj" silent`
epssrc=`locatefile "apps/$SYS_APPNAME/artwork.eps" silent`
if [ "X$epssrc" = "X" ]; then
assertfile $objsrc
epssrc=`echo $objsrc | sed 's/obj$/eps/'`
fi
if [ `isnewer $objsrc $epssrc` = "yes" ]; then
if [ ! "X$objsrc" = "X" ]; then
assertfile $objsrc
echo " => generating eps artwork.."
tgif -print -stdout -eps -color $objsrc > $epssrc
fi
fi
assertfile $epssrc
mkdir -p "$SYS_PREFIX/build"
mkdir -p "$SYS_PREFIXROOT/build/$SYS_APPNAME"
pngsrc="$SYS_PREFIXROOT/build/$SYS_APPNAME/artwork.png"
tmpfile="$SYS_PREFIXROOT/build/$SYS_APPNAME/tmp.png"
if [ `isnewer $epssrc $pngsrc` = "yes" ]; then
echo " => generating master pixmap.."
veval "gs -r600 -dNOPAUSE -sDEVICE=png16m -dEPSCrop -sOutputFile=$tmpfile $epssrc quit.ps"
assertfile $tmpfile
veval "convert $tmpfile -trim -transparent \"#00ff00\" $pngsrc"
rm $tmpfile
fi
assertfile $pngsrc
# the crazy list of artwork sizes:
# 1024: iTunes
# 512: google play
# 144: retina ipad
# 128: macosx
# 114: retina iphone
# 96: Retina iPad spotlight, android launcher
# 72: ipad, android launcher
# 58: iphone 4 settings
# 57: iphone
# 48: iPad Spotlight, android launcher, macosx
# 36: android launcher
# 32: macosx
# 29: iphone settings
# 16: macosx
sizes="1024 512 144 128 114 96 72 58 57 48 36 32 29 16"
for s in $sizes; do
tgt="$SYS_PREFIXROOT/build/$SYS_APPNAME/artwork-$s.png"
if [ `isnewer $epssrc $tgt` = "yes" ]; then
echo " => generating "$s"x"$s" pixmap.."
convert $pngsrc -resize $s"x"$s $tgt
assertfile $tgt
fi
done
# create a dummy splash image to get full screen on retina displays
tgt="$SYS_PREFIXROOT/build/$SYS_APPNAME/retina.png"
if [ ! -f "$tgt" ]; then
echo " => generating retina default image.."
convert -size 640x1136 xc:black $tgt
fi
assertfile $tgt
setstate
}
make_textures()
{
setstate TEXTURES
echo "==> creating textures needed for $SYS_APPNAME.."
srcdir=`locatedir apps/$SYS_APPNAME/textures silent`
if [ "X" == "X$srcdir" ]; then
return
fi
tgtdir=$SYS_PREFIXROOT/build/$SYS_APPNAME/textures
mkdir -p $tgtdir
incfile=$tgtdir/textures_include.scm
images=`ls -1 "$srcdir"/*.png 2> /dev/null`
dirty="no"
empty=yes
for imgfile in $images; do
empty=no
if [ `isnewer $imgfile $incfile` = "yes" ]; then
dirty="yes"
fi
done
if [ "$dirty" = "yes" ]; then
echo ";; Automatically generated. Do not edit." > $incfile
if [ -d "$srcdir" ]; then
for imgfile in $images; do
scmfile=$SYS_PREFIXROOT/build/$SYS_APPNAME/textures/`basename $imgfile | sed 's/png$/scm/'`
if [ `isnewer $imgfile $scmfile` = "yes" ]; then
echo " => $imgfile.."
$SYS_HOSTPREFIX/bin/png2scm $imgfile > $scmfile
fi
echo "(include \"$scmfile\")" >> $incfile
done
fi
echo ";; eof" >> $incfile
fi
if [ "$empty" = "yes" ]; then
if [ ! -e $incfile ]; then
touch $incfile
fi
fi
setstate
}
make_fonts()
{
setstate FONTS
echo "==> creating fonts needed for $SYS_APPNAME.."
tgtdir=$SYS_PREFIXROOT/build/$SYS_APPNAME/fonts
mkdir -p $tgtdir
srcfile=`locatefile apps/$SYS_APPNAME/FONTS silent`
if [ "X$srcfile" = "X" ]; then
touch $tgtdir/fonts_include.scm
else
incfile=$tgtdir/fonts_include.scm
if [ `isnewer $srcfile $incfile` = "yes" ]; then
echo ";; Automatically generated. Do not edit." > $incfile
while read line; do
fline=`echo "$line" | sed '/^#/d'`
if [ "$fline" ]; then
fontname=`echo "$fline" | cut -f 1 -d " "`
font=`locatefile fonts/$fontname`
assertfile $font
bits=`echo "$fline" | cut -f 2 -d " "`
sizes=`echo "$fline" | cut -f 3 -d " "`
name=`echo "$fline" | cut -f 4 -d " "`
scmfile=$tgtdir/${name}.scm
if [ `isnewer $srcfile $scmfile` = "yes" ]; then
echo " => $name.."
$SYS_HOSTPREFIX/bin/ttffnt2scm $font $bits $sizes $name > $scmfile
fi
echo "(include \"$scmfile\")" >> $incfile
fi
done < $srcfile
echo ";; eof" >> $incfile
fi
fi
setstate
}
make_string_aux()
{
oldpath=`pwd`
newpath=`mktemp -d tmp.XXXXXX`
cd $newpath
srcfont=$1
fontname=`$SYS_HOSTPREFIX/bin/ttfname $srcfont`
tgtfont="$fontname".ttf
cp $srcfont $tgtfont
fontpath=`pwd`"/"
size=$2
string="$3"
name=$4
opt="$5"
cat > tmp.tex << __EOF
\documentclass{article}
\makeatletter
\renewcommand{\Large}{\@setfontsize\Large{$size}{$size}}
\makeatother
\usepackage{fontspec}
\usepackage{xunicode}
%\fontspec [ Path = $fontpath ]{$fontname}
\setmainfont[$opt]{"[$fontname.ttf]"}
\usepackage[margin=0.1in, paperwidth=40in, paperheight=2in]{geometry}
\begin{document}
\thispagestyle{empty}
\noindent \Large
$string
\end{document}
__EOF
xelatex tmp.tex > /dev/null 2> /dev/null
assertfile tmp.pdf
if [ "X"`which pdftops 2> /dev/null` = "X" ]; then
pdf2ps tmp.pdf > /dev/null 2> /dev/null
else
pdftops tmp.pdf > /dev/null 2> /dev/null
fi
assertfile tmp.ps
ps2eps -B -C tmp.ps > /dev/null 2> /dev/null
assertfile tmp.eps
gs -r300 -dNOPAUSE -sDEVICE=pnggray -dEPSCrop -sOutputFile=$name.png tmp.eps quit.ps > /dev/null 2> /dev/null
assertfile $name.png
convert $name.png -bordercolor White -border 5x5 -negate -scale 25% $name.png > /dev/null 2> /dev/null
$SYS_HOSTPREFIX/bin/png2scm $name.png
cd $oldpath
rm -rf $newpath
}
make_strings()
{
setstate STRINGS
echo "==> creating strings needed for $SYS_APPNAME.."
tgtdir=$SYS_PREFIXROOT/build/$SYS_APPNAME/strings
mkdir -p $tgtdir
incfile=$tgtdir/strings_include.scm
srcfile=`locatefile apps/$SYS_APPNAME/STRINGS silent`
if [ "X$srcfile" = "X" ]; then
touch $incfile
else
assertfile $srcfile
if [ `isnewer $srcfile $incfile` = "yes" ]; then
cat $srcfile | sed '/^#/d' > $tgtdir/STRINGS
echo ";; Automatically generated. Do not edit." > $incfile
while read -r fline; do
# fline=`echo "$line" | sed '/^#/d'`
if [ "$fline" ]; then
fontname=`eval "getparam 1 $fline"`
font=`locatefile fonts/$fontname`
assertfile $font
size=`eval "getparam 2 $fline"`
label=`eval "getparam 3 $fline" | sed 's:_/:@TMP@:g;s:/:\\\\:g;s:@TMP@:/:g'`
name=`eval "getparam 4 $fline"`
opt=`eval "getparam 5 $fline"`
scmfile=$tgtdir/${name}.scm
if [ `isnewer $srcfile $scmfile` = "yes" ]; then
echo " => $name.."
# echo "$SYS_HOSTPREFIX/bin/ttfstr2scm $font $size \"$label\" $name > $scmfile"
# $SYS_HOSTPREFIX/bin/ttfstr2scm $font $size "$label" $name > $scmfile
make_string_aux $font $size "$label" $name $opt > $scmfile
fi
echo "(include \"$scmfile\")" >> $incfile
fi
done < $tgtdir/STRINGS
echo ";; eof" >> $incfile
fi
fi
setstate
}
###################################
# platform specific stuff
make_setup()
{
profile=`locatefile PROFILE`
assertfile "$profile"
. "$profile"
versionfile=`locatefile apps/$SYS_APPNAME/VERSION`
assertfile $versionfile
SYS_APPVERSION=`cat $versionfile`
SYS_APPVERSIONCODE=`echo $SYS_APPVERSION | sed 's/\.//'`
echo "=== using profile $SYS_PROFILE [$profile].."
echo "=== configured to build $SYS_APPNAME version $SYS_APPVERSION for $SYS_PLATFORM on $SYS_HOSTPLATFORM in $SYS_MODE mode"
if [ "$SYS_MODE" = "release" ]; then
SYS_IOSCERT=$SYS_IOSRELCERT
else
SYS_IOSCERT=$SYS_IOSDEVCERT
fi
SYS_PREFIXROOT=`pwd`"-cache"
SYS_PREFIX="$SYS_PREFIXROOT/$SYS_PLATFORM"
SYS_HOSTPREFIX="$SYS_PREFIXROOT/$SYS_HOSTPLATFORM"
SYS_GSC=$SYS_HOSTPREFIX/bin/gsc
SYS_DEBUGFLAG=
if [ "X$SYS_MODE" = "Xdebug" ]; then
SYS_DEBUGFLAG="-g"
fi
mkdir -p $SYS_PREFIX/bin
mkdir -p $SYS_PREFIX/lib
mkdir -p $SYS_PREFIX/include
mkdir -p $SYS_PREFIX/build
mkdir -p $SYS_HOSTPREFIX/bin
mkdir -p $SYS_HOSTPREFIX/lib
mkdir -p $SYS_HOSTPREFIX/include
mkdir -p $SYS_PREFIXROOT/packages
mkdir -p $SYS_PREFIXROOT/build
buildsys=$SYS_PLATFORM"_"$SYS_HOSTPLATFORM
case "$buildsys" in
win32_macosx|win32_linux)
SDKROOT=$WIN32SDK/i?86*-mingw32
CROSS=$WIN32SDK/bin/i?86*-mingw32-
SYS_CC=$CROSS"gcc $SYS_DEBUGFLAG -isysroot $SDKROOT -DWIN32"
SYS_AR=$CROSS"ar"
SYS_RANLIB=$CROSS"ranlib"
SYS_STRIP=$CROSS"strip"
SYS_WINDRES=$CROSS"windres"
SYS_EXEFIX=".exe"
SYS_APPFIX=
;;
linux_macosx)
SDKROOT=$LINUXSDK/i?86-linux
CROSS=$LINUXSDK/bin/i?86-linux-
## fixme: should be no need to include /usr/local/linux/i686-linux/include
SYS_CC=$CROSS"gcc $SYS_DEBUGFLAG -isysroot $SDKROOT -DLINUX -I/usr/local/linux/i686-linux/include"
SYS_AR=$CROSS"ar"
SYS_RANLIB=$CROSS"ranlib"
SYS_STRIP=$CROSS"strip"
SYS_WINDRES=
SYS_EXEFIX=
SYS_APPFIX=
;;
linux_linux)
SYS_CC="gcc $SYS_DEBUGFLAG -m32 -DLINUX"
SYS_AR=ar
SYS_RANLIB=ranlib
SYS_STRIP=strip
SYS_WINDRES=
SYS_EXEFIX=
SYS_APPFIX=
;;
openbsd_openbsd)
SYS_CC="gcc $SYS_DEBUGFLAG -DOPENBSD -I/usr/X11R6/include"
SYS_AR=ar
SYS_RANLIB=ranlib
SYS_STRIP=strip
SYS_WINDRES=
SYS_EXEFIX=
SYS_APPFIX=
;;
macosx_macosx)
SYS_CC=gcc
SYS_CC="$SYS_CC $SYS_DEBUGFLAG -m32 -DMACOSX"
SYS_AR=ar
SYS_RANLIB=ranlib
SYS_STRIP=strip
SYS_WINDRES=
SYS_EXEFIX=
SYS_APPFIX=.app
;;
ios_macosx)
SYS_IOSSDK=`basename $IOSSDK`
SYS_IOSVERSION=$IOSVERSION
CROSS=$IOSROOT/usr/bin
SYS_CC=`ls -1 $CROSS/arm-apple-darwin*-gcc-* | sort -r | sed '/llvm/d' | head -n 1`
if [ "X$SYS_CC" = "X" ]; then
SYS_CC=`ls -1 $CROSS/arm-apple-darwin*-gcc-* | sort -r | head -n 1`
fi
if [ "X$SYS_CC" = "X" ]; then
SYS_CC=`ls -1 $CROSS/arm-apple-darwin*-llvm-* | sort -r | head -n 1`
fi
assertfile $SYS_CC
SYS_CC="$SYS_CC $SYS_DEBUGFLAG -isysroot $IOSSDK -DIOS -DIPHONE -miphoneos-version-min=$SYS_IOSVERSION"
SYS_CC="$SYS_CC -fPIC -fsigned-char -fomit-frame-pointer -fforce-addr"
SYS_AR="$CROSS/ar"
SYS_RANLIB="$CROSS/ranlib"
SYS_STRIP="$CROSS/strip"
SYS_WINDRES=
SYS_EXEFIX=
SYS_APPFIX=".app"
;;
android_macosx|android_linux)
# TOOLCHAIN=`echo $ANDROIDNDK/toolchains/arm-*/prebuilt/*-x86`
TOOLCHAIN=`wildcard_dir $ANDROIDNDK/toolchains/arm-*/prebuilt/*-x86 2> /dev/null`
if [ "X$TOOLCHAIN" = "X" ]; then
TOOLCHAIN=`wildcard_dir $ANDROIDNDK/toolchains/arm-*/prebuilt/*-x86_64 2> /dev/null`
fi
assertfile "$TOOLCHAIN"
# SYSROOT=`wildcard_dir $ANDROIDNDK/platforms/android-*/arch-arm`
SYSROOT=`echo $ANDROIDNDK/platforms/android-9/arch-arm`
assertfile "$SYSROOT"
CROSS="$TOOLCHAIN/bin/arm-linux-androideabi-"
# the linker gunk is just to fool gambit's configure into thinking the gcc can make binaries
SYS_CC=$CROSS"gcc $SYS_DEBUGFLAG -DANDROID -isysroot $SYSROOT -fno-short-enums -nostdlib -I$SYSROOT/usr/include -L$SYSROOT/usr/lib -lstdc++ -lc -ldl -lgcc"
SYS_AR=$CROSS"ar"
SYS_RANLIB=$CROSS"ranlib"
SYS_STRIP=$CROSS"strip"
SYS_WINDRES=
SYS_EXEFIX=
SYS_APPFIX=
;;
esac
SYS_LOCASEAPPNAME=`echo $SYS_APPNAME | tr A-Z a-z`
SYS_ANDROIDAPI=$ANDROIDAPI
# Add git path for overlay, additional paths, and the lambdanative path
here=`pwd`
SYS_BUILDHASH=
for p in $(echo "$SYS_PATH" | tr ":" "\n"); do
cd $p
if [ -d "$p/.git" ]; then
SYS_BUILDHASH="$SYS_BUILDHASH"`basename $p`": "`git log --pretty=format:"%h" -1`","
fi
cd $here
done
SYS_BUILDHASH=`echo "$SYS_BUILDHASH" | sed 's/,$//'`
echo $SYS_BUILDHASH
SYS_BUILDEPOCH=`date +"%s"`
# Adding BUILD info requires rebuilding of config module
touch modules/config/config.scm
ac_subst SYS_ORGTLD
ac_subst SYS_ORGSLD
ac_subst SYS_APPNAME
ac_subst SYS_LOCASEAPPNAME
ac_subst SYS_IOSCERT
ac_subst SYS_IOSVERSION
ac_subst SYS_IOSSDK
ac_subst SYS_PLATFORM
ac_subst SYS_HOSTPLATFORM
ac_subst SYS_PREFIX
ac_subst SYS_PREFIXROOT
ac_subst SYS_HOSTPREFIX
ac_subst SYS_GSC
ac_subst SYS_CC
ac_subst SYS_AR
ac_subst SYS_RANLIB
ac_subst SYS_STRIP
ac_subst SYS_WINDRES
ac_subst SYS_EXEFIX
ac_subst SYS_APPFIX
ac_subst SYS_APPVERSION
ac_subst SYS_APPVERSIONCODE
ac_subst SYS_ANDROIDAPI
ac_subst SYS_BUILDHASH
ac_subst SYS_BUILDEPOCH
ac_output CONFIG.h $SYS_PREFIX/include/CONFIG.h
}
make_bootstrap()
{
setstate BOOTSTRAP
locaseappname=`echo $SYS_APPNAME | tr A-Z a-z`
here=`pwd`
echo "==> creating $SYS_PLATFORM bootstrap needed for $SYS_APPNAME.."
case $SYS_PLATFORM in
################################
ios)
tgtdir="$SYS_PREFIX/$SYS_APPNAME$SYS_APPFIX"
srcdir=`pwd`"/bootstraps/ios"
cmakedir=`mktemp -d tmp.XXXXXX`
cmakedir=`pwd`"/$cmakedir"
cd $here
ac_output $srcdir/CMakeLists.txt $cmakedir/CMakeLists.txt
cp $srcdir/*.m $cmakedir
cp $srcdir/*.mm $cmakedir
cp $srcdir/*.h $cmakedir
echo " => preparing icons.."
cp "$SYS_PREFIXROOT/build/$SYS_APPNAME/artwork-57.png" "$cmakedir/Icon.png"
cp "$SYS_PREFIXROOT/build/$SYS_APPNAME/artwork-114.png" "$cmakedir/[email protected]"
cp "$SYS_PREFIXROOT/build/$SYS_APPNAME/artwork-72.png" "$cmakedir/Icon-72.png"
cp "$SYS_PREFIXROOT/build/$SYS_APPNAME/artwork-144.png" "$cmakedir/[email protected]"
# go full screen on retina displays!
cp "$SYS_PREFIXROOT/build/$SYS_APPNAME/retina.png" "$cmakedir/[email protected]"
snddir=`locatedir apps/$SYS_APPNAME/sounds silent`
if [ -d "$snddir" ]; then
echo " => transferring sounds..."
snds=`ls -1 $snddir/*.wav`
for snd in $snds; do
# locasesnd=`basename $snd | tr A-Z a-z`
# echo " => $locasesnd.."
# cp $snd $cmakedir/$locasesnd
vecho " => $snd.."
cp $snd $cmakedir
done
fi
echo " => preparing plist.."
configsrc=`locatedir apps/$SYS_APPNAME`"/CONFIG_IOS.in"
configtgt=$SYS_PREFIXROOT/build/$SYS_APPNAME/CONFIG_IOS
ac_output $configsrc $configtgt
assertfile $configtgt
cat $configtgt | sed '/^#/d' > "$SYS_PREFIXROOT/build/$SYS_APPNAME/Info.plist"
echo "// automatically generated. Do not edit" > "$cmakedir/config.h"
cat $configtgt | sed -n '/^#+/p' | cut -f 2- -d "+" >> "$cmakedir/config.h"
echo " => building bootstrap.."
xcodedir=`mktemp -d tmp.XXXXXX`
xcodedir=`pwd`"/$xcodedir"
cd $here
cd $xcodedir
veval "cmake -GXcode $cmakedir"
asserterror $?
# xcodebuild -configuration Release | grep -A 2 error
veval "xcodebuild -configuration Release"
asserterror $?
cd $here
tmpappdir=$xcodedir/Release-iphoneos/$SYS_APPNAME$SYS_APPFIX
if [ ! -d $tmpappdir ]; then
tmpappdir=$xcodedir/Release/$SYS_APPNAME$SYS_APPFIX
fi
assertfile $tmpappdir
echo " => verifying application.."
checkfail=`codesign --verify $tmpappdir 2>&1`
if [ "$checkfail" ]; then
echo "ERROR: $SYS_APPNAME build was not successful"
exit 1
fi
echo " => relocating application.."
rmifexists "$tgtdir"
cp -R $tmpappdir $tgtdir
echo " => cleaning up.."
rm -rf "$cmakedir" "$xcodedir" 2> /dev/null
;;
#####################################
android)
echo " => creating android project.."
tmpdir=`mktemp -d tmp.XXXXXX`
tmpdir=`pwd`"/$tmpdir"
cd $here
ANDROIDSDKTARGET=`$ANDROIDSDK/tools/android list targets | grep "^id:" | grep "android-$ANDROIDAPI" | cut -f 2 -d " "`
if [ "X$ANDROIDSDKTARGET" = "X" ]; then
echo "ERROR: API $ANDROIDAPI not a target."
exit
else
echo " => using target $ANDROIDSDKTARGET [API $ANDROIDAPI]"
fi
$ANDROIDSDK/tools/android --silent create project \
--target $ANDROIDSDKTARGET --name $SYS_APPNAME --path $tmpdir \
--activity $SYS_APPNAME --package $SYS_ORGTLD.$SYS_ORGSLD.$SYS_LOCASEAPPNAME
echo " => preparing icons.."