|
55 | 55 |
|
56 | 56 | # copy to app build folder preserving the directory structure |
57 | 57 | mkdir -p $APPS_ROOT/build/tinycc/bin |
58 | | -mkdir -p $APPS_ROOT/build/usr/local/bin/tcc/ |
59 | | -cp tcc.cwasm $APPS_ROOT/build/tinycc/bin |
60 | | -cp libtcc1.a $APPS_ROOT/build/usr/local/bin/tcc/ |
| 58 | +mkdir -p $APPS_ROOT/build/tinycc/usr/local/bin/tcc/ |
| 59 | +if [ -s "tcc.cwasm" ]; then |
| 60 | + cp tcc.cwasm $APPS_ROOT/build/tinycc/bin/tcc |
| 61 | +elif [ -s "tcc.wasm" ]; then |
| 62 | + cp tcc.wasm $APPS_ROOT/build/tinycc/bin/tcc |
| 63 | +else |
| 64 | + echo "No wasm binary created" |
| 65 | + exit 1 |
| 66 | +fi |
| 67 | + |
| 68 | +#libtcc1.a is required to run tinycc |
| 69 | +cp libtcc1.a $APPS_ROOT/build/tinycc/usr/local/bin/tcc/ |
| 70 | + |
| 71 | +#These headers are required to compile C programs using tinycc |
| 72 | +tar -xvzf tcc_headers.tar.gz |
| 73 | +rsync -a "${SCRIPT_DIR}/tcc_headers/" "$APPS_ROOT/build/tinycc/" |
| 74 | + |
| 75 | +#While running tinycc to compile C programs as 32-bit binaries, it |
| 76 | +#requires 32-bit versions of libc.so, ld.so, libc_nonshared.a and crt object files |
| 77 | +#in the search path. Since tinycc is run within lindfs/ it will search in paths |
| 78 | +#relative to lindfs. We first create these paths with respect to the build folder |
| 79 | +#Later at 'make install' stage, all the files within the build folder copied to lindfs folder |
| 80 | + |
| 81 | +mkdir -p "$APPS_ROOT/build/tinycc/usr/lib/i386-linux-gnu/" |
| 82 | +cp /usr/i686-linux-gnu/lib/crt*.o "$APPS_ROOT/build/tinycc/usr/lib/i386-linux-gnu/" |
| 83 | +cp /usr/i686-linux-gnu/lib/libc.so* "$APPS_ROOT/build/tinycc/usr/lib/i386-linux-gnu/" |
| 84 | +cp /usr/i686-linux-gnu/lib/ld-linux.so.2 "$APPS_ROOT/build/tinycc/usr/lib/i386-linux-gnu/" |
| 85 | +cp /usr/i686-linux-gnu/lib/libc_nonshared.a "$APPS_ROOT/build/tinycc/usr/lib/i386-linux-gnu/" |
| 86 | + |
| 87 | +#While running tinycc, it checks for libc.so which is a stub that looks for ld.so, libc_nonshared.a and libc.so.6. We change the absolute paths of these which were with respect to the root filesystem, so tinycc can locate these files with respect to lindfs |
| 88 | +sed -i 's|[^ ]*/libc\.so\.6|libc.so.6|g; s|[^ ]*/libc_nonshared\.a|libc_nonshared.a|g; s|[^ ]*/ld-linux\.so\.2|ld-linux.so.2|g' "$APPS_ROOT/build/tinycc/usr/lib/i386-linux-gnu/libc.so" |
| 89 | + |
| 90 | +#To run dynamically linked executable using tinycc, it expects its linker at /lib/ld-linux.so.2, hence we map the 32-bit linker to that file |
| 91 | +sudo ln -s /usr/i686-linux-gnu/lib/ld-linux.so.2 /lib/ld-linux.so.2 |
0 commit comments