#
#
# Copyright 2016-2018 Broadcom.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
#

#
# We need to set and export OPEN_ROOT to point to the
# root directory of the OpEN ADK installation, and then
# bring in the common.mak settings.
# 
# Include target package output settings.

export OPEN_ROOT = ../..
export PYTHON_H = ./python2.7.10
export SWIGVER=3.0.0

# Override headers to use defaults for following distros

ifeq (1,$(BLD_L7_TARGETOS_LINUX_UB16))
export PYTHON_H = ./python2.7.12
endif

ifeq (1,$(BLD_L7_TARGETOS_LINUX_UB18))
export PYTHON_H = ./python2.7.12
endif

ifeq (1,$(BLD_L7_TARGETOS_LINUX_UB20))
export PYTHON_H = ./python3.8.10
endif

ifeq (1,$(BLD_L7_TARGETOS_LINUX_COS7))
export PYTHON_H = ./python2.7.5
endif

include $(OPEN_ROOT)/swig/make/make.swig

#
# Simple rule for compiling our applications, no
# incremental steps.
#
all: _OpEN_base.so
	$(NOOP)

openswig: _OpEN_base.so
	$(NOOP)

_OpEN_base.so: openwrap.i createstub.pl
	$(DBG) swig -DL7_NO_PRINTF_FMT=1 -python -o openwrap_qos.c openwrap_qos.i
	$(DBG) swig -DL7_NO_PRINTF_FMT=1 -python -o openwrap_switching.c openwrap_switching.i
	$(DBG) swig -DL7_NO_PRINTF_FMT=1 -python -o openwrap_routing.c openwrap_routing.i
	$(DBG) swig -DL7_NO_PRINTF_FMT=1 -python -o openwrap_security.c openwrap_security.i
	$(DBG) swig -DL7_NO_PRINTF_FMT=1 -python -o openwrap.c openwrap.i
	$(DBG) python getwrappers_base.py
	$(DBG) python getwrappers_qos.py
	$(DBG) python getwrappers_switching.py
	$(DBG) python getwrappers_routing.py
	$(DBG) python getwrappers_security.py
	$(DBG) perl createstub.pl
	$(DBG) sh updatepymethods_base.sh
	$(DBG) sh updatepymethods_qos.sh
	$(DBG) sh updatepymethods_switching.sh
	$(DBG) sh updatepymethods_routing.sh
	$(DBG) sh updatepymethods_security.sh
	$(DBG) $(CROSS_COMPILE)$(CC) -I$(PYTHON_H) -fPIC $(CFLAGS) $(CFLAGSEXTRA) -c openwrap.c
	$(DBG) $(CROSS_COMPILE)$(CC) -I$(PYTHON_H) -fPIC $(CFLAGS) $(CFLAGSEXTRA) -c openwrap_qos.c
	$(DBG) $(CROSS_COMPILE)$(CC) -I$(PYTHON_H) -fPIC $(CFLAGS) $(CFLAGSEXTRA) -c openwrap_switching.c
	$(DBG) $(CROSS_COMPILE)$(CC) -I$(PYTHON_H) -fPIC $(CFLAGS) $(CFLAGSEXTRA) -c openwrap_routing.c
	$(DBG) $(CROSS_COMPILE)$(CC) -I$(PYTHON_H) -fPIC $(CFLAGS) $(CFLAGSEXTRA) -c openwrap_security.c
	$(DBG) $(CROSS_COMPILE)$(CC) -shared openwrap.o -o $@ $(LDFLAGS) $(LFLAGSEXTRA)
	$(DBG) $(CROSS_COMPILE)$(CC) -shared openwrap_qos.o -o _OpEN_qos.so $(LDFLAGS) $(LFLAGSEXTRA)
	$(DBG) $(CROSS_COMPILE)$(CC) -shared openwrap_switching.o -o _OpEN_switching.so $(LDFLAGS) $(LFLAGSEXTRA)
	$(DBG) $(CROSS_COMPILE)$(CC) -shared openwrap_routing.o -o _OpEN_routing.so $(LDFLAGS) $(LFLAGSEXTRA)
	$(DBG) $(CROSS_COMPILE)$(CC) -shared openwrap_security.o -o _OpEN_security.so $(LDFLAGS) $(LFLAGSEXTRA)
	$(DBG) sh appendpywrappers.sh

openwrap.i: genifile_base.pl
	$(DBG) python rpccom_openapi_enums.py
	$(DBG) perl genifile_base.pl
	$(DBG) perl genifile_qos.pl
	$(DBG) perl genifile_switching.pl
	$(DBG) perl genifile_routing.pl
	$(DBG) perl genifile_security.pl

clean:
	$(DBG) rm -f *.o _OpE*.so openwra*.c openwrapbase.c openwraptmp.c appen*.txt  pyresul*.txt  resul*.txt OpEN*py.py OpEN*.py openwra*.i
