#Makefile: Debian package creation
deb: BINFILES/youtube-dl.deb

BINFILES/youtube-dl.deb: youtube-dl clean
	mkdir -p DebData DebControl
	$(MAKE) install DESTDIR=DebData
	cd DebData && find usr -type f -print0 | xargs -0 md5sum > ../DebControl/md5sums && tar -cJf ../data.tar.xz ./*
	rm -R DebData
	cp DebianPkg/conffiles DebianPkg/p* DebControl/
	env echo -ne "Package: youtube-dl\nVersion: " > DebControl/control
	devscripts/version.sh -r >> DebControl/control
	env echo -ne "\nArchitecture: all\nMaintainer: Grace Past <gpast_panama@protonmail.com>\nInstalled-Size: " >> DebControl/control
	du | tail -1 | awk '{ print $1 }' >> DebControl/control
	cat DebianPkg/control >> DebControl/control
	cd DebControl && tar -czf ../control.tar.gz ./*
	rm -R DebControl
	echo 2.0 > debian-binary
	$(AR) rcs BINFILES/youtube-dl.deb debian-binary control.tar.gz data.tar.xz
	rm debian-binary control.tar.gz data.tar.xz