Skip to content

Commit d56733c

Browse files
committed
Compiled it successfully. Doesn't run for now, though :)
1 parent 633e824 commit d56733c

13 files changed

+279
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,4 @@ trace-dtrace-root.dtrace
212212
trace-ust-all.h
213213
trace-ust-all.c
214214
/target/arm/decode-sve.inc.c
215+
/build

block/file-posix.c

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
#include <CoreFoundation/CoreFoundation.h>
5353
#endif
5454

55+
#ifdef __EMSCRIPTEN__
56+
#include <sys/ioctl.h>
57+
#endif
58+
5559
#ifdef __sun__
5660
#define _POSIX_PTHREAD_SEMANTICS 1
5761
#include <sys/dkio.h>

configure

+34-3
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ slirp="yes"
406406
oss_lib=""
407407
bsd="no"
408408
linux="no"
409+
emscripten="no"
409410
solaris="no"
410411
profiler="no"
411412
cocoa="no"
@@ -620,7 +621,9 @@ int main(void) { return 0; }
620621
EOF
621622
}
622623

623-
if check_define __linux__ ; then
624+
if check_define __EMSCRIPTEN__; then
625+
targetos='Emscripten'
626+
elif check_define __linux__ ; then
624627
targetos="Linux"
625628
elif check_define _WIN32 ; then
626629
targetos='MINGW32'
@@ -672,6 +675,8 @@ esac
672675
if test ! -z "$cpu" ; then
673676
# command line argument
674677
:
678+
elif check_define __EMSCRIPTEN__ ; then
679+
cpu="emscripten"
675680
elif check_define __i386__ ; then
676681
cpu="i386"
677682
elif check_define __x86_64__ ; then
@@ -747,6 +752,10 @@ case "$cpu" in
747752
supported_cpu="yes"
748753
cross_cc_sparc=$host_cc
749754
;;
755+
emscripten)
756+
supported_cpu="yes"
757+
cross_cc_emscripten=$host_cc
758+
;;
750759
*)
751760
# This will result in either an error or falling back to TCI later
752761
ARCH=unknown
@@ -872,6 +881,13 @@ Linux)
872881
QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
873882
supported_os="yes"
874883
;;
884+
Emscripten)
885+
emscripten="yes"
886+
docs="no"
887+
glusterfs="no"
888+
QEMU_CFLAGS="$QEMU_CFLAGS -m32 -s USE_ZLIB=1"
889+
supported_os="yes"
890+
;;
875891
esac
876892

877893
if [ "$bsd" = "yes" ] ; then
@@ -1509,6 +1525,12 @@ case "$cpu" in
15091525
cross_cc_i386=$cc
15101526
cross_cc_cflags_i386=$CPU_CFLAGS
15111527
;;
1528+
emscripten)
1529+
CPU_CFLAGS="-m32"
1530+
LDFLAGS="-m32 $LDFLAGS"
1531+
cross_cc_emscripten=$cc
1532+
cross_cc_emscripten=$CPU_CFLAGS
1533+
;;
15121534
# No special flags required for other host CPUs
15131535
esac
15141536

@@ -1876,7 +1898,7 @@ static __thread int tls_var;
18761898
int main(void) { return tls_var; }
18771899
EOF
18781900

1879-
if ! compile_prog "-Werror" "" ; then
1901+
if (test "$emscripten" != "yes") && ! compile_prog "-Werror" "" ; then
18801902
error_exit "Your compiler does not support the __thread specifier for " \
18811903
"Thread-Local Storage (TLS). Please upgrade to a version that does."
18821904
fi
@@ -3479,7 +3501,10 @@ for i in $glib_modules; do
34793501
LIBS="$glib_libs $LIBS"
34803502
libs_qga="$glib_libs $libs_qga"
34813503
else
3482-
error_exit "glib-$glib_req_ver $i is required to compile QEMU"
3504+
if test "$emscripten" != "yes"
3505+
then
3506+
error_exit "glib-$glib_req_ver $i is required to compile QEMU"
3507+
fi
34833508
fi
34843509
done
34853510

@@ -6053,6 +6078,12 @@ if test "$supported_os" = "no"; then
60536078
echo "us upstream at [email protected]."
60546079
fi
60556080

6081+
if test "$emscripten" = "yes"
6082+
then
6083+
vector16="no"
6084+
eventfd="no"
6085+
fi
6086+
60566087
config_host_mak="config-host.mak"
60576088

60586089
echo "# Automatically generated by configure - do not modify" >config-all-disas.mak

emscripten/bin/pkg-config

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
echo $* | grep -qE "glib|gthread|gl|pixman"

emscripten/build-deps.sh

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash -e
2+
3+
. emscripten/opts.sh
4+
export STUBDIR=$(pwd)/emscripten/stubs
5+
export CFLAGS="$OPTS"
6+
export CXXFLAGS="$OPTS"
7+
8+
makeargs="$@"
9+
10+
echo "Now this script will download and build some libraries..."
11+
read -p"Press ENTER..." unused
12+
13+
function build_stub()
14+
{
15+
test -f stub.built && return
16+
test -d stub || cp -a "$STUBDIR" stub
17+
pushd stub
18+
pwd
19+
$MAKERUNNER make $makeargs
20+
popd
21+
touch stub.built
22+
}
23+
24+
function build_libffi()
25+
{
26+
test -f libffi.built && return
27+
test -d libffi || git clone --depth 1 --branch emscripten https://github.com/atrosinenko/libffi.git
28+
pushd libffi
29+
test -f configure || ./autogen.sh
30+
$CONFRUNNER ./configure $FFIOPT
31+
$MAKERUNNER make $makeargs
32+
popd
33+
touch libffi.built
34+
}
35+
36+
function build_gettext()
37+
{
38+
test -f gettext.built && return
39+
test -d gettext-$GETTEXT_VERSION || wget https://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz
40+
test -d gettext-$GETTEXT_VERSION || tar -axf gettext-$GETTEXT_VERSION.tar.gz
41+
pushd gettext-$GETTEXT_VERSION/gettext-runtime
42+
$CONFRUNNER ./configure \
43+
--disable-java --disable-native-java \
44+
--disable-largefile \
45+
--disable-c++ \
46+
--disable-threads --disable-acl --disable-openmp --disable-curses \
47+
--without-emacs
48+
$MAKERUNNER make $makeargs
49+
popd
50+
touch gettext.built
51+
}
52+
53+
function build_glib()
54+
{
55+
test -f glib.built && return
56+
test -d $GLIB_SRC || wget https://download.gnome.org/sources/glib/$GLIB_VERSION/$GLIB_SRC.tar.xz
57+
test -d $GLIB_SRC || tar -axf $GLIB_SRC.tar.xz
58+
pushd $GLIB_SRC
59+
60+
curdir=$(pwd)
61+
export ZLIB_CFLAGS="-s USE_ZLIB=1"
62+
export ZLIB_LIBS="$ZLIB_CFLAGS"
63+
export LIBFFI_CFLAGS="-I${curdir}/../libffi/emscripten-unknown-linux-gnu/include"
64+
export LIBFFI_LIBS="-L${curdir}/../libffi/emscripten-unknown-linux-gnu/.libs -lffi"
65+
export LIBMOUNT_CFLAGS=
66+
export LIBMOUNT_LIBS=
67+
export LIBS="-L${curdir}/../gettext-$GETTEXT_VERSION/gettext-runtime/intl/.libs/ -L${curdir}/../stub/"
68+
69+
test -f ./configure || NOCONFIGURE=1 ./autogen.sh
70+
$CONFRUNNER ./configure \
71+
--disable-always-build-tests --disable-installed-tests \
72+
--disable-largefile --disable-selinux --disable-fam --disable-xattr --disable-libelf \
73+
--disable-libmount \
74+
--with-pcre=internal
75+
$MAKERUNNER make $makeargs
76+
popd
77+
touch glib.built
78+
}
79+
80+
function build_pixman()
81+
{
82+
test -f pixman.built && return
83+
test -d $PIXMAN_SRC || wget https://cairographics.org/releases/$PIXMAN_SRC.tar.gz
84+
test -d $PIXMAN_SRC || tar -axf $PIXMAN_SRC.tar.gz
85+
pushd $PIXMAN_SRC
86+
$CONFRUNNER ./configure
87+
$MAKERUNNER make -C pixman $makeargs
88+
popd
89+
touch pixman.built
90+
}
91+
92+
mkdir -p $DIRNAME
93+
cd $DIRNAME
94+
build_stub
95+
build_libffi
96+
build_gettext
97+
build_glib
98+
build_pixman
99+

emscripten/build-js.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
top=$(pwd)
4+
. $top/emscripten/opts.sh
5+
build=$top/$DIRNAME
6+
7+
makeargs=-j3
8+
ARGS="$@"
9+
10+
function link_bin() {
11+
echo "Linking $1..."
12+
base=$(basename $1)
13+
ln -sf $1 $base.bc
14+
time emcc $base.bc $OPTS \
15+
$build/$GLIB_SRC/glib/.libs/libglib-2.0.so \
16+
$build/$PIXMAN_SRC/pixman/.libs/libpixman-1.so \
17+
-o $base.html \
18+
-s USE_SDL=2 \
19+
-s USE_ZLIB=1 \
20+
-s INVOKE_RUN=0 \
21+
--shell-file $top/shell.html \
22+
$ARGS
23+
ls -lh $base*
24+
}
25+
26+
cd $build/qemu
27+
28+
make $makeargs || exit 1
29+
for bin in *-softmmu/qemu-system-*
30+
do
31+
if echo $bin | grep -vqF "."
32+
then
33+
link_bin $bin
34+
fi
35+
done

emscripten/clangconfigure

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
export CC=clang
4+
export CXX=clang++
5+
exec $*

emscripten/configure-js.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
top=$(pwd)
4+
. $top/emscripten/opts.sh
5+
build=$top/$DIRNAME
6+
7+
export PATH="$top/emscripten/bin:$PATH"
8+
9+
EXTRA_CFLAGS="-DNOTHREAD -I$build/$GLIB_SRC/glib/ -I$build/$GLIB_SRC/ -I$build/$PIXMAN_SRC/pixman $OPTS"
10+
EXTRA_LDFLAGS="-L$build/$GLIB_SRC/glib/.libs/ -L$build/$GLIB_SRC/gthread/.libs/ -L$build/stub -L$build/$PIXMAN_SRC/pixman/.libs $OPTS"
11+
12+
export CFLAGS="$EXTRA_CFLAGS"
13+
14+
mkdir -p $build/qemu
15+
cd $build/qemu
16+
17+
exec emconfigure $top/configure \
18+
--extra-cflags="$EXTRA_CFLAGS" \
19+
--extra-ldflags="$EXTRA_LDFLAGS" \
20+
$*

emscripten/opts.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
if true
2+
then
3+
#OPTS="-m32 -O3 -s ALLOW_MEMORY_GROWTH=1"
4+
OPTS="-m32 -O3"
5+
#OPTS="-m32 -Os -g2"
6+
#OPTS="-m32 -O2 -g3 -s ASSERTIONS=1 -s SAFE_HEAP=1 -s ALLOW_MEMORY_GROWTH=1 -s INLINING_LIMIT=1"
7+
BUILDTYPE=emscripten
8+
CONFRUNNER=emconfigure
9+
MAKERUNNER=emmake
10+
FFIOPT="--host=emscripten-unknown-linux"
11+
else
12+
OPTS="-m32 -g"
13+
BUILDTYPE=native
14+
CONFRUNNER=$(pwd)/emscripten/clangconfigure
15+
MAKERUNNER=$(pwd)/emscripten/clangconfigure
16+
FFIOPT=
17+
fi
18+
19+
DIRNAME="build/${BUILDTYPE}_$(echo $OPTS | sed 's/[ =]/_/g')"
20+
21+
GLIB_VERSION=2.56
22+
GLIB_MINOR=1
23+
GLIB_SRC=glib-$GLIB_VERSION.$GLIB_MINOR
24+
PIXMAN_SRC=pixman-0.34.0
25+
GETTEXT_VERSION=0.19.8
26+
27+
echo "OPTS = $OPTS"
28+
echo "DIRNAME = $DIRNAME"
29+

emscripten/stubs/Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
all: libresolv.so libthread.so
2+
3+
SHELL = /bin/bash -o pipefail
4+
5+
libresolv.so: res_query.c
6+
$(CC) $(CFLAGS) --shared res_query.c -fPIC -o libresolv.so
7+
8+
libthread.so: thread.c
9+
$(CC) $(CFLAGS) --shared thread.c -fPIC -o libthread.so
10+
11+
clean:
12+
rm -f *.so

emscripten/stubs/res_query.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#define _GNU_SOURCE
2+
#include <resolv.h>
3+
#include <netdb.h>
4+
5+
int res_query(const char *name, int class, int type, unsigned char *dest, int len)
6+
{
7+
if (class != 1 || len < 512)
8+
return -1;
9+
h_errno = HOST_NOT_FOUND;
10+
return -1;
11+
}
12+

emscripten/stubs/thread.c

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <pthread.h>
2+
3+
// For ./configure script
4+
// Execute new thread function just now in this thread
5+
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
6+
void *(*start_routine) (void *), void *arg)
7+
{
8+
// typedef unsigned long pthread_t;
9+
*thread = start_routine(arg);
10+
return 0;
11+
}
12+
13+
int pthread_join(pthread_t thread, void **retval)
14+
{
15+
*retval = thread;
16+
return 0;
17+
}

util/qemu-openpty.c

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
# include <termios.h>
5252
#endif
5353

54+
#ifdef __EMSCRIPTEN__
55+
static int openpty(int *amaster, int *aslave, char *name,
56+
struct termios *termp, struct winsize *winp)
57+
{
58+
return -1;
59+
}
60+
#endif
61+
5462
#ifdef __sun__
5563
/* Once Solaris has openpty(), this is going to be removed. */
5664
static int openpty(int *amaster, int *aslave, char *name,

0 commit comments

Comments
 (0)