# vim: set shiftwidth=8 tabstop=8 autoindent noexpandtab copyindent:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

DEPTH		= @DEPTH@
topsrcdir	= @top_srcdir@
srcdir		= @srcdir@
VPATH		= @srcdir@

include $(DEPTH)/config/autoconf.mk

MODULE		= reftest

EXTRA_COMPONENTS= \
		reftest-cmdline.js \
		$(NULL)

ifdef XPI_NAME
NO_JS_MANIFEST = 1
DIST_FILES = install.rdf

ifeq ($(MOZ_BUILD_APP),mobile/android)
DEFINES += -DBOOTSTRAP
DIST_FILES += bootstrap.js
endif

ifeq ($(MOZ_BUILD_APP),b2g)
DEFINES += -DBOOTSTRAP
DEFINES += -DREFTEST_B2G
endif

# Used in install.rdf
USE_EXTENSION_MANIFEST=1
else
EXTRA_COMPONENTS += reftest-cmdline.manifest
endif

include $(topsrcdir)/config/rules.mk

# We're installing to _tests/reftest
TARGET_DEPTH = ../..
include $(topsrcdir)/build/automation-build.mk

_DEST_DIR = $(DEPTH)/_tests/reftest

# We want to get an extension-packaged version of reftest as well, 
# so this seems to be the simplest way to make that happen.
ifndef XPI_NAME
make-xpi:
	+$(MAKE) -C $(DEPTH)/netwerk/test/httpserver libs XPI_NAME=reftest
	+$(MAKE) libs XPI_NAME=reftest
copy-harness: make-xpi
libs:: copy-harness
endif

_HARNESS_FILES = \
  $(srcdir)/runreftest.py \
  $(srcdir)/remotereftest.py \
  $(srcdir)/runreftestb2g.py \
  $(srcdir)/b2g_start_script.js \
  automation.py \
  $(topsrcdir)/build/mobile/devicemanager.py \
  $(topsrcdir)/build/mobile/devicemanagerADB.py \
  $(topsrcdir)/build/mobile/devicemanagerSUT.py \
  $(topsrcdir)/build/mobile/b2gautomation.py \
  $(topsrcdir)/build/automationutils.py \
  $(topsrcdir)/build/mobile/remoteautomation.py \
  $(topsrcdir)/testing/mochitest/server.js \
  $(topsrcdir)/build/pgo/server-locations.txt \
  $(NULL)

$(_DEST_DIR):
	$(NSINSTALL) -D $@

$(_HARNESS_FILES): $(_DEST_DIR)

# copy harness and the reftest extension bits to $(_DEST_DIR)
copy-harness: $(_HARNESS_FILES)
	$(INSTALL) $(_HARNESS_FILES) $(_DEST_DIR)
	(cd $(DIST)/xpi-stage && tar $(TAR_CREATE_FLAGS) - reftest) | (cd $(_DEST_DIR) && tar -xf -)

PKG_STAGE = $(DIST)/test-package-stage

# stage harness and tests for packaging
stage-package:
	$(NSINSTALL) -D $(PKG_STAGE)/reftest && $(NSINSTALL) -D $(PKG_STAGE)/reftest/tests
	(cd $(DEPTH)/_tests/reftest/ && tar $(TAR_CREATE_FLAGS_QUIET) - *) | (cd $(PKG_STAGE)/reftest && tar -xf -)
	$(PYTHON) $(topsrcdir)/layout/tools/reftest/print-manifest-dirs.py \
          $(topsrcdir) \
          $(topsrcdir)/layout/reftests/reftest.list \
          $(topsrcdir)/testing/crashtest/crashtests.list \
          | (cd $(topsrcdir) && xargs tar $(TAR_CREATE_FLAGS_QUIET) -) \
          | (cd $(PKG_STAGE)/reftest/tests && tar -xf -)
