###############################
#
#  Main Makefile for Coq 6.2
# 
###############################

include ./config

MAKE=make

noarguments:
	@echo Please use either
	@echo ./configure
	@echo make world
	@echo make world-opt
	@echo make install
	@echo make cleanall
	@echo or make archclean


#######################
# Building the system #
#######################

world:
	@$(MAKE) "OPT=" "ALL=byte" common-world
	@echo "=== Compilation in bytecode is done ==="

world-opt:
	@$(MAKE) "OPT=-opt" "ALL=opt" common-world
	@echo "=== Compilation in native code is done ==="

small-world:
	@$(MAKE) "OPT=" "ALL=byte" common-small-world
	@echo "=== Compilation in bytecode is done (small version) ==="

small-world-opt:
	@$(MAKE) "OPT=-opt" "ALL=opt" common-small-world
	@echo "=== Compilation in native code is done (small version) ==="


###################################################
# Building the system for profiling and debugging #
###################################################

debug:
	cd tactics/contrib; $(MAKE) coq-debug
	@echo "=== Compilation for debugging is done (bytecode version) ==="

profile:
	(cd tactics/contrib; $(MAKE) coq-profile)
	@echo "=== Compilation for profiling is done (native code version) ==="

common-world: bin-arch config-file utils build-src library full

common-small-world: bin-arch config-file utils build-src small-library small

bin-arch:
	if test -d bin/$(ARCH); then : ; else $(MKDIR) bin/$(ARCH); fi
	if test -d states; then : ; else $(MKDIR) states; fi

config-file:
	cd src/config ; $(MAKE) $(COQTOOLS)

utils:
	cd tools ; $(MAKE) ALL=$(ALL)

build-src: images coqstates

images:
	(cd src ; $(MAKE) $(ALL))

coqstates:
	cd src ; $(MAKE) barestate.coq install-barestate
	cd theories/INIT ; $(MAKE) $(ALL)
	cd src ; $(MAKE) state.coq install-state
	cd tactics ; $(MAKE) $(ALL)
	cd src ; $(MAKE) tactics.coq install-tactics

profile-src:
	@$(MAKE) "OPT=-opt" "ALL=opt" "TIMEPROF=-p" build-src

library:
	@echo "Now we build the Coq library"
	cd theories ; $(MAKE) library

small-library:
	@echo "Now we build the Coq library (small version)"
	cd theories ; $(MAKE) small-library


full:
	cd tactics/contrib; $(MAKE) $(ALL)
	cd theories/REALS; $(MAKE) $(ALL)

small:
	cd tactics/contrib; $(MAKE) $(ALL)small

demos:
	cd theories; $(MAKE) OPT=-full others

#####################
# True installation #
#####################

COQINSTALLPREFIX= # Can be changed for a local installation (to make packages)

install: mkdir-lib install-binaries install-library install-manpages
	-(cd tools/emacs ; make install)
	echo $(COQLIB)/COQFILES >> $(COQINSTALLPREFIX)/$(COQLIB)/COQFILES
	@echo "=== Your installation is done ==="

mkdir-lib:
	if test -d $(COQINSTALLPREFIX)/$(COQLIB); then : ; else $(MKDIR) $(COQINSTALLPREFIX)/$(COQLIB); fi

install-binaries:
	- rm -f $(COQINSTALLPREFIX)/$(COQLIB)/COQFILES
	cd bin ; make install-binaries
	cd src ; $(MAKE) install-library

install-manpages:
	cd src/man ; make install-manpages
	cd tools ; make install-manpages

install-library:
	cd states ; $(MAKE) install-library
	cd theories ; $(MAKE) install-library
	cd tactics ; $(MAKE) install-library

##################
# TAGS for Emacs #
##################

tags:
	find . -name "*.ml*" | sort -r | xargs \
	etags "--regex=/let[ \t]+\([^ \t]+\)/\1/" \
	      "--regex=/let[ \t]+rec[ \t]+\([^ \t]+\)/\1/" \
	      "--regex=/and[ \t]+\([^ \t]+\)/\1/" \
	      "--regex=/type[ \t]+\([^ \t]+\)/\1/" \
              "--regex=/exception[ \t]+\([^ \t]+\)/\1/" \
	      "--regex=/val[ \t]+\([^ \t]+\)/\1/" \
	      "--regex=/module[ \t]+\([^ \t]+\)/\1/"

################
# dependencies #
################

depend:
	cd tools; $(MAKE) depend
	cd src; $(MAKE) depend
	cd tactics; $(MAKE) depend
	cd theories; $(MAKE) depend


############
# Cleaning #
############

cleanall: clean-bin-arch clean-states clean-src clean-others
	@echo "=== Your installation is cleaned ==="

clean-src:
	cd src ; $(MAKE) clean
	cd tools; $(MAKE) clean

clean-others:
	cd tactics ; $(MAKE) clean
	cd theories ; $(MAKE) clean
	cd theories/INIT ; $(MAKE) clean

clean-states:
	rm -f states/*.coq 

clean-bin-arch:
	rm -rf bin/$(ARCH)

clean-config:
	rm -f src/config/coq_config.* config

archclean:
	cd src ; $(MAKE) archclean
	cd theories ; $(MAKE) archclean
	cd tactics ; $(MAKE) archclean
	cd tools ; $(MAKE) archclean
	rm -f src/config/coq_config.ml config
	@echo "=== The system is ready to compile for a new architecture ==="

# $Id: Makefile,v 1.65 1999/06/30 10:56:51 loiseleu Exp $
