#!/usr/bin/make -f

package := NotePad.apk

all: out/signed-$(package)

clean:
	rm -rf out

.PHONY: FORCE

DSAPARAM := out/dsaparam
$(DSAPARAM):
	mkdir -p $(dir $@)
	umask 0077 && openssl dsaparam -out $@ 1024

%.pem: $(DSAPARAM) FORCE
	mkdir -p $(dir $@)
	umask 0077 && openssl gendsa -out $@.pk~ $(DSAPARAM)
	umask 0077 && openssl pkcs8 -topk8 -nocrypt \
		-in $@.pk~ -out $@.pk
	umask 0077 && openssl req -new -x509 -key $@.pk -out $@ -days 1095 \
	    -subj "/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com"

cert := out/key1.pem
out/signed-$(package): $(package) $(cert)
	mkdir -p $(dir $@)
	SIGNAPK_DEBUG=1 \
	signapk -input $< -output $@ \
		-key $(cert).pk -cert $(cert) -tempdir out
