<commit_before>SHELL   := /usr/bin/env bash
VERSION := 0.1.0

TARGETS := armv7-apple-ios \
           armv7s-apple-ios \
           i386-apple-ios \
           aarch64-apple-ios \
           x86_64-apple-ios

# pkg-config is invoked by libsodium-sys
# cf. https://github.com/alexcrichton/pkg-config-rs/blob/master/src/lib.rs#L12
export PKG_CONFIG_ALLOW_CROSS=1

all: dist

distclean:
	rm -rf build
	rm -rf dist

dist-libs: cryptobox
	mkdir -p dist/lib
	mkdir -p dist/include
	cp build/lib/libsodium.a dist/lib/
	cp -r build/include/* dist/include/
	lipo -create $(foreach tgt,$(TARGETS),"build/lib/libcryptobox-$(tgt).a") \
		-output "dist/lib/libcryptobox.a"

dist/cryptobox-ios-$(VERSION).tar.gz: dist-libs
	tar -C dist \
		-czf dist/cryptobox-ios-$(VERSION).tar.gz \
		lib include

dist-tar: dist/cryptobox-ios-$(VERSION).tar.gz

dist: dist-tar

#############################################################################
# cryptobox

include mk/cryptobox-src.mk

build/lib/libcryptobox.a: libsodium $(CRYPTOBOX_SRC)
	cd $(CRYPTOBOX_SRC) && \
	sed -i.bak s/crate\-type.*/crate\-type\ =\ \[\"staticlib\"\]/g Cargo.toml && \
	$(foreach tgt,$(TARGETS),cargo rustc --lib --release --target=$(tgt);)
	mkdir -p build/lib
	$(foreach tgt,$(TARGETS),cp $(CRYPTOBOX_SRC)/target/$(tgt)/release/libcryptobox.a build/lib/libcryptobox-$(tgt).a;)

build/include/cbox.h: $(CRYPTOBOX_SRC)
	mkdir -p build/include
	cp $(CRYPTOBOX_SRC)/cbox.h build/include/

cryptobox: build/lib/libcryptobox.a build/include/cbox.h

#############################################################################
# libsodium

include mk/libsodium-src.mk

build/lib/libsodium.a: $(LIBSODIUM_SRC)
	cp mk/ios-full.sh $(LIBSODIUM_SRC)/dist-build && \
		chmod +x $(LIBSODIUM_SRC)/dist-build/ios-full.sh && \
		cd $(LIBSODIUM_SRC) && \
		dist-build/ios-full.sh
	mkdir -p build/lib
	cp $(LIBSODIUM_SRC)/libsodium-ios/libsodium.a build/lib/libsodium.a
<commit_msg>Add a make target for 'building' against an existing release.<commit_after>SHELL   := /usr/bin/env bash
VERSION := 0.1.0

TARGETS := armv7-apple-ios \
           armv7s-apple-ios \
           i386-apple-ios \
           aarch64-apple-ios \
           x86_64-apple-ios

# pkg-config is invoked by libsodium-sys
# cf. https://github.com/alexcrichton/pkg-config-rs/blob/master/src/lib.rs#L12
export PKG_CONFIG_ALLOW_CROSS=1

all: dist

distclean:
	rm -rf build
	rm -rf dist

dist-libs: cryptobox
	mkdir -p dist/lib
	mkdir -p dist/include
	cp build/lib/libsodium.a dist/lib/
	cp -r build/include/* dist/include/
	lipo -create $(foreach tgt,$(TARGETS),"build/lib/libcryptobox-$(tgt).a") \
		-output "dist/lib/libcryptobox.a"

dist/cryptobox-ios-$(VERSION).tar.gz: dist-libs
	tar -C dist \
		-czf dist/cryptobox-ios-$(VERSION).tar.gz \
		lib include

dist-tar: dist/cryptobox-ios-$(VERSION).tar.gz

dist: dist-tar

#############################################################################
# cryptobox

include mk/cryptobox-src.mk

build/lib/libcryptobox.a: libsodium $(CRYPTOBOX_SRC)
	cd $(CRYPTOBOX_SRC) && \
	sed -i.bak s/crate\-type.*/crate\-type\ =\ \[\"staticlib\"\]/g Cargo.toml && \
	$(foreach tgt,$(TARGETS),cargo rustc --lib --release --target=$(tgt);)
	mkdir -p build/lib
	$(foreach tgt,$(TARGETS),cp $(CRYPTOBOX_SRC)/target/$(tgt)/release/libcryptobox.a build/lib/libcryptobox-$(tgt).a;)

build/include/cbox.h: $(CRYPTOBOX_SRC)
	mkdir -p build/include
	cp $(CRYPTOBOX_SRC)/cbox.h build/include/

cryptobox: build/lib/libcryptobox.a build/include/cbox.h

# Build against an existing release.
cryptobox-%:
	mkdir -p build
	cd build && \
	wget -O cryptobox-ios-$*.tar.gz https://github.com/romanb/cryptobox-ios/releases/download/v$*/cryptobox-ios-$*.tar.gz && \
	tar -xzf cryptobox-ios-$*.tar.gz &&
	rm cryptobox-ios-$*.tar.gz

#############################################################################
# libsodium

include mk/libsodium-src.mk

build/lib/libsodium.a: $(LIBSODIUM_SRC)
	cp mk/ios-full.sh $(LIBSODIUM_SRC)/dist-build && \
		chmod +x $(LIBSODIUM_SRC)/dist-build/ios-full.sh && \
		cd $(LIBSODIUM_SRC) && \
		dist-build/ios-full.sh
	mkdir -p build/lib
	cp $(LIBSODIUM_SRC)/libsodium-ios/libsodium.a build/lib/libsodium.a

{'fraction_non_alphanumeric': 0.23038156947444205, 'fraction_numerical': 0.008159347252219822, 'mean_word_length': 3.6414253897550113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5570568', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1578, 'n_words': 269}