<commit_before>SYSROOT = $(EM_CACHE)/sysroot

# Add custom sysroot to autoconf macro search
# (we need this because we use custom local copy of libtool)
export ACLOCAL_PATH := $(SYSROOT)/share/aclocal:$(ACLOCAL_PATH)

# Common linking flags for all targets.
export LDFLAGS += -s DYNAMIC_EXECUTION=0 -s AUTO_JS_LIBRARIES=0 -s AUTO_NATIVE_LIBRARIES=0 -s ALLOW_UNIMPLEMENTED_SYSCALLS=0

# Common compilation & linking flags for all langs and targets.
COMMON_FLAGS = -Os -flto
export CFLAGS += $(COMMON_FLAGS)
export CXXFLAGS += $(COMMON_FLAGS)
export LDFLAGS += $(COMMON_FLAGS)

## Main API module

libapi.mjs: api.o $(SYSROOT)/lib/libltdl.la $(SYSROOT)/lib/libgphoto2.la
	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

## Generic rules for deps

$(SYSROOT):
	mkdir -p $(@D)

## libtool

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/libtool/Makefile: deps/libtool/configure
	cd $(@D) && ./configure --prefix=$(SYSROOT) --disable-shared

$(SYSROOT)/lib/libltdl.la: deps/libtool/Makefile | $(SYSROOT)
	$(MAKE) -C deps/libtool install

## libgphoto2

deps/libgphoto2/configure.ac deps/libusb/configure.ac &:
	git submodule update --init

deps/libgphoto2/configure: deps/libusb/configure.ac | $(SYSROOT)/lib/libltdl.la
	cd $(@D) && autoreconf -fiv

deps/libgphoto2/Makefile: deps/libgphoto2/configure | $(SYSROOT)/lib/libusb-1.0.la
	./configure --prefix=$(SYSROOT) --disable-shared --host=wasm32 \
		 --without-libxml-2.0 --disable-nls --disable-ptpip --disable-disk \
		 --with-camlibs=ptp2

$(SYSROOT)/lib/libgphoto2.la: deps/libgphoto2/Makefile $(SYSROOT)/lib/libusb-1.0.la $(SYSROOT)/lib/libltdl.la
	$(MAKE) -C deps/libgphoto2 install

## libusb

deps/libusb/configure: deps/libusb/configure.ac | $(SYSROOT)/lib/libltdl.la
	cd $(@D) && autoreconf -fiv

deps/libusb/Makefile: deps/libusb/configure
	cd $(@D) && ./configure --prefix=$(SYSROOT) --disable-shared --host=wasm32

$(SYSROOT)/lib/libusb-1.0.la: deps/libusb/Makefile
	$(MAKE) -C deps/libusb install
<commit_msg>Fix Git lock errors and a bit of cleanup<commit_after>SYSROOT = $(EM_CACHE)/sysroot

# Add custom sysroot to autoconf macro search
# (we need this because we use custom local copy of libtool)
export ACLOCAL_PATH := $(SYSROOT)/share/aclocal:$(ACLOCAL_PATH)

# Common linking flags for all targets.
export LDFLAGS += -s DYNAMIC_EXECUTION=0 -s AUTO_JS_LIBRARIES=0 -s AUTO_NATIVE_LIBRARIES=0 -s ALLOW_UNIMPLEMENTED_SYSCALLS=0

# Common compilation & linking flags for all langs and targets.
COMMON_FLAGS = -Os -flto
export CFLAGS += $(COMMON_FLAGS)
export CXXFLAGS += $(COMMON_FLAGS)
export LDFLAGS += $(COMMON_FLAGS)

## Main API module

libapi.mjs: api.o $(SYSROOT)/lib/libltdl.la $(SYSROOT)/lib/libgphoto2.la
	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

## Generic rules for deps

$(SYSROOT):
	mkdir -p $(@D)

deps/%/configure.ac:
	git submodule update --init $(@D)

deps/%/configure: deps/%/configure.ac | $(SYSROOT)/lib/libltdl.la
	cd $(@D) && autoreconf -fiv

deps/%/Makefile: deps/%/configure
	cd $(@D) && ./configure --prefix=$(SYSROOT) --disable-shared $(CONFIGURE_ARGS)

## libtool

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

$(SYSROOT)/lib/libltdl.la: deps/libtool/Makefile | $(SYSROOT)
	$(MAKE) -C deps/libtool install

## libusb

deps/libusb/Makefile: CONFIGURE_ARGS = --host=wasm32

$(SYSROOT)/lib/libusb-1.0.la: deps/libusb/Makefile
	$(MAKE) -C deps/libusb install

## libgphoto2

deps/libgphoto2/Makefile: | $(SYSROOT)/lib/libusb-1.0.la
deps/libgphoto2/Makefile: CONFIGURE_ARGS = --host=wasm32 \
	--without-libxml-2.0 --disable-nls --disable-ptpip --disable-disk \
	--with-camlibs=ptp2

$(SYSROOT)/lib/libgphoto2.la: deps/libgphoto2/Makefile $(SYSROOT)/lib/libusb-1.0.la $(SYSROOT)/lib/libltdl.la
	$(MAKE) -C deps/libgphoto2 install

{'fraction_non_alphanumeric': 0.16145947126939042, 'fraction_numerical': 0.020974437404413373, 'mean_word_length': 4.143820224719101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7067017', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1845, 'n_words': 363}