-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckInstall.sh
More file actions
executable file
·149 lines (124 loc) · 4.67 KB
/
Copy pathcheckInstall.sh
File metadata and controls
executable file
·149 lines (124 loc) · 4.67 KB
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
#!/bin/bash
# checkInstall.sh — verifies the os161 toolchain is correctly installed
# Run from the same directory as install.sh
set -uo pipefail # no -e: we want to collect ALL failures, not stop at first
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
source "$SCRIPT_DIR/common.sh"
PASS=0
FAIL=0
_pass() { log_ok "$1"; (( PASS++ )) || true; }
_fail() { log_error "$1"; (( FAIL++ )) || true; }
# ── 1. Required binaries exist and are executable ─────────────────────────────
echo ""
log_info "--- Checking binaries ---"
BINS=(
mips-harvard-os161-as
mips-harvard-os161-gcc
mips-harvard-os161-gdb
mips-harvard-os161-ld
mips-harvard-os161-objdump
sys161
disk161
)
for bin in "${BINS[@]}"; do
path="$TOOLS_DIR/bin/$bin"
if [ -x "$path" ]; then
_pass "$bin ($path)"
else
_fail "$bin NOT FOUND at $path"
fi
done
# ── 2. Binaries are MIPS cross-tools (not native) ────────────────────────────
echo ""
log_info "--- Checking binary targets ---"
GCC_BIN="$TOOLS_DIR/bin/mips-harvard-os161-gcc"
if [ -x "$GCC_BIN" ]; then
target=$("$GCC_BIN" -dumpmachine 2>/dev/null)
if [ "$target" = "mips-harvard-os161" ]; then
_pass "gcc target: $target"
else
_fail "gcc target is '$target', expected 'mips-harvard-os161'"
fi
version=$("$GCC_BIN" --version 2>/dev/null | head -n 1)
_pass "gcc version: $version"
fi
GDB_BIN="$TOOLS_DIR/bin/mips-harvard-os161-gdb"
if [ -x "$GDB_BIN" ]; then
version=$("$GDB_BIN" --version 2>/dev/null | head -n 1)
_pass "gdb version: $version"
fi
SYS161_BIN="$TOOLS_DIR/bin/sys161"
if [ -x "$SYS161_BIN" ]; then
version=$("$SYS161_BIN" --version 2>/dev/null | head -n 1 || true)
_pass "sys161 found: $SYS161_BIN"
fi
# ── 3. PATH contains the tools bin directory ──────────────────────────────────
echo ""
log_info "--- Checking PATH ---"
if command -v mips-harvard-os161-gcc > /dev/null 2>&1; then
found=$(command -v mips-harvard-os161-gcc)
_pass "mips-harvard-os161-gcc on PATH ($found)"
else
_fail "mips-harvard-os161-gcc NOT on PATH — run: export PATH=\$PATH:$TOOLS_DIR/bin"
fi
if command -v sys161 > /dev/null 2>&1; then
_pass "sys161 on PATH"
else
_fail "sys161 NOT on PATH"
fi
# ── 4. os161 source tree exists ───────────────────────────────────────────────
echo ""
log_info "--- Checking source tree ---"
SRC="$OS161_DIR/src"
for f in "$SRC/configure" "$SRC/kern/conf/conf.kern" \
"$SRC/userland/testbin/usemtest/usemtest.c"; do
if [ -f "$f" ]; then
_pass "$(basename "$f") ($f)"
else
_fail "Missing: $f"
fi
done
# ── 5. Cross-compiler can compile a hello-world C file ───────────────────────
echo ""
log_info "--- Compile test ---"
_TMPDIR=$(mktemp -d)
trap 'rm -rf "$_TMPDIR"' EXIT
cat > "$_TMPDIR/hello.c" << 'CSRC'
int main(void) { return 0; }
CSRC
if "$TOOLS_DIR/bin/mips-harvard-os161-gcc" \
-nostdinc -nostdlib \
-o "$_TMPDIR/hello.o" -c "$_TMPDIR/hello.c" 2>/dev/null; then
_pass "Cross-compiled hello.c → hello.o successfully"
arch=$(file "$_TMPDIR/hello.o" 2>/dev/null)
if echo "$arch" | grep -q "MIPS"; then
_pass "Output is MIPS object: $arch"
else
_fail "Output is NOT MIPS: $arch"
fi
else
_fail "Cross-compilation failed"
fi
# ── 6. rc file contains the os161 PATH line ───────────────────────────────────
echo ""
log_info "--- Checking permanent PATH config ---"
RC_FILES=("$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.profile")
_rc_found=0
for _rc in "${RC_FILES[@]}"; do
if [ -f "$_rc" ] && grep -q "os161/tools/bin" "$_rc"; then
_pass "os161 PATH entry found in $_rc"
_rc_found=1
break
fi
done
[ "$_rc_found" -eq 1 ] || _fail "os161 PATH entry not found in any rc file (~/.bashrc, ~/.bash_profile, ~/.profile) — run setEnvPermanent.sh"
# ── Summary ───────────────────────────────────────────────────────────────────
echo ""
echo "────────────────────────────────────"
if [ "$FAIL" -eq 0 ]; then
log_ok "All checks passed ($PASS/$((PASS+FAIL)))"
else
log_error "$FAIL check(s) failed, $PASS passed"
exit 1
fi
exit 0