diff --git a/.gitignore b/.gitignore index bcd122a..2e180f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ /.vscode/c_cpp_properties.json -/.libs /libapi.* !/libapi.mjs.d.ts /node_modules +/deps/* +!/deps/libgphoto2 +!/deps/libusb +/api.o diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ee5de6e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,8 @@ +[submodule "libgphoto2"] + path = deps/libgphoto2 + url = https://github.com/RReverser/libgphoto2 + branch = em +[submodule "libusb"] + path = deps/libusb + url = https://github.com/RReverser/libusb + branch = em diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bf1d1ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM emscripten/emsdk:2.0.26 +RUN apt-get update && apt-get install -qqy autoconf autopoint libtool-bin pkg-config +WORKDIR /src +ENV EM_CACHE /src/deps/.emcache +CMD ["sh", "-c", "emmake make -j`nproc`"] diff --git a/Makefile b/Makefile index b917414..2dd379e 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,50 @@ -CPPFLAGS += -I $(GPHOTO2PREFIX)/include +SYSROOT = $(PWD)/deps/.install +export PKG_CONFIG_PATH = $(SYSROOT)/lib/pkgconfig -libapi.mjs: api.cpp - libtool --verbose --mode=link --tag=CXX $(CC) -std=c++17 $+ --bind -s ASYNCIFY -fexceptions -Os -s ALLOW_MEMORY_GROWTH -s DYNAMIC_EXECUTION=0 -o $@ \ - $(GPHOTO2PREFIX)/lib/libltdl.la \ - $(GPHOTO2PREFIX)/lib/libgphoto2.la \ - -dlpreopen $(GPHOTO2PREFIX)/lib/libgphoto2/2.5.27.1/ptp2.la \ - -dlpreopen $(GPHOTO2PREFIX)/lib/libgphoto2_port/0.12.0/usb1.la \ - $(CPPFLAGS) +export CPPFLAGS += -I$(SYSROOT)/include +export LDFLAGS += -L$(SYSROOT)/lib -s DYNAMIC_EXECUTION=0 -s AUTO_JS_LIBRARIES=0 -s AUTO_NATIVE_LIBRARIES=0 -s ALLOW_UNIMPLEMENTED_SYSCALLS=0 + +COMMON_FLAGS = -Os -flto +export CFLAGS += $(COMMON_FLAGS) +export CXXFLAGS += $(COMMON_FLAGS) +export LDFLAGS += $(COMMON_FLAGS) + +libapi.mjs: api.o $(SYSROOT)/lib/libltdl.la $(SYSROOT)/lib/libgphoto2.la + deps/libgphoto2/libtool --verbose --mode=link $(LD) $(LDFLAGS) -o $@ $+ \ + --bind -s ASYNCIFY -s ALLOW_MEMORY_GROWTH \ + -dlpreopen $(SYSROOT)/lib/libgphoto2/2.5.27.1/ptp2.la \ + -dlpreopen $(SYSROOT)/lib/libgphoto2_port/0.12.0/usb1.la + +api.o: deps/libgphoto2/configure.ac +api.o: CPPFLAGS += -Ideps/libgphoto2 -Ideps/libgphoto2/libgphoto2_port +api.o: CXXFLAGS += -std=c++17 -fexceptions + +$(SYSROOT)/.exists: + mkdir -p $(@D) + touch $@ + +deps/libtool/configure: + mkdir -p deps/libtool + curl -L https://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz | tar zx --strip 1 -C deps/libtool + +deps/libgphoto2/configure.ac deps/libusb/configure.ac &: + git submodule update --init + +$(SYSROOT)/lib/libltdl.la: $(SYSROOT)/.exists deps/libtool/configure + cd deps/libtool && \ + ./configure --prefix=$(SYSROOT) --disable-shared && \ + $(MAKE) install + +$(SYSROOT)/lib/libusb-1.0.la: $(SYSROOT)/.exists deps/libusb/configure.ac + cd deps/libusb && \ + autoreconf -fiv && \ + ./configure --prefix=$(SYSROOT) --disable-shared --host=wasm32 && \ + $(MAKE) install + +$(SYSROOT)/lib/libgphoto2.la: deps/libgphoto2/configure.ac $(SYSROOT)/lib/libltdl.la $(SYSROOT)/lib/libusb-1.0.la + cd deps/libgphoto2 && \ + autoreconf -fiv && \ + ./configure --prefix=$(SYSROOT) --disable-shared --host=wasm32 \ + --without-libxml-2.0 --disable-nls --disable-ptpip --disable-disk \ + --with-camlibs=ptp2 && \ + $(MAKE) install diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a3b05f1 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh +docker build -t web-gphoto2 - < Dockerfile +docker run --rm -it \ + -v $PWD:/src \ + -u $(id -u):$(id -g) \ + web-gphoto2 diff --git a/deps/libgphoto2 b/deps/libgphoto2 new file mode 160000 index 0000000..951b836 --- /dev/null +++ b/deps/libgphoto2 @@ -0,0 +1 @@ +Subproject commit 951b8364a69eb93df4aab3409a7803f1355be139 diff --git a/deps/libusb b/deps/libusb new file mode 160000 index 0000000..0e5f839 --- /dev/null +++ b/deps/libusb @@ -0,0 +1 @@ +Subproject commit 0e5f839ebb66dcb3f428ef1f4df1ded268f7f2c9