#
# GNUmakefile for wl/exe
#
# Copyright (c) 2000, Broadcom Corp.
# $Id: GNUmakefile,v 1.1.4.2 2009/06/08 22:13:14 Exp $

ifndef	SRCBASE
	SRCBASE = ../..
endif

UNAME = $(shell uname)

#-----------------------------------------------------------------
# Windows build
# 1) windows, don't include Makerules due to all: conflict

ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)

include ../../GNUmakefile.inc

else # UNAME

# 2) not windows, need to include first to pick up TARGETENV dependent vars
include $(SRCBASE)/Makerules



#ifdef BCMWPA2
CFLAGS += -DBCMWPA2
#endif

#ifdef WLCNT
CFLAGS += -DWLCNT
#endif

#-----------------------------------------------------------------
# Linux build
#
# This should be one of values recognized in src/Makerules

ifneq ($(findstring $(TARGETENV), "linux linuxmips linuxmips_be linuxarm linuxarm_le"),)

# $(TARGETARCH) is set based on TARGETENV in src/Makerules.* files
BWL_OBJS := bwl.o bwl_linux.o bwl_wps_enr.o bwltest.o
BWL_EXE  := bwl
WPS_PATH := $(CC)
WPS_LIBS  = $(WPS_PATH)/libwpsenr.a $(WPS_PATH)/libwpscom.a $(WPS_PATH)/libbcmcrypto.a
WLU_OBJS := wlu.o bcmutils.o bcmwifi.o wlu_cmd.o wlu_iov.o miniopt.o
#WLU_OBJS := wlu.o bcmutils.o bcmwifi.o wlu_cmd.o wlu_iov.o wlu_client_shared.o wlu_pipe_linux.o wlu_pipe.o miniopt.o
WPS_OBJS := wps_linux_hooks.o wl_wps.o


ifneq ($(findstring x86,$(TARGETARCH)),x86)
  BWL_EXE  := $(BWL_EXE)$(TARGETARCH)
  BWL_OBJS := $(BWL_OBJS:%.o=$(CC)/%.o)
  WLU_OBJS := $(WLU_OBJS:%.o=$(CC)/%.o)
  WPS_OBJS := $(WPS_OBJS:%.o=$(CC)/%.o)
endif

###########################
# openssl
###########################
export CFLAGS += -include wps_openssl.h
export CXXFLAGS += -include wps_openssl.h

BCM_PARTIAL_CRYPTO = 1
EXTERNAL_OPENSSL = 0

export EXTERNAL_OPENSSL_INC = $(EXTERNAL_OPENSSL_BASE)/include
export EXTERNAL_OPENSSL_LIB = $(EXTERNAL_OPENSSL_BASE)/lib/libcrypto.a

ifeq ($(EXTERNAL_OPENSSL), 1)
	export CFLAGS += -DUSE_EXTERNAL_OPENSSL
	export CXXFLAGS += -DUSE_EXTERNAL_OPENSSL
	EXTERNAL_OPENSSL_LIB = $(EXTERNAL_OPENSSL_BASE)/lib/libcrypto.a
	ifeq ($(BCM_PARTIAL_CRYPTO),1)
		CFLAGS += -I$(EXTERNAL_OPENSSL_INC) -I$(EXTERNAL_OPENSSL_INC)/openssl -I$(SRCBASE)/include/bcmcrypto
	else
		CFLAGS += -I$(EXTERNAL_OPENSSL_INC) -I$(EXTERNAL_OPENSSL_INC)/openssl
	endif
else
	CFLAGS += -I$(SRCBASE)/include/bcmcrypto
	EXTERNAL_OPENSSL_LIB =
endif


CFLAGS += -DWLPFN
CFLAGS += -DWLC_HIGH
CFLAGS += -I$(SRCBASE)/wl/sys
CFLAGS += -I$(SRCBASE)/wl/exe
CFLAGS += -I$(SRCBASE)/wps/common/include

vpath %.c $(SRCBASE)/shared
vpath %.c $(SRCBASE)/wl/sys
vpath %.c $(SRCBASE)/wl/exe
vpath %.c $(SRCBASE)/wps/linux/enr
vpath %.c $(SRCBASE)/wps/common/enrollee

all: wps_enr $(BWL_EXE)


$(BWL_EXE): $(WLU_OBJS) $(WPS_OBJS) $(BWL_OBJS)
	$(CC) $(LDFLAGS) -o $@ $^ $(WPS_LIBS) $(EXTERNAL_OPENSSL_LIB)

$(CC)/%.o: %.c
	@mkdir -p $(CC)
	$(CC) -c $(CFLAGS) -o $@ $^

wps_enr:
	make -f bwl_wps_libs.mk

clean:
	rm -f $(BWL_EXE) $(BWL_OBJS) $(WLU_OBJS) $(WPS_OBJS)
	rm -rf $(CC)

.PHONY: all clean

endif # TARGETENV linux


endif # UNAME
