# -*- Makefile -*-
#*****************************************************************************
#
# DESCRIPTION: Verilator: Makefile for verilog source
#
# Code available from: http://www.veripool.org/verilator
#
#*****************************************************************************
#
# Copyright 2003-2009 by Wilson Snyder.  This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
#
# Verilator is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
#****************************************************************************/

#### Start of system configuration section. ####

srcdir = @srcdir@
VPATH = @srcdir@
PERL = @PERL@

#### End of system configuration section. ####


default: dbg opt
debug: dbg
optimize: opt

ifeq ($(OBJCACHE_HOSTS),)
 ifneq ($(SLCHOOSED_HOST),)
  ifeq ($(VERILATOR_AUTHOR_SITE),1)
export OBJCACHE_HOSTS := $(shell rschedule --no-allow-reserved --similar hostnames)
  endif
 endif
endif

ifeq ($(OBJCACHE_JOBS),)
ifneq ($(OBJCACHE_HOSTS),)
export OBJCACHE_JOBS := -j $(shell objcache --jobs "$(OBJCACHE_HOSTS)")
endif
endif

UNDER_GIT = $(wildcard ../.git/logs/HEAD)

#*********************************************************************

obj_opt:
	mkdir $@
obj_dbg:
	mkdir $@

.PHONY: ../verilator_bin ../verilator_bin_dbg

opt: ../verilator_bin
ifeq ($(VERILATOR_NO_OPT_BUILD),1)	# Faster laptop development... One build
../verilator_bin: ../verilator_bin_dbg
	cp -p $< $@
	@-cp -p $<.exe $@.exe
else
../verilator_bin: obj_opt prefiles
	cd obj_opt && $(MAKE) -j 1             TGT=../$@ -f ../Makefile_obj serial
	cd obj_opt && $(MAKE) $(OBJCACHE_JOBS) TGT=../$@ -f ../Makefile_obj
endif

dbg: ../verilator_bin_dbg
../verilator_bin_dbg: obj_dbg prefiles
	cd obj_dbg && $(MAKE) -j 1             TGT=../$@ VL_DEBUG=1 -f ../Makefile_obj serial
	cd obj_dbg && $(MAKE) $(OBJCACHE_JOBS) TGT=../$@ VL_DEBUG=1 -f ../Makefile_obj

prefiles::

ifneq ($(UNDER_GIT),)	# If local git tree... Else don't burden users
prefiles:: config_rev.h
# This output goes into srcdir, as we need to distribute it as part of the kit.
config_rev.h:	config_rev.pl ../.git/logs/HEAD
	$(PERL) config_rev.pl . >$@
endif

maintainer-copy::
clean mostlyclean distclean maintainer-clean::
	-rm -rf obj_* *.log *.dmp *.vpd core
	-rm -f *.o *.d perlxsi.c *_gen_*
	-rm -f *__gen*
	-rm -f .objcache*

distclean maintainer-clean::
	-rm -f Makefile Makefile_obj config_build.h
