
# $Id: Makefile,v 1.13 2020/12/24 20:46:46 gilles Exp gilles $	

TARGET=pop2imap

.PHONY: help usage all

help: usage

usage:
	@echo "      $(TARGET) $(VERSION), You can do :"
	@echo make install # as root
	@echo make testf   # run tests
	@echo make testv   # run tests verbosely
	@echo make all     

all: test ChangeLog.txt README.txt VERSION.txt

.PHONY: test testp testf

.test: $(TARGET) tests.sh
	sh tests.sh 1>/dev/null
	touch .test

testv:
	sh -x tests.sh

test: .test

testf: clean_test test

testp :
	perl -c $(TARGET)

ChangeLog.txt: $(TARGET)
	rlog $(TARGET) > ChangeLog.txt

README.txt: $(TARGET)
	perldoc -t $(TARGET) > README.txt

VERSION.txt: $(TARGET) Makefile
	./$(TARGET) --version > VERSION.txt

.PHONY: clean clean_tilde clean_test   

clean: clean_tilde clean_test

clean_test:
	rm -f .test

clean_tilde:
	rm -f *~

.PHONY: install dist

install: testp
	cp $(TARGET) /usr/bin/$(TARGET)
	chmod 755 /usr/bin/$(TARGET)

DIST_NAME=$(TARGET)-$(VERSION)
DIST_FILE=$(DIST_NAME).tgz
VERSION=$(shell ./$(TARGET) --version)

DISTRO_NAME := $(shell lsb_release -i -s || echo Unknown)
DISTRO_RELEASE := $(shell lsb_release -r -s || echo 0.0)
DISTRO_CODE := $(shell lsb_release -c -s || echo Unknown)
DISTRO := $(DISTRO_NAME)_$(DISTRO_RELEASE)_$(DISTRO_CODE)

hello:
	@echo "VERSION          $(VERSION)"
	@echo "DIST_NAME        $(DIST_NAME)"
	@echo "DISTRO           $(DISTRO)"



dist: cidone clean clean_dist all INSTALL.txt
	echo making tarball $(DIST_FILE)
	mkdir -p dist
	mkdir -p ../prepa_dist/$(DIST_NAME)
	rsync -aCv --delete ./  ../prepa_dist/$(DIST_NAME)
	cd ../prepa_dist && tar czfv $(DIST_FILE) $(DIST_NAME)
	cp -f ../prepa_dist/$(DIST_FILE) dist/
	cd dist && md5sum $(DIST_FILE) > $(DIST_FILE).md5
	cd dist && md5sum -c $(DIST_FILE).md5



.PHONY: cidone clean_dist

cidone:
	rcsdiff RCS/*

clean_dist:
	rm -f dist/*

# Local goals

.PHONY: lfo ks prereq exe testexe ci


lfo: cidone dist 
	rsync -av --delete . \
	/home/gilles/public_html/www.linux-france.org/html/prj/$(TARGET)/
	sh ~/memo/lfo-rsync

ks: cidone
	rsync -av --delete . \
	gilles@ks.lamiral.info:public_html/$(TARGET)/


prereq: W/prereq.scandeps.$(DISTRO).txt

W/prereq.scandeps.$(DISTRO).txt: $(TARGET)
	scandeps -c -x  $(TARGET) | tee W/prereq.scandeps.$(DISTRO).txt
	rcsdiff W/prereq.scandeps.$(DISTRO).txt || { echo 'rcsdiff detected a diff' | ci -l W/prereq.scandeps.$(DISTRO).txt ; }



exe: $(TARGET)_64bit.exe

$(TARGET)_64bit.exe: $(TARGET)
	(date "+%s"| tr "\n" " "; echo -n "BEGIN 64bit " $(VERSION) ": "; date) >> W/.BUILD_EXE_TIME
	ssh 'pc HP DV7'@p24 'perl -V'
	unix2dos W/build_exe.bat W/test_exe.bat W/install_modules.bat
	scp $(TARGET) pop2imap_example.bat W/build_exe.bat W/install_modules.bat W/install_module_one.bat \
	W/test_exe_tests.bat W/test_exe_testsdebug.bat W/test_exe.bat ./W/check_win64err \
	pc_HP_DV7_p24:'Desktop/$(TARGET)_build'
	ssh 'pc HP DV7'@p24 'Desktop/$(TARGET)_build/build_exe.bat'
	./W/check_win64err build_exe.bat
	ssh 'pc HP DV7'@p24 'Desktop/$(TARGET)_build/test_exe_tests.bat'
	./W/check_win64err test_exe_tests.bat
	ssh 'pc HP DV7'@p24 'Desktop/$(TARGET)_build/test_exe.bat'
	./W/check_win64err test_exe.bat
	rm -f $(TARGET)_64bit.exe
	scp pc_HP_DV7_p24:'Desktop/$(TARGET)_build/$(TARGET)_64bit.exe' .
	chmod a+r+x $(TARGET)_64bit.exe
	mv $(TARGET)_64bit.exe $(TARGET).exe
	(date "+%s"| tr "\n" " "; echo -n "END   64bit " $(VERSION) ": "; date) >> W/.BUILD_EXE_TIME


testexe:
	ssh 'pc HP DV7'@p24 'Desktop/$(TARGET)_build/test_exe.bat'
	./W/check_win64err test_exe.bat


ci:
	rcsdiff $(TARGET) *.sh *.bat *.txt Makefile



