PROJECT = groff
SOURCE_VCS = cvs
TARGET_VCS = git
VERBOSITY = "verbose 1"

# Configuration ends here

.PHONY: local-clobber remote-clobber gitk gc compare clean dist

default: $(PROJECT)-$(TARGET_VCS)

# Build the repo from the fast-import stream
$(PROJECT)-$(TARGET_VCS): $(PROJECT).fi
	rm -fr $(PROJECT)-$(TARGET_VCS); reposurgeon "read $(PROJECT).fi" "prefer $(TARGET_VCS)" "rebuild $(PROJECT)-$(TARGET_VCS)"

# Mirror the groff repo
groff-mirror:
	rsync -av cvs.sv.nongnu.org::sources/groff/ groff-mirror

# Make a checkout of it.
groff-checkout:
	cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/groff co groff-mirror

# Get a stream from the repo mirror.  We don't need reposurgron annotations 
# because the comments don't use RCS revision numbers.
groff-raw.fi:
	find groff-mirror -name '*,v' -print | cvs-fast-export -A groff.authormap -k >groff-raw.fi

# Edit the raw fast-import stream
groff.fi: groff-raw.fi groff.lift 
	reposurgeon "script groff.lift"

#
# The following productions are git-specific
#

# Browse the generated git repository
gitk: $(PROJECT)-git
	cd $(PROJECT)-git; gitk --all

# Run a garbage-collect on the generated git repository.  Import doesn't.
# This repack call is the active part of gc --aggressive.  This call is
# tuned for very large repositories.
gc: $(PROJECT)-git
	cd $(PROJECT)-git; time git -c pack.threads=1 repack -AdF --window=1250 --depth=250

# General cleanup and utility
clean:
	rm -fr *~ .rs* $(PROJECT)-conversion.tar.gz REPODIFFER.LOG

# Bundle up the conversion metadata for shipping
SOURCES = Makefile $(PROJECT).lift $(PROJECT).authormap $(EXTRAS)
$(PROJECT)-conversion.tar.gz: $(SOURCES)
	tar --dereference --transform 's:^:$(PROJECT)-conversion/:' -czvf $(PROJECT)-conversion.tar.gz $(SOURCES)

dist: $(PROJECT)-conversion.tar.gz

