-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·146 lines (131 loc) · 3.72 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
#!/bin/sh
# MCODE project configuration where
# - sourceDir contains
# - MCODE source files (extension .src)
# - linker file ${projectName}.lnk
# - (optional) emulator loader file ${projectName}.lod
# - buildDir is the target for all output files
# Note that all files in $sourceDir are expected to have CR LF
# line terminators! You may use command 'file ${sourceDir}/*'
# to check that.
sourceDir=./src
buildDir=./build
# Get absolute path of build script
SCRIPT_PATH="$(cd $(dirname $0); pwd -P)"
# Delete $buildDir, see build target 'clean'
doClean() {
echo "clean"
rm -rf $buildDir
return 0
}
# Guess project name from linker file name
guessProjectName() {
files=($sourceDir/*.lnk)
pathName=${files[0]}
fileName=$(basename $pathName)
echo "${fileName%.*}"
}
# Copy source files from source to build directory
prepareBuildDir() {
mkdir -p $buildDir
# copy source, linker and load files
cp $sourceDir/*.{src,lnk,lod} $buildDir
# copy standard emulator ROM images
cp $SDK41/*.ROM $buildDir
}
# Create batch file to compile and link MCODE project
# using the SDK41 compiler/linker
createDosBuildScript() {
buildHelper="$(cd $buildDir; pwd -P)/build.bat"
echo "l41 /arol /ll /r $1 > build.log" > $buildHelper
# DOS needs CR LF line terminators
unix2dos -q $buildHelper
echo "$buildHelper"
}
# Call DOSBox to run batch file (SDK41 in path)
runDosScript() {
open -a DOSBOX $1 \
--args "$2" -exit -c "mount d $SDK41" -c "path d:/"
}
runDosScriptHidden() { runDosScript -Wnj $1; }
runDosScriptInteractive() { runDosScript -Wn $1; }
# Just for convenience: convert DOS upper case filenames to
# lower case
lowerCaseFileNames() {
local path="$1"
for i in $path; do
j=$(echo "$i" | tr '[:upper:]' '[:lower:]')
mv "$i" "$j"
done
}
# Create batch file to run MCODE project in HP-41 emulator
createDosTestScript() {
testScript="$(cd $buildDir; pwd -P)/test.bat"
echo "m41 /j /$1" > $testScript
# DOS needs CR LF line terminators
unix2dos -q $testScript
echo "$testScript"
}
# Build project, see build target 'build'
doBuild() {
local projectName="$1"
echo "build $projectName"
prepareBuildDir
local buildScript=$(createDosBuildScript $projectName)
runDosScriptHidden "$buildScript"
lowerCaseFileNames "$buildDir/*"
grep "\*\*\* ERROR" $buildDir/build.log
if [ $? -eq 1 ]; then
echo "DONE"
return 0
else
return 1
fi
}
# Debug project, see built target 'test'
doTest() {
local projectName="$1"
doBuild "$projectName"
echo "test $1"
local testScript=$(createDosTestScript $projectName)
runDosScriptInteractive "$testScript"
return 0
}
# Deploy project to HP-41CL, see built target 'deploy'
doDeploy() {
local projectName="$1"
doBuild "$projectName"
echo "deploy $1"
echo "\033[0;31mGet ready to start receive program on your HP-41CL\033[0m"
sleep 2
java -jar $CLUPDATE --upload build/${projectName}.rom $USBSERIAL 4800
return 0
}
# Environment variable SDK41 defines path to SDK41
if [ -z "$SDK41" ]; then
echo "*** error: path to HP-41 SDK not set"
exit 1
elif [ "$1" == "clean" ]; then
doClean
exit $?
elif [ "$1" == "" ] || [ "$1" == "build" ]; then
doBuild "$(guessProjectName)"
exit $?
elif [ "$1" == "test" ]; then
doTest "$(guessProjectName)"
exit $?
elif [ "$1" == "deploy" ]; then
if [ -z "$CLUPDATE" ]; then
echo "*** error: path to HP-41CL update program not set"
exit 1
fi
if [ -z "$USBSERIAL" ]; then
echo "*** error: USB serial device name not set"
exit 1
fi
doDeploy "$(guessProjectName)"
exit $?
else
echo "*** error: unknown build target"
exit 1
fi