-
Notifications
You must be signed in to change notification settings - Fork 9
/
puny
executable file
·191 lines (167 loc) · 6.05 KB
/
puny
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
#!/bin/bash
# puny CLI - The Puny BuildTools command-line interface
# Copyright (c) 2024 Stefan Vogt
#read config file
if [ -f config.sh ] ; then
source config.sh
fi
#get short git version hash
gitversion=$(git -C ~/FictionTools rev-parse --short HEAD)
do_compile()
{
if ! [ -f config.sh ] ; then
echo -e "No config file found in current directory.\n"
exit 1
fi
if [ -f ${STORY}.z${ZVERSION} ] ; then
rm ${STORY}.z${ZVERSION}
fi
if ! [ -f ${STORY}.inf ] ; then
echo -e "'${STORY}.inf' not found. Operation aborted.\n"
exit 1
fi
${WRAPPER} -${ZVERSION} ${STORY}.inf
if ! [ -f ${STORY}.z${ZVERSION} ] ; then
echo -e "Inform 6 compiler error detected, no story file compiled.\n"
exit 1;
else
echo -e "Story file '${STORY}.z${ZVERSION}' successfully compiled.\n"
fi
}
printf "puny CLI 2.2_%s" "$gitversion"
printf " | Craters of Ganymede\n\n"
while getopts ':iectb:haosv' opt; do
case "$opt" in
i) # init project directory
echo -e "initializing project directory [...]\n"
if [ -f config.sh ] ; then
echo -e "Config file found in current directory. Aborting project init.\n"
exit 1
fi
echo "-> writing 'config.sh' file"
echo "-> writing 'Resources' directory"
cp -r ~/FictionTools/Templates/Resources .
mv Resources/config.sh .
echo "-> writing 'bundle.sh' and 'all.sh' scripts"
mv Resources/bundle.sh .
mv Resources/all.sh .
echo "-> writing 'Releases' directory"
mv Resources/Releases .
echo -e "\nDone.\nUse 'puny -e' to edit your project configuration.\n"
exit 0
;;
a) # create optimized abbrevations > abbrvs.h
echo -e "writing abbreviations to abbrvs.h [...]\n"
~/FictionTools/make_abbrvs.sh
echo
exit 0
;;
e) # edit project config
if ! [ -f config.sh ] ; then
echo -e "No config file found in current directory.\n"
exit 1
fi
echo -e "launching config editor [...]"
echo -e "Done.\n"
${CFGEDITOR} config.sh
exit 0
;;
c) # project story file compilation
do_compile
exit 0
;;
t) # project testing
echo -e "testing '${STORY}' in '${TESTTERP}', Z-machine version ${ZVERSION} [...]"
do_compile
echo -e "Launching ${TESTTERP} [...]"
echo -e "Done.\n"
${TESTTERP} ${STORY}.z${ZVERSION}
exit 0
;;
b) # target processing
if ! [ -f config.sh ] ; then
echo -e "No config file found in current directory.\n"
exit 1
fi
zvalue="$ZVERSION"
if ! (( zvalue == 3 || zvalue == 5 )) ; then
echo -e "Z-machine version ${zvalue} is not supported.\n";
exit 1
fi
target="$OPTARG"
if ! [ -f ~/FictionTools/Templates/${target}.sh ] ; then
echo -e "'${target}' is not a valid target. Operation aborted.\n"
exit 1
fi
echo -e "Processing target '${target}', Z-machine version ${zvalue}"
~/FictionTools/Templates/${target}.sh
;;
h) # help menu
echo -e "Synopsis: $(basename $0) [-switch] or [-build target]\n"
echo "[switches]"
echo " -i initialize project directory"
echo " -e edit project configuration"
echo " -c compile project to Z-machine story file"
echo " -a create optimized abbreviations"
echo " -t test project"
echo " -o see full range of target systems"
echo " -s show examples"
echo " -v version information"
echo -e " -h help menu\n"
echo "[build target]"
echo -e " -b arg create disk image for the system defined as argument\n"
exit 0
;;
o) # target listing
echo "Target systems:"
echo "C64 [-b c64] Amiga [-b amiga] ZX Spectrum [-b speccy]"
echo "CPC/PCW [-b cpc_pcw] Atari ST [-b atari_st] Atari 8-bit [-b a8bit]"
echo "MS-DOS [-b dos] MSX [-b msx] BBC/Electron [-b bbc_acorn]"
echo "C128 [-b c128] Plus/4 [-b plus4] Apple II [-b apple2]"
echo "SAM [-b sam_coupe] TRS M3 [-b trs80_m3] TRS M4 [-b trs80_m4]"
echo "Mega65 [-b mega65] Macintosh [-b macintosh]"
echo -e "\nDeprecated systems (only supporting Z-machine v3):"
echo "[-b vic20_pet] [-b decrainbow] [-b trs_coco_dragon64] [-b osborne1]"
echo -e "[-b ti99] [-b oric] [-b kaypro]\n"
exit 0
;;
s) # examples
echo "Examples:"
echo "puny -e"
echo -e "-> edit project config file\n"
echo "puny -c"
echo -e "-> compile your project source to Z-machine story\n"
echo "puny -b c64"
echo -e "-> build Commodore 64 target\n"
echo "puny -b dos -b msx -b amiga"
echo -e "-> build DOS, MSX and Amiga targets\n"
exit 0
;;
v) # version information
echo "the Puny BuildTools command-line interface"
echo "Copyright (c) 2024, Stefan Vogt"
echo "https://github.com/ByteProject/Puny-BuildTools"
echo -e "\n| component versions: |"
echo "[CLI 2.2] [pi6 3.0] [bundle.sh 2.1] [Puny-Wan Kenobi 1.3]"
echo "[makescr.sh 1.0] [ifftool.sh 1.2] [cpcscr.sh 1.0] [degaspi1.sh 1.0]"
echo -e "\n| module versions: |"
echo "[c64 2.1] [amiga 2.0] [speccy 2.5] [cpc_pcw 2.5] [atari_st 2.0] [a8bit 3.0]"
echo "[dos 2.2] [msx 2.5] [bbc_acorn 2.2] [c128 2.2] [plus4 2.1] [apple2 2.6]"
echo "[sam_coupe 2.5] [trs80_m3 2.6] [trs80_m4 2.6] [mega65 2.1] [macintosh 2.0]"
echo "[vic20_pet 1.5] [decrainbow 1.0] [trs_coco_dragon64 1.5] [osborne1 1.0]"
echo -e "[ti99 1.5] [oric 1.5] [kaypro 1.0]\n"
exit 0
;;
:)
echo -e "Option [-${OPTARG}] requires an argument.\n\nType: $(basename $0) [-h] for help.\n"
exit 1
;;
?)
echo -e "Invalid command option.\n\nType: $(basename $0) [-h] for help.\n"
exit 1
;;
esac
done
if [ $OPTIND -eq 1 ]; then echo -e "Nothing to be done. No options passed. Use [-h] for help.\n"; fi
shift "$(($OPTIND -1))"
exit 0;