For now, only one `pyodide` can be loaded in a given global scope because we need to use a global variable for package loading. This changes `loadPyodide` so that it no longer defines `globalThis.pyodide` in favor of just returning `pyodide` from `loadPyodide`. `Module` is placed on the global object as `globalThis.__pyodide_module` for the purposes of package loading. I added documentation to explicitly state that `loadPyodide` can only be run once in each global Javascript context, an error will be thrown otherwise.

This has two advantages: 
1. The returned `pyodide` module is understandable to Typescript and other code analysis, whereas the global variable is not understandable.
2. If in the future we are able to remove the global variable, no further API change will be needed (other than relaxing the documented "pyodide must be globally-unique" constraint). I figure it's better to make this API change earlier rather than later.

It will be possible to completely remove the global variable dependence when Firefox implements support for using ES6 modules in webworkers (see https://bugzilla.mozilla.org/show_bug.cgi?id=1247687).
API Don't expose pyodide as a global variable in loadPyodide. For now, only one `pyodide` can be loaded in a given global scope because we need to use a global variable for package loading. This changes `loadPyodide` so that it no longer defines `globalThis.pyodide` in favor of just returning `pyodide` from `loadPyodide`. `Module` is placed on the global object as `globalThis.__pyodide_module` for the purposes of package loading. I added documentation to explicitly state that `loadPyodide` can only be run once in each global Javascript context, an error will be thrown otherwise.

This has two advantages: 
1. The returned `pyodide` module is understandable to Typescript and other code analysis, whereas the global variable is not understandable.
2. If in the future we are able to remove the global variable, no further API change will be needed (other than relaxing the documented "pyodide must be globally-unique" constraint). I figure it's better to make this API change earlier rather than later.

It will be possible to completely remove the global variable dependence when Firefox implements support for using ES6 modules in webworkers (see https://bugzilla.mozilla.org/show_bug.cgi?id=1247687).
export PYODIDE_EMSCRIPTEN_VERSION ?= 2.0.15
export PYODIDE_BINARYEN_VERSION ?= version_100

# BASH_ENV tells bash to run pyodide_env.sh on startup, whcih sets various
# environment variables. The next line instructs make to use bash to run each
# command.
export BASH_ENV := $(PYODIDE_ROOT)/pyodide_env.sh
SHELL := /bin/bash

export TOOLSDIR=$(PYODIDE_ROOT)/tools
export PYVERSION=3.8.2
export PYMINOR=$(basename $(PYVERSION))
export HOSTPYTHONROOT=$(shell python3.8 -c "import sys; print(sys.prefix)")
export HOSTPYTHON=$(HOSTPYTHONROOT)/bin/python3.8
export TARGETPYTHONROOT=$(PYODIDE_ROOT)/cpython/installs/python-$(PYVERSION)
export PYTHONINCLUDE=$(PYODIDE_ROOT)/cpython/installs/python-$(PYVERSION)/include/python$(PYMINOR)

# Use env variable if defined, otherwise fallback to './'
export PYODIDE_BASE_URL?=./

# This environment variable is used for packages to detect if they are built
# for pyodide during build time
export PYODIDE=1
# This is the legacy environment variable used for the aforementioned purpose
export PYODIDE_PACKAGE_ABI=1
export EM_COMPILER_WRAPPER=ccache

export OPTFLAGS=-O2
export CFLAGS_BASE=\
	$(OPTFLAGS) \
	-g \
	-fPIC \
	$(EXTRA_CFLAGS)

export LDFLAGS_BASE=\
	-s BINARYEN_EXTRA_PASSES="--pass-arg=max-func-params@61" \
	$(OPTFLAGS) \
	-s MODULARIZE=1 \
	-s EMULATE_FUNCTION_POINTER_CASTS=1 \
	-s LINKABLE=1 \
	-s EXPORT_ALL=1 \
	-s WASM=1 \
	-std=c++14 \
	-s LZ4=1 \
	$(EXTRA_LDFLAGS)

export CXXFLAGS_BASE=

export SIDE_MODULE_LDFLAGS=	$(LDFLAGS_BASE) -s SIDE_MODULE=1
export MAIN_MODULE_LDFLAGS= $(LDFLAGS_BASE) -s MAIN_MODULE=1 \
	-s EXPORTED_FUNCTIONS='["___cxa_guard_acquire", "__ZNSt3__28ios_base4initEPv", "_main"]' \
	$(CPYTHONROOT)/installs/python-$(PYVERSION)/lib/libpython$(PYMINOR).a \
	-s TOTAL_MEMORY=20971520 \
	-s ALLOW_MEMORY_GROWTH=1 \
    --use-preload-plugins \
	-s USE_FREETYPE=1 \
	-s USE_LIBPNG=1 \
	-L$(wildcard $(CPYTHONROOT)/build/sqlite*/.libs) -lsqlite3 \
	$(wildcard $(CPYTHONROOT)/build/bzip2*/libbz2.a) \
	-lstdc++ \
	--memory-init-file 0 \

export SIDE_MODULE_CXXFLAGS = $(CXXFLAGS_BASE)

export SIDE_MODULE_CFLAGS= $(CFLAGS_BASE)
export MAIN_MODULE_CFLAGS= $(CFLAGS_BASE) \
    	-Wall \
    	-Wno-warn-absolute-paths \
    	-Werror=unused-variable \
    	-Werror=sometimes-uninitialized \
    	-Werror=int-conversion \
    	-Werror=incompatible-pointer-types \
		-I$(PYTHONINCLUDE) 


.output_vars:
	set

export PYODIDE_EMSCRIPTEN_VERSION ?= 2.0.15
export PYODIDE_BINARYEN_VERSION ?= version_100

# BASH_ENV tells bash to run pyodide_env.sh on startup, whcih sets various
# environment variables. The next line instructs make to use bash to run each
# command.
export BASH_ENV := $(PYODIDE_ROOT)/pyodide_env.sh
SHELL := /bin/bash

export TOOLSDIR=$(PYODIDE_ROOT)/tools
export PYVERSION=3.8.2
export PYMINOR=$(basename $(PYVERSION))
export HOSTPYTHONROOT=$(shell python3.8 -c "import sys; print(sys.prefix)")
export HOSTPYTHON=$(HOSTPYTHONROOT)/bin/python3.8
export TARGETPYTHONROOT=$(PYODIDE_ROOT)/cpython/installs/python-$(PYVERSION)
export PYTHONINCLUDE=$(PYODIDE_ROOT)/cpython/installs/python-$(PYVERSION)/include/python$(PYMINOR)

# Use env variable if defined, otherwise fallback to './'
export PYODIDE_BASE_URL?=./

# This environment variable is used for packages to detect if they are built
# for pyodide during build time
export PYODIDE=1
# This is the legacy environment variable used for the aforementioned purpose
export PYODIDE_PACKAGE_ABI=1
export EM_COMPILER_WRAPPER=ccache

export OPTFLAGS=-O2
export CFLAGS_BASE=\
	$(OPTFLAGS) \
	-g \
	-fPIC \
	$(EXTRA_CFLAGS)

export LDFLAGS_BASE=\
	-s BINARYEN_EXTRA_PASSES="--pass-arg=max-func-params@61" \
	$(OPTFLAGS) \
	-s MODULARIZE=1 \
	-s EMULATE_FUNCTION_POINTER_CASTS=1 \
	-s LINKABLE=1 \
	-s EXPORT_ALL=1 \
	-s WASM=1 \
	-std=c++14 \
	-s LZ4=1 \
	$(EXTRA_LDFLAGS)

export CXXFLAGS_BASE=

export SIDE_MODULE_LDFLAGS=	$(LDFLAGS_BASE) -s SIDE_MODULE=1
export MAIN_MODULE_LDFLAGS= $(LDFLAGS_BASE) -s MAIN_MODULE=1 \
	-s EXPORTED_FUNCTIONS='["___cxa_guard_acquire", "__ZNSt3__28ios_base4initEPv", "_main"]' \
	$(CPYTHONROOT)/installs/python-$(PYVERSION)/lib/libpython$(PYMINOR).a \
	-s TOTAL_MEMORY=20971520 \
	-s ALLOW_MEMORY_GROWTH=1 \
    --use-preload-plugins \
	-s USE_FREETYPE=1 \
	-s USE_LIBPNG=1 \
	-L$(wildcard $(CPYTHONROOT)/build/sqlite*/.libs) -lsqlite3 \
	$(wildcard $(CPYTHONROOT)/build/bzip2*/libbz2.a) \
	-lstdc++ \
	--memory-init-file 0 \

export SIDE_MODULE_CXXFLAGS = $(CXXFLAGS_BASE)

export SIDE_MODULE_CFLAGS= $(CFLAGS_BASE)
export MAIN_MODULE_CFLAGS= $(CFLAGS_BASE) \
    	-Wall \
    	-Wno-warn-absolute-paths \
    	-Werror=unused-variable \
    	-Werror=sometimes-uninitialized \
    	-Werror=int-conversion \
    	-Werror=incompatible-pointer-types \
		-I$(PYTHONINCLUDE) 


.output_vars:
	set
