## ============================================================================
##
##  SeaMAC driver build makefile
##  Builds the SeaMAC kernel module (seamac.ko)
##
## ============================================================================

## KVER: Specify kernel version or use the running kernel.
## Warning: Kernels only load modules that match its version exactly.
## Source for the designated version must be present in /usr/src/kernels/
## Do not use a trailing comment or you'll get a fake "No kernel source" error.
#KVER = 4.18.0-553.89.1.el8_10.x86_64
KVER = $(shell uname -r)

export KDIR = /lib/modules/$(KVER)/build
export MODDIR = /lib/modules/$(KVER)/kernel/drivers/serial

## Change these if you wish to change default installation directories.
export INCLUDEDIR = /usr/local/inc
export SUAPPDIR = /sbin
export APPDIR = /usr/bin

## Change these if your system is configured differently.
export CP 	= /bin/cp
export RM 	= /bin/rm
export MKDIR 	= /bin/mkdir
export CHMOD    = /bin/chmod
export CC 	= /usr/bin/gcc

export INCLUDE = $(shell pwd)/inc

## ============================================================================
## The following values are for internal package management and should only
## be changed if you know what you are doing.
PRODUCT = SeaMAC
VERSION = 1.7.0
DISTRO = SM010700

#project name, used for install scripts
PROJECT = seamac
#SUBDIRS = inc acb r56 dhd
SUBDIRS = inc acb
SVN = `find -iname \.svn`

TAR 	= /bin/tar
GZIP 	= /bin/gzip

## ============================================================================

all: subdirs
	@echo Done 7

objs:
	@echo "----------------------------------------------------------------"
	@echo "Building all objects."
	@echo "----------------------------------------------------------------"
	@echo
	@for n in $(SUBDIRS); do $(MAKE) -s -C $$n objs || exit 1; done
	@echo "----------------------------------------------------------------"
	@echo "Done building objects."
	@echo "----------------------------------------------------------------"

subdirs:
	@echo "----------------------------------------------------------------"
	@echo "Building all."
	@echo "----------------------------------------------------------------"
	@echo
	@for n in $(SUBDIRS); do $(MAKE) -s -C $$n all || exit 1; done
	@echo "----------------------------------------------------------------"
	@echo "Done building all sources."
	@echo "----------------------------------------------------------------"

clean:
	@echo "----------------------------------------------------------------"
	@echo "Removing all temp build output files."
	@echo "----------------------------------------------------------------"
	@echo
	@for n in $(SUBDIRS); do $(MAKE) -s -C $$n clean || exit 1; done
	@echo "----------------------------------------------------------------"
	@echo "Done removing all build files."
	@echo "----------------------------------------------------------------"

clobber:
	@echo "----------------------------------------------------------------"
	@echo "Removing all build output including driver module."
	@echo "----------------------------------------------------------------"
	@echo
	@for n in $(SUBDIRS); do $(MAKE) -s -C $$n clobber || exit 1; done
	@echo "----------------------------------------------------------------"
	@echo "Done removing all build output."
	@echo "----------------------------------------------------------------"

install:
	@echo "----------------------------------------------------------------"
	@echo "Installing $(PRODUCT) v$(VERSION) suite."
	@echo "----------------------------------------------------------------"
	@echo
	@for n in $(SUBDIRS); do $(MAKE) -s -C $$n install || exit 1; done
	@echo "----------------------------------------------------------------"
	@echo "Done installing $(PRODUCT) v$(VERSION) suite."
	@echo "----------------------------------------------------------------"

uninstall:
	@echo "----------------------------------------------------------------"
	@echo "Uninstalling $(PRODUCT) v$(VERSION) suite."
	@echo "----------------------------------------------------------------"
	@echo
	@for n in $(SUBDIRS); do $(MAKE) -s -C $$n uninstall || exit 1; done
	@echo "----------------------------------------------------------------"
	@echo "Done uninstalling $(PRODUCT) v$(VERSION) suite."
	@echo "----------------------------------------------------------------"

cleaninstall: clean install

purge: uninstall clean

distro: clean
	@echo "----------------------------------------------------------------"
	@echo "Building $(PRODUCT) v$(VERSION) distribution package!"
	@echo "----------------------------------------------------------------"
	@$(RM) -rf $(PRODUCT)_$(VERSION).tar.gz
	@$(RM) -rf $(SVN)
	@$(RM) -rf ./TESTING
	@$(TAR) -cf $(DISTRO).tar ../${PROJECT}
	@$(GZIP) $(DISTRO).tar
	@echo "----------------------------------------------------------------"
	@echo "Done!"
	@echo "----------------------------------------------------------------"
