all: linux-server linux-client win-server win-client mac-server mac-client
win-server: obj/server-windows/x86 obj/server-windows/x64  obj/server-windows/arm64
win-client: obj/client-windows/x86 obj/client-windows/x64 obj/client-windows/arm64
mac-server: obj/server-mac/x64  obj/server-mac/arm64
mac-client: obj/client-mac/x64  obj/client-mac/arm64
linux-server: obj/server-linux/x64 obj/server-linux/arm obj/server-linux/arm64
linux-client: obj/client-linux/x64 obj/client-linux/arm obj/client-linux/arm64 

blazor:
	mkdir -p obj/wwwroot
	cd TessesDedupWeb && dotnet publish -o ../obj/ -c Release

obj/server-linux/%: blazor
	rm -rf $@/data/wwwroot || true
	mkdir -p $@ || true && cd "TessesDedupServer" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r linux-$(notdir $@)
	mkdir -p $@/data/
	cp -r obj/wwwroot $@/data/wwwroot
	mkdir -p publish/server
	cd $@ && tar cvzf ../../../publish/server/tessesbackup-linux-server-$(notdir $@).tar.gz .

obj/client-linux/%:
	mkdir -p $@ || true && cd "TessesDedupClient" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r linux-$(notdir $@)
	mkdir -p publish/client
	cd $@ && tar cvzf ../../../publish/client/tessesbackup-linux-client-$(notdir $@).tar.gz .


obj/server-mac/%: blazor
	rm -rf $@/data/wwwroot || true
	mkdir -p $@ || true && cd "TessesDedupServer" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r osx-$(notdir $@)
	mkdir -p $@/data/
	cp -r obj/wwwroot $@/data/wwwroot
	mkdir -p publish/server
	cd $@ && tar cvzf ../../../publish/server/tessesbackup-macos-server-$(notdir $@).tar.gz .

obj/client-mac/%:
	mkdir -p $@ || true && cd "TessesDedupClient" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r osx-$(notdir $@)
	mkdir -p publish/client
	cd $@ && tar cvzf ../../../publish/client/tessesbackup-macos-client-$(notdir $@).tar.gz .

obj/server-windows/%: blazor
	rm -rf $@/data/wwwroot || true
	mkdir -p $@ || true && cd "TessesDedupServer" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r win-$(notdir $@)
	mkdir -p $@/data/
	cp -r obj/wwwroot $@/data/wwwroot
	mkdir -p publish/server
	cd $@ && zip -r ../data.zip . && mv ../data.zip ../../../publish/server/tessesbackup-windows-server-$(notdir $@).zip

obj/client-windows/%:
	mkdir -p $@ || true && cd "TessesDedupClient" && dotnet publish -c Release -o ../$@ --self-contained -p:PublishReadyToRun=true -p:PublishSingleFile=true -r win-$(notdir $@)
	mkdir -p publish/client
	cd $@ && zip -r ../data.zip . && mv ../data.zip ../../../publish/client/tessesbackup-windows-client-$(notdir $@).zip
	
test:
	cd TessesDedupWeb && dotnet build
	cd TessesDedupServer && dotnet build
	cd TessesDedupClient && dotnet build