# 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/.

XPI_MODULE	= enigmail
XPI_MODULE_VERS = 1.6

DEPTH		= ../../..
topsrcdir	= @top_srcdir@
srcdir		= @srcdir@
VPATH		= @srcdir@

include $(DEPTH)/config/autoconf.mk

MOZILLA_VERSION_PARTS = $(subst ., ,$(MOZILLA_VERSION))
MOZILLA_MAJOR_VERSION = $(firstword $(MOZILLA_VERSION_PARTS))
TMP_VAR = $(word 2,$(MOZILLA_VERSION_PARTS))
MOZILLA_MINOR_VERSION = $(shell echo $(TMP_VAR)|sed 's/[a-z].*//')

GECKO18 = $(shell test $(MOZILLA_MAJOR_VERSION) -lt 19 && echo 1)

DIRS = ipc public

ifeq ($(GECKO18),1)
  DIRS += src build
endif

DIRS += ui package lang

PLATFORM_STR = unknown

# Edit the lines below as needed, depending upon your platform(s)
ifeq ($(OS_ARCH),Linux)
PLATFORM_STR = linux
endif

ifeq ($(OS_ARCH),WIN95)
PLATFORM_STR = win32
endif

ifeq ($(OS_ARCH),WINNT)
PLATFORM_STR = win32
endif

ifeq ($(OS_CONFIG),SunOS5)
PLATFORM_STR = sunos5
endif

ifeq ($(OS_ARCH),Darwin)
PLATFORM_STR = darwin
# from $(topsrcdir)/config/config.mk
ifdef MACOSX_DEPLOYMENT_TARGET
export MACOSX_DEPLOYMENT_TARGET
endif # MACOSX_DEPLOYMENT_TARGET
endif

ifeq ($(OS_ARCH),FreeBSD)
PLATFORM_STR = freebsd
endif

ifeq ($(OS_ARCH),OpenBSD)
PLATFORM_STR = openbsd
endif

ifeq ($(OS_ARCH),OS2)
PLATFORM_STR = os2
endif

ifeq ($(OS_ARCH),OSF1)
PLATFORM_STR = osf1
endif

XPIFILE = $(XPI_MODULE)-$(XPI_MODULE_VERS)-$(PLATFORM_STR)-$(TARGET_CPU)$(TENFOURBIRD_TUNED).xpi

ifeq ($(TARGET_XPCOM_ABI),)
ENIG_XPCOM_ABI = $(OS_ARCH)
else
ENIG_XPCOM_ABI = $(OS_ARCH)_$(TARGET_XPCOM_ABI)
endif

.PHONY: dirs $(DIRS)

all: dirs

dirs: $(DIRS)

$(DIRS):
	$(MAKE) -C $@

xpi:
	$(srcdir)/genxpi $(XPIFILE) $(XPI_MODULE_VERS) $(OS_ARCH) "$(TARGET_XPCOM_ABI)" $(MOZ_APP_NAME)-$(MOZ_APP_VERSION) $(DIST)/bin $(srcdir) $(XPI_MODULE) $(DLL_SUFFIX) $(LIB_PREFIX) $(TENFOURBIRD_TUNED)

clean:
	test -f $(DIST)/bin/$(XPIFILE) && rm $(DIST)/bin/$(XPIFILE) || echo ""
	for dir in $(DIRS); do \
	  $(MAKE) -C $$dir clean; \
	done
