# $NetBSD: Makefile.common,v 1.3 2006/11/25 21:38:51 jdolecek Exp $

DISTNAME=		# see Makefile.${OPSYS}.${ARCH}
PKGNAME=		${MOZILLA}${MOZ_EXTRA}-bin-${MOZ_VER}
CATEGORIES=		www

MAINTAINER=		grant@NetBSD.org
HOMEPAGE?=		http://www.mozilla.org/

WRKSRC?=		${WRKDIR}/${MOZILLA}
NO_CONFIGURE=		yes
USE_LANGUAGES=		# empty

FILESDIR=		${.CURDIR}/../../www/seamonkey-bin/files
MOZILLA_SCRIPT?=	${FILESDIR}/mozilla.sh


.include "../../mk/bsd.prefs.mk"

# everything specific to your OS/Arch goes into its own Makefile
# group together i386, i486, i586 and i686 (for Linux)
ARCH=${MACHINE_ARCH:C/i[3-6]86/i386/g}

.if exists(${.CURDIR}/Makefile.${OPSYS}.${ARCH})
.  include "${.CURDIR}/Makefile.${OPSYS}.${ARCH}"
.endif

MOZILLA_SHORT=		${MOZILLA}
MOZ_DIR?=		${MOZ_VER}

.if !defined(MASTER_SITES)
_MASTER_SITES+=		http://ftp.mozilla.org/pub/mozilla.org/${MOZILLA_SHORT}/releases/${MOZ_DIR}/
_MASTER_SITES+=		ftp://ftp.mozilla.org/pub/mozilla.org/${MOZILLA_SHORT}/releases/${MOZ_DIR}/
_MASTER_SITES+=		http://public.planetmirror.com.au/pub/${MOZILLA_SHORT}/releases/${MOZ_DIR}/
_MASTER_SITES+=		ftp://public.planetmirror.com.au/pub/${MOZILLA_SHORT}/releases/${MOZ_DIR}/
_MASTER_SITES+=		ftp://ftp.tuwien.ac.at/infosys/browsers/${MOZILLA_SHORT}/releases/${MOZ_DIR}/
_MASTER_SITES+=		ftp://ftp.uni-erlangen.de/pub/mozilla.org/${MOZILLA_SHORT}/releases/${MOZ_DIR}/
_MASTER_SITES+=		ftp://ftp.fu-berlin.de/unix/network/www/${MOZILLA_SHORT}/releases/${MOZ_DIR}/
_MASTER_SITES+=		http://ftp.cvut.cz/mozilla/${MOZILLA_SHORT}/releases/${MOZ_DIR}/
.  for _site_ in ${_MASTER_SITES}
MASTER_SITES+=		${_site_}
MASTER_SITES+=		${_site_}contrib/
.  endfor
.endif

MOZILLA_LIB=	${PREFIX}/lib/${MOZILLA}${MOZ_EXTRA}-${MOZ_PLATFORM}

FILES_SUBST+=	MOZILLA=${MOZILLA:Q}
FILES_SUBST+=	MOZ_EXTRA=${MOZ_EXTRA:Q}
FILES_SUBST+=	MOZ_PLATFORM=${MOZ_PLATFORM:Q}
MESSAGE_SUBST+=	PKGBASE=${PKGBASE}
PLIST_SRC=	${WRKDIR}/PLIST_DYNAMIC

# protect against MOZ_PLATFORM being undefined so we don't bomb, but
# instead use the result of ONLY_FOR_PLATFORM.
.if defined(MOZ_PLATFORM)

.  if ${OPSYS} == "NetBSD" && ${MOZ_PLATFORM} == "linux"
MESSAGE_SRC+=	${.CURDIR}/../../www/seamonkey-bin/MESSAGE.compat_linux
.  endif

# Linux builds on NetBSD
.  if ${OPSYS} == "NetBSD" && ${MOZ_PLATFORM} == "linux"
.    include "../../emulators/suse_linux/Makefile.application"
.  elif ${OPSYS} == "NetBSD" && ${MOZ_PLATFORM} == "netbsd"
# we need libstdc++.so.4 on -current.
.    if !exists(/usr/lib/libstdc++.so.4)
DEPENDS+=	compat16>=1.6.0:../../emulators/compat16
_COMPAT16_LIBSTDCXX=	YES
.    endif
.  endif

# GTK2 builds.
.  if defined(MOZ_GTK2) && !empty(MOZ_GTK2:M[Yy][Ee][Ss])
.    if ${OPSYS} == "NetBSD" && ${MOZ_PLATFORM} == "netbsd"
DEPENDS+=	gtk2+>=2.4:../../x11/gtk2
.    elif ${OPSYS} == "NetBSD" && ${MOZ_PLATFORM} == "linux"
DEPENDS+=	suse_compat>=9.1:../../emulators/${SUSE_DIR_PREFIX}_compat
DEPENDS+=	suse_gtk2>=9.1:../../emulators/${SUSE_DIR_PREFIX}_gtk2
DEPENDS+=	suse_locale>=9.1:../../emulators/${SUSE_DIR_PREFIX}_locale
.    else
DEPENDS+=	gtk2+>=2.2:../../x11/gtk2
.    endif
.  elif ${OPSYS} == "NetBSD" && ${MOZ_PLATFORM} == "linux"
DEPENDS+=	suse_compat>=7.3:../../emulators/${SUSE_DIR_PREFIX}_compat
DEPENDS+=	suse_gtk>=7.3:../../emulators/${SUSE_DIR_PREFIX}_gtk
.  else
# default to at least gtk-1.2.
DEPENDS+=	gtk+>=1.2:../../x11/gtk
.  endif

.endif	# defined(MOZ_PLATFORM)

INSTALLATION_DIRS=	bin

SUBST_CLASSES+=		paths
SUBST_FILES.paths=	${WRKDIR}/${MOZILLA}.sh
SUBST_SED.paths+=	-e 's,@PREFIX@,${PREFIX},g'
SUBST_SED.paths+=	-e 's,@SH@,${SH},g'
SUBST_SED.paths+=	-e 's,@MOZILLA@,${MOZILLA},g'
SUBST_SED.paths+=	-e 's,@MOZ_EXTRA@,${MOZ_EXTRA},g'
SUBST_SED.paths+=	-e 's,@MOZ_PLATFORM@,${MOZ_PLATFORM},g'
SUBST_STAGE.paths=	post-patch

# we don't want libnullplugin.
post-extract:
	@${RM} -f ${WRKSRC}/plugins/libnullplugin.so
	${CP} ${MOZILLA_SCRIPT} ${WRKDIR}/${MOZILLA}.sh

do-build:

do-install:
	${INSTALL_DATA_DIR} ${MOZILLA_LIB}
	cd ${WRKSRC} && ${PAX} -rw -pm . ${MOZILLA_LIB}
	${INSTALL_SCRIPT} ${WRKDIR}/${MOZILLA}.sh ${PREFIX}/bin/${MOZILLA}${MOZ_EXTRA}-${MOZ_PLATFORM}
	@${FIND} ${MOZILLA_LIB} -type f -print \
		| ${XARGS} ${CHMOD} a+r
	@${FIND} ${MOZILLA_LIB} \( -type f -o -perm -u+x \) -print \
		| ${XARGS} ${CHMOD} a+rx
	@${FIND} ${MOZILLA_LIB} -type d -print \
		| ${XARGS} ${CHMOD} a+rx

# builds typically want exactly 'libgtk-1.2.so.0', etc. symlink them
# into the mozilla directory.
post-install:
.if ${OPSYS} != "NetBSD"
.  if defined(MOZ_GTK2) && ${MOZ_GTK2} == "YES"
	@cd ${MOZILLA_LIB} && \
	${LN} -s ${PREFIX}/lib/libatk-1.0.*so* .;			\
	${LN} -s ${X11PREFIX}/lib/libgdk-x11-2.0.*so* .;		\
	${LN} -s ${PREFIX}/lib/libgdk_pixbuf-2.0.*so* .;		\
	${LN} -s ${PREFIX}/lib/libglib-2.0.*so* .;			\
	${LN} -s ${PREFIX}/lib/libgmodule-2.0.*so* .;			\
	${LN} -s ${PREFIX}/lib/libgobject-2.0.*so* .;			\
	${LN} -s ${X11PREFIX}/lib/libgtk-x11-2.0.*so* .;		\
	${LN} -s ${PREFIX}/lib/libpango-1.0.*so* .;			\
	${LN} -s ${PREFIX}/lib/libpangox-1.0.*so* .;			\
	${LN} -s ${PREFIX}/lib/libpangoxft-1.0.*so* .;			\
	\
	${LN} -s libatk-1.0.so libatk-1.0.so.0;				\
	${LN} -s libgdk-x11-2.0.so libgdk-x11-2.0.so.0;			\
	${LN} -s libgdk_pixbuf-2.0.so libgdk_pixbuf-2.0.so.0;		\
	${LN} -s libglib-2.0.so libglib-2.0.so.0;			\
	${LN} -s libgmodule-2.0.so libgmodule-2.0.so.0;			\
	${LN} -s libgobject-2.0.so libgobject-2.0.so.0;			\
	${LN} -s libgtk-x11-2.0.so libgtk-x11-2.0.so.0;			\
	${LN} -s libpango-1.0.so libpango-1.0.so.0;			\
	${LN} -s libpangox-1.0.so libpangox-1.0.so.0;			\
	${LN} -s libpangoxft-1.0.so libpangoxft-1.0.so.0
.  else
	@cd ${MOZILLA_LIB} && \
	${LN} -s ${PREFIX}/lib/libglib.*so* .;				\
	${LN} -s ${PREFIX}/lib/libgmodule.*so* .;			\
	${LN} -s ${X11PREFIX}/lib/libgdk.*so* .;			\
	${LN} -s ${X11PREFIX}/lib/libgtk.*so* .;			\
	${LN} -s libgtk.so libgtk-1.2.so.0;				\
	${LN} -s libgdk.so libgdk-1.2.so.0;				\
	${LN} -s libglib.so libglib-1.2.so.0;				\
	${LN} -s libgmodule.so libgmodule-1.2.so.0
.  endif
.endif
.if defined(_COMPAT16_LIBSTDCXX) && ${_COMPAT16_LIBSTDCXX} == "YES"
	@cd ${MOZILLA_LIB} && \
		${LN} -s ${PREFIX}/emul/netbsd16/usr/lib/libstdc++.so* .
.endif
	@${INSTALL_DATA_DIR} ${PREFIX}/lib/mozilla-linux/plugins
	@${CP} -f ${PKGDIR}/PLIST ${PLIST_SRC}
	@${ECHO} bin/${MOZILLA}${MOZ_EXTRA}-${MOZ_PLATFORM} >> ${PLIST_SRC}
	@${FIND} ${MOZILLA_LIB} \( -type f -o -type l \) -print		\
		| ${SORT} | ${SED} -e "s,${PREFIX}/,,g"			\
		>> ${PLIST_SRC}
	@${FIND} ${MOZILLA_LIB} -type d -print				\
		| ${SORT} -r | ${SED} -e "s,${PREFIX}/,@dirrm ,g"	\
		>> ${PLIST_SRC}
	@${ECHO} @exec ${MKDIR} %D/lib/mozilla-linux/plugins >> ${PLIST_SRC}

.include "../../mk/bsd.pkg.mk"