#!/usr/bin/make -f
# ------------------------------------------------------------------------------
# COHWRAID(LNX) libCoHwRaid shared library
#
# Copyright (c) Since 2021 CONTEC Co.,Ltd. All Rights reserved.
# ------------------------------------------------------------------------------

PWD := $(shell pwd)
ARCH := $(shell uname -m)

# check board info
TARGET_VENDORS := CONTEC
TARGET_MODELS := GMB-MQ37000 VPC-5000 GMB-AW48000 GMB-MQ67000

BOARD_VENDOR ?= $(shell echo -n `cat /sys/devices/virtual/dmi/id/sys_vendor`)
MODEL_NAME ?= $(shell echo -n `cat /sys/devices/virtual/dmi/id/product_name`)

CHK_BOARD_VENDOR ?= $(filter $(BOARD_VENDOR), $(TARGET_VENDORS))
CHK_MODEL_NAME ?= $(filter $(MODEL_NAME), $(TARGET_MODELS))

ifeq ($(and $(CHK_BOARD_VENDOR), $(CHK_MODEL_NAME)),)
$(warning This model is probably not supported.)
endif

# check drives
CHK_DISKS ?= $(filter SVRC-%, $(shell echo -n `cat /sys/bus/scsi/devices/*/model | tr -d ' '`))

ifeq ($(CHK_DISKS),)
$(warning "SVRC-*" RAID drive not found!)
endif

install : lib_install
uninstall : lib_uninstall
install_all : lib_install cohwraid cohwraidmond cohwraidmond_install cohwraidmond_up
uninstall_all : cohwraidmond_down cohwraidmond_uninstall lib_uninstall
samples : cohwraid cohwraidmond
samples_clean : cohwraid_clean cohwraid_clean

lib_install :
	make install -C ./library

lib_uninstall :
	make uninstall -C ./library

cohwraid :
	make -C ./samples/console_sample

cohwraid_clean :
	make clean -C ./samples/console_sample

cohwraidmond :
	make -C ./samples/cohwraidmond

cohwraidmond_install :
	make install -C ./samples/cohwraidmond

cohwraidmond_uninstall :
	make uninstall -C ./samples/cohwraidmond

cohwraidmond_up :
	make service_start -C ./samples/cohwraidmond

cohwraidmond_down :
	make service_stop -C ./samples/cohwraidmond

cohwraidmond_clean :
	make clean -C ./samples/cohwraidmond
