
#****************************************************************************#
# Copyright 2014 QLogic Corporation
# The contents of this file are subject to the terms of the
# QLogic End User License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the License at
# http://www.qlogic.com/Resources/Documents/DriverDownloadHelp/
# QLogic_End_User_Software_License.txt
# See the License for the specific language governing permissions
# and limitations under the License.
#****************************************************************************#

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

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


all:
	$(MAKE) BRCMbnx BPATH=rel
	$(MAKE) BRCMbnx BPATH=dbg DBGPKG=-dbg

du:
	@echo "******************************"
	@echo "* Must perform this as root! *"
	@echo "******************************"
	$(MAKE) bnxdu


PKGNAME = BRCMbnx-$(SOLARIS_VER)-$(OSARCH)-$(BRCMVERSION)$(DBGPKG)
PKGTMP  = $(OSARCH)-$(SOLARIS_VER)

PKGFILES = \
  ../build_$(BPATH)_32_$(OSARCH)-${SOLARIS_VER}/bnx32 \
  ../build_$(BPATH)_32_$(OSARCH)-${SOLARIS_VER}/bnx_mdb32 \
  ../build_$(BPATH)_64_$(OSARCH)-${SOLARIS_VER}/bnx64 \
  ../build_$(BPATH)_64_$(OSARCH)-${SOLARIS_VER}/bnx_mdb64

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

PROTO_BNX_32BIT_SRC = \
    if test "$(OSREL)" = "5.11" -o "$(OSARCH)" = "sparc"; then echo ""; \
    else echo "f none kernel/drv/bnx=PREFIX/bnx32 0755 root sys"; \
    fi
PROTO_BNX_32BIT = $(PROTO_BNX_32BIT_SRC:sh)

PROTO_BNX_64BIT_SRC = \
    echo "f none kernel/drv/ARCH/bnx=PREFIX/bnx64 0755 root sys";
PROTO_BNX_64BIT = $(PROTO_BNX_64BIT_SRC:sh)

PROTO_BNX_MDB_32BIT_SRC = \
    if test "$(OSREL)" = "5.11" -o "$(OSARCH)" = "sparc"; then echo ""; \
    else echo "f none kernel/kmdb/bnx=PREFIX/bnx_mdb32 0555 root sys"; \
    fi
PROTO_BNX_MDB_32BIT = $(PROTO_BNX_MDB_32BIT_SRC:sh)

PROTO_BNX_MDB_64BIT_SRC = \
    echo "f none kernel/kmdb/ARCH/bnx=PREFIX/bnx_mdb64 0555 root sys";
PROTO_BNX_MDB_64BIT = $(PROTO_BNX_MDB_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|BNX_32BIT|$(PROTO_BNX_32BIT)|" \
	    -e "s|BNX_MDB_32BIT|$(PROTO_BNX_MDB_32BIT)|" \
	    -e "s|BNX_64BIT|$(PROTO_BNX_64BIT)|" \
	    -e "s|BNX_MDB_64BIT|$(PROTO_BNX_MDB_64BIT)|" \
	    -e "s/PREFIX/$(PKGTMP)/g" \
	    -e "s/ARCH/$(PROTO_ARCH)/g" \
	    -e "/^$$/d" \
	    prototype > prototype-$(PKGTMP)
	pkgmk -f prototype-$(PKGTMP) -o -d $(PKGTMP)
	-rm -f prototype-$(PKGTMP)

BRCMbnx: 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) BRCMbnx
	compress -f $(PKGNAME).tar
	-rm -rf $(PKGTMP)



bnxdu: rawpkg
	cp $(PKGTMP)/bnx32 bnx
	cp $(PKGTMP)/bnx64 bnx64
	sed "s/driverpkgvers.*/driverpkgvers=$(PKGVERS)/" itu > bnx.itu
	bash fixdisk.sh ${SOLARIS_VER} $(BRCMVERSION)
	-rm -f bnx bnx64 bnx.itu
	-rm -rf $(PKGTMP)



clean:
	-rm -f BRCMbnx-*
	-rm -f bnxdu-*
	-rm -rf i386* sparc*

