
#****************************************************************************#
# The information contained in this file is confidential and proprietary to  #
# Broadcom Corporation.  No part of this file may be reproduced or           #
# distributed, in any form or by any means for any purpose, without the      #
# express written permission of Broadcom Corporation.                        #
#                                                                            #
# (c) COPYRIGHT 2010-2013 Broadcom Corporation, ALL RIGHTS RESERVED.         #
#****************************************************************************#

VERSION_FILE = "../src/version.h"
include ../Makefile.inc

DATE = date '+%Y%m%d'
PKGVERS=\"Version=$(BRCMVERSION),REV=$(DATE:sh).$(BRCMVERSION)\"


all:
	$(MAKE) BRCMbge_PKG BPATH=rel
	$(MAKE) BRCMbge_PKG BPATH=dbg DBGPKG=-dbg
	if test "$(ILLUMOS)" = ""; then $(MAKE) BRCMbge_DU; fi


PKGNAME = BRCMbge-$(BUILD_VER)-$(OSARCH)-$(BRCMVERSION)$(DBGPKG)
PKGTMP  = $(OSARCH)-$(BUILD_VER)

PKGFILES = \
  ../build_$(BPATH)_32_$(OSARCH)-$(BUILD_VER)/bge32 \
  ../build_$(BPATH)_64_$(OSARCH)-$(BUILD_VER)/bge64

PROTO_MANPAGE_SRC = \
    if test "$(OSREL)" = "5.11" -o "$(OSREL)" = "5.12"; then echo "bge.7d"; \
    else echo "bge.7d.s10"; \
    fi
PROTO_MANPAGE = $(PROTO_MANPAGE_SRC:sh) 

PROTO_ARCH_SRC = \
    if test "$(OSARCH)" = "sparc"; then echo "sparcv9"; \
    else echo "amd64"; \
    fi
PROTO_ARCH = $(PROTO_ARCH_SRC:sh) 

PROTO_BGE_32BIT_SRC = \
    if test "$(OSREL)" = "5.11" -o "$(OSREL)" = "5.12" -o "$(OSARCH)" = "sparc"; then echo ""; \
    else echo "f none kernel/drv/bge=PREFIX/bge32 0755 root sys"; \
    fi
PROTO_BGE_32BIT = $(PROTO_BGE_32BIT_SRC:sh)

PROTO_BGE_64BIT_SRC = \
    echo "f none kernel/drv/ARCH/bge=PREFIX/bge64 0755 root sys";
PROTO_BGE_64BIT = $(PROTO_BGE_64BIT_SRC:sh)


rawpkg:
	-mkdir $(PKGTMP)
	for pf in $(PKGFILES); do \
	    if [ -d `dirname $$pf` ]; then \
	        cp $$pf $(PKGTMP); \
	    fi; \
	done
	sed -e "s/VERSION.*/VERSION=v$(BRCMVERSION)/" \
	    -e "s/PRODVERS.*/PRODVERS=v$(BRCMVERSION)/" \
	    -e "s/OSREL.*/OSREL=$(OSREL)/" \
	    -e "s/ARCH.*/ARCH=$(OSARCH)/" pkginfo.src > $(PKGTMP)/pkginfo
	sed -e "s|BGE_32BIT|$(PROTO_BGE_32BIT)|" \
	    -e "s|BGE_64BIT|$(PROTO_BGE_64BIT)|" \
	    -e "s/PREFIX/$(PKGTMP)/g" \
	    -e "s/ARCH/$(PROTO_ARCH)/g" \
	    -e "s/MANPAGE/$(PROTO_MANPAGE)/g" \
	    -e "/^$$/d" \
	    prototype > prototype-$(PKGTMP)
	pkgmk -f prototype-$(PKGTMP) -o -d $(PKGTMP)
	-rm -f prototype-$(PKGTMP)


BRCMbge_PKG: rawpkg
	-rm -f $(PKGNAME).pkg
	-rm -f $(PKGNAME).tar.Z
	echo "all" | pkgtrans -s $(PKGTMP) $(PKGNAME).pkg
	mv $(PKGTMP)/*.pkg .
	tar -cvf $(PKGNAME).tar -C $(PKGTMP) BRCMbge
	compress -f $(PKGNAME).tar
	-rm -rf $(PKGTMP)


BRCMbge_DU:
	-rm -f $(PKGNAME)_DU.tar $(PKGNAME)_DU.iso
	-mkdir $(PKGTMP)
	echo "all" | pkgtrans $(PKGNAME).pkg $(PKGTMP)
	pkg2du -r $(OSREL) -v -d `pwd`/$(PKGNAME)_DU -o `pwd`/$(PKGNAME)_DU.iso $(PKGTMP)/BRCMbge
	tar -cvf $(PKGNAME)_DU.tar $(PKGNAME)_DU
	-rm -rf $(PKGNAME)_DU $(PKGTMP)


clean:
	-rm -rf BRCMbge*
	-rm -rf i386* sparc*

