hbmap: fix iterator truncation when size_t < 32bit
[rofl0r-agsutils.git] / agsex
blobd9f8805621c122f6d8dff5744ee2e62c6684867c
1 #!/bin/sh
3 usage() {
4 echo "$0 game.exe FILES OBJ"
5 echo "extracts ags game files into FILES and script files into OBJ"
6 echo "also a Makefile is created which automatically recompiles"
7 echo "and reinjects changed asm (.s) files into 'game.ags'"
8 exit 1
11 test $# -ne 3 && usage
13 BINDIR="$(dirname "$(readlink -f "$0")")"
15 GAME="$1"
16 FILES="$2"
17 OBJS="$3"
19 set -e
21 "$BINDIR"/agstract "$GAME" "$FILES"
22 "$BINDIR"/agscriptxtract "$FILES" "$OBJS"
24 DATAFILE="$FILES"/game28.dta
25 test -e "$DATAFILE" || DATAFILE="$FILES"/ac2game.dta
26 test -e "$DATAFILE" || { echo "error: none of datafiles game28.dta/ac2game.dta found" 2>&1; exit 1; }
28 # fix timestamps of object files so they're newer than .s
29 for i in "$OBJS"/*.o ; do touch "$i" ; done
31 # fix timestamps of game files so they're newer than .o
32 for i in "$FILES"/* ; do touch "$i" ; done
34 MAKEFILE=$PWD/Makefile
35 cat << EOF > "$MAKEFILE"
36 .PHONY: all optimize
38 FILES_DIR=$FILES
39 FILES = \$(sort \$(wildcard \$(FILES_DIR)/*))
40 OBJS_DIR=$OBJS
41 OBJS = \$(sort \$(wildcard \$(OBJS_DIR)/*.o))
42 SRCS = \$(OBJS:%.o=%.s)
43 OPT_FILES = \$(SRCS:%.s=%.sopt)
45 GAME_DATA=$DATAFILE
46 GAME=game.ags
48 OPT_FLAGS=-cmp -pushpop -sourceline -lnl -ll -cmp2 -axmar -mrswap
50 -include config.mak
52 all: \$(GAME)
53 agspack \$(FILES_DIR) \$(GAME)
55 optimize: \$(OPT_FILES)
56 \$(foreach file, \$(OPT_FILES), mv \$(file) \$(file:%.sopt=%.s) ; )
58 \$(GAME): \$(FILES)
60 \$(FILES_DIR)/%.crm: \$(OBJS_DIR)/%.o
61 agsinject 0 \$< \$@
63 \$(OBJS_DIR)/%.sopt: \$(OBJS_DIR)/%.s
64 agsoptimize \$(OPT_FLAGS) \$< \$@
66 \$(OBJS_DIR)/%.o: \$(OBJS_DIR)/%.s
67 agssemble \$(AS_FLAGS) \$< \$@
69 GAME_DATA_FILES= \\
70 EOF
71 (cd "$OBJS"
72 for i in globalscript.o dialogscript.o gamescript*.o ; do
73 test -e "$i" && printf '\t$(OBJS_DIR)/%s \\\n' "$i" >> "$MAKEFILE" || true
74 done)
76 cat << EOF >> "$MAKEFILE"
78 \$(GAME_DATA): \$(GAME_DATA_FILES)
79 agsinject -e -t \$(GAME_DATA) 0:\$(OBJS_DIR)/globalscript.o \\
80 EOF
81 (cd "$OBJS"
82 cnt=1
83 i=dialogscript.o
84 test -e "$i" && {
85 printf '\t %d:$(OBJS_DIR)/%s \\\n' $cnt "$i" >> "$MAKEFILE"
86 cnt=2
87 } || true
88 ocnt=0
89 while test -e gamescript${ocnt}.o ; do
90 i=gamescript${ocnt}.o
91 printf '\t %d:$(OBJS_DIR)/%s \\\n' $cnt "$i" >> "$MAKEFILE"
92 ocnt=$(($ocnt + 1))
93 cnt=$(($cnt + 1))
94 done)
95 printf '\t\n' >> "$MAKEFILE"