CC = swiftc
CFLAGS = -g
FLAGS = -g

build_minizip:
	@:$(if $(value MACOS_VERSION),,$(error MACOS_VERSION is not defined))
	@$(MAKE) -C minizip CFLAGS=$(CFLAGS) MACOS_VERSION=$(MACOS_VERSION) all

./arm64/libzip.a: Zip.swift QuickZip.swift ZipUtilities.swift \
	./minizip/arm64/zip.o ./minizip/arm64/unzip.o ./minizip/arm64/ioapi.o
	@:$(if $(value MACOS_VERSION),,$(error MACOS_VERSION is not defined))
	swiftc -target arm64-apple-macos$(MACOS_VERSION) -I./minizip/module \
		-I./minizip/include -L./minizip/arm64 $(FLAGS) -static \
		-module-name Zip -emit-library -emit-module -parse-as-library \
		$^ -o $@

./x86_64/libzip.a: Zip.swift QuickZip.swift ZipUtilities.swift \
	./minizip/x86_64/zip.o ./minizip/x86_64/unzip.o \
	./minizip/x86_64/ioapi.o
	@:$(if $(value MACOS_VERSION),,$(error MACOS_VERSION is not defined))
	@swiftc -target x86_64-apple-macos$(MACOS_VERSION) -I./minizip/module \
		-I./minizip/include -L./minizip/x86_64 $(FLAGS) -static \
		-module-name Zip -emit-library -emit-module -parse-as-library \
		$^ -o $@

all: build_minizip ./arm64/libzip.a ./x86_64/libzip.a

clean:
	rm -rf arm64 x86_64
	mkdir arm64 x86_64

clean-all: clean
	$(MAKE) -C minizip clean
