#
# Copyright (c) 2000 Broadcom Corporation, all rights reserved.
# Proprietary and Confidential Information.
#
# This source file is the property of Broadcom Corporation, and
# may not be copied or distributed in any isomorphic form without
# the prior written consent of Broadcom Corporation.
#
# Name:        Makefile.rel
#
# Description: makefile for building Broadcom Advanced Server Program
#              (BASP) for Linux.
#
# Author:      Frankie Fan
#
# Created:     September 5, 2000
#

#############################################################################
# customizable options
#############################################################################

# major number
BLF_DEVICE_MAJOR=0

#############################################################################
# end of customizable options
#############################################################################

# select the right compiler, it's necessary for Redhat 7.x
ifeq ($(shell which kgcc >/dev/null 2>&1 && echo missing),)
CC=gcc -DLINUX
else
  ifneq ($(findstring gcc version egcs-2.91.66, $(shell cat /proc/version 2>&1)),)
    CC=kgcc -DLINUX
  else
    CC=gcc -DLINUX
  endif
endif

RH71_BUILD_PATH=$(shell echo /lib/modules/`uname -r`/build)
RH71_INCLUDE_PATH=$(RH71_BUILD_PATH)/include
ifeq ($(shell [ -d $(RH71_BUILD_PATH) ] && echo missing),)
KERNEL_INCLUDE_PATH=/usr/src/linux/include
INSTALL_PHASE2=install_phase2b
else
KERNEL_INCLUDE_PATH=$(RH71_INCLUDE_PATH)
INSTALL_PHASE2=install_phase2a
endif

# select the right architecture string
# note that only i386 and ia64 are supported for now.
ARCH=$(shell if [ `uname -m` = ia64 ]; then echo ia64; elif [ `uname -m` = x86_64 ]; then echo x86_64; else echo i386; fi)

CFLAGS= -D__KERNEL__ -DMODULE -I$(KERNEL_INCLUDE_PATH) -Wall -Wstrict-prototypes -O2
LDFLAGS= -r # -m elf_i386

#
# smp
#
ifdef SMP
CFLAGS+= -D__SMP__
endif

#
# debug
#
ifdef DBG
CFLAGS+= -g -DDBG 
endif

#
# x86_64
#
ifeq ($(ARCH),x86_64)
CFLAGS+= -mcmodel=kernel
endif

#
# module version support
#
#ifdef MODVERSIONS
#CFLAGS+= -DCONFIG_MODVERSIONS=1 -DMODVERSIONS
#endif

RM=rm -f
MAKE=make

.SUFFIXES: .c .o

# final binary name
BLFMOD= basp.o

# list of internal source files
BLFCOREOBJ= blfcore.o

# list of external source files
BLFEXTSRC= \
	blf.c \
	pal.c

BLFEXTOBJ= \
	blf.o \
	pal.o

BLFEXTHDR= \
	bcmtype.h \
	blfver.h \
	blfcore.h \
	pal.h \
	nicext.h \
	blfopt.h

# targets

all: $(BLFMOD)

#ver:
#	@$(MAKE) MODVERSIONS=1

smp:
	@$(MAKE) SMP=1

#smp_ver:
#	@$(MAKE) SMP=1 MODVRESIONS=1

# this target is built from all source files
$(BLFMOD): $(BLFEXTHDR) $(BLFEXTOBJ) $(BLFCOREOBJ) 
	$(LD) $(LDFLAGS) -o $(BLFMOD) $(BLFEXTOBJ) $(BLFCOREOBJ)

clean:
	$(RM) $(BLFMOD) $(BLFEXTOBJ) 

debug:
	@$(MAKE) clean
	@$(MAKE) DBG=1

#verdebug:
#	@$(MAKE) clean
#	@$(MAKE) DBG=1 MODVERSION=1

.c.o: $(BLFEXTHDR)
	$(CC) $(CFLAGS) -c $<

blfopt.h: Makefile
	@echo \#ifndef __blfopt_h__ > .ver
	@echo \#define __blfopt_h__ >> .ver
	@echo /\* created on: `date` \*/ >> .ver
	@echo \#define BLF_DEVICE_MAJOR $(BLF_DEVICE_MAJOR) >> .ver
	@echo \#endif >> .ver
	@mv -f .ver $@

install_phase1:
	@-$(RM) -f $(PREFIX)/dev/basp
	-mkdir -p $(PREFIX)/dev
	-mknod $(PREFIX)/dev/basp c $(BLF_DEVICE_MAJOR) 0
	-mkdir -p $(PREFIX)/usr/bin
	cp -f baspcfg $(PREFIX)/usr/bin
	-mkdir -p $(PREFIX)/etc/init.d
	cp -f scripts/basp $(PREFIX)/etc/init.d
	-mkdir -p $(PREFIX)/etc/basp/samples
	cp -f scripts/baspteam $(PREFIX)/etc/basp
	cp -f scripts/baspif $(PREFIX)/etc/basp
	cp -f scripts/team-sample $(PREFIX)/etc/basp/samples
	cp -f scripts/team-gec $(PREFIX)/etc/basp/samples
	cp -f scripts/team-vlan $(PREFIX)/etc/basp/samples
	-mkdir -p $(PREFIX)/usr/src/nice-2.2.16
	cp -f nice-2.2.16/* $(PREFIX)/usr/src/nice-2.2.16
	cp -f nicext.h $(PREFIX)/usr/src/nice-2.2.16
	-mkdir -p $(PREFIX)/usr/src/nice-2.4.16
	cp -f nice-2.4.16/* $(PREFIX)/usr/src/nice-2.4.16
	cp -f nicext.h $(PREFIX)/usr/src/nice-2.4.16
	-mkdir -p $(PREFIX)/usr/share/man/man4
	cp -f basp.4.gz $(PREFIX)/usr/share/man/man4
	-mkdir -p $(PREFIX)/usr/share/man/man8
	cp -f baspcfg.8.gz $(PREFIX)/usr/share/man/man8

install_phase2a:
	-mkdir -p $(PREFIX)/lib/modules/`uname -r`/kernel/net/basp
	cp -f basp.o $(PREFIX)/lib/modules/`uname -r`/kernel/net/basp
	-mkdir -p $(PREFIX)/lib/modules/`uname -r`/build/include/linux
	cp -f nicext.h $(PREFIX)/lib/modules/`uname -r`/build/include/linux

install_phase2b:
	-mkdir -p $(PREFIX)/lib/modules/`uname -r`/net
	cp -f basp.o $(PREFIX)/lib/modules/`uname -r`/net
	-mkdir -p $(PREFIX)/usr/src/linux/include/linux
	cp -f nicext.h $(PREFIX)/usr/src/linux/include/linux

install: install_phase1 $(INSTALL_PHASE2)

