1#
2# Broadcom Linux Router WPS Makefile
3#
4# Copyright (C) 2013, Broadcom Corporation
5# All Rights Reserved.
6# 
7# This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8# the contents of this file may not be disclosed to third parties, copied
9# or duplicated in any form, in whole or in part, without the prior
10# written permission of Broadcom Corporation.
11#
12# $Id: Makefile 383955 2013-02-08 06:00:32Z $
13#
14REBUILD = $(shell if [ -f "prebuilt/wps_monitor" ]; then echo 0; else echo 1; fi)
15
16ifneq (true,$(parallel))
17  .NOTPARALLEL:
18endif
19
20# Build type
21export BLDTYPE = release
22#export BLDTYPE = debug
23
24
25include $(TOP)/.config
26
27# linux kernel config
28include $(LINUXDIR)/.config
29
30export WPSSRC = $(SRCBASE)/wps
31
32# Get wireless driver support mode
33ifneq ($(CONFIG_WL_USE_STA)$(CONFIG_WL_USE_STA_ONCHIP_G)$(CONFIG_WL_USE_APSTA)$(CONFIG_WL_USE_APSTA_ONCHIP_G),)
34  ifneq ($(CONFIG_WL_USE_STA)$(CONFIG_WL_USE_STA_ONCHIP_G),)
35    export WL_MODE = sta
36    export WPS_CONF_FILE = wpsconfig_router_sta
37    WPS_LIB_FILE = wps_sta
38  else
39    export WL_MODE = apsta
40    export WPS_CONF_FILE = wpsconfig_router_apsta
41    WPS_LIB_FILE = wps_apsta
42  endif
43else
44  export WL_MODE = ap
45  export WPS_CONF_FILE = wpsconfig_router_ap
46  WPS_LIB_FILE = wps_ap
47endif
48
49# Include wps common make file
50include $(WPSSRC)/common/config/$(WPS_CONF_FILE)
51ifneq ($(CONFIG_WFI),y)
52WPS_WFI = 0
53endif
54ifneq ($(CONFIG_LIBUPNP),y)
55WPS_UPNP_DEVICE = 0
56endif
57ifeq ($(CONFIG_PLC),y)
58CFLAGS += -DWPS_PLC
59endif
60ifeq ($(CONFIG_NFC),y)
61export WPS_NFC_DEVICE = 1
62endif
63include $(WPSSRC)/common/config/wps.mk
64EXTRA_CFLAGS = $(WPS_FLAGS)
65
66# Generate list of supported variants
67VLIST  = AP STA APSTA
68
69# Set suffix and config based on the selected variant
70WPS_SUFFIX      := $(strip $(foreach v,$(VLIST),$(if $(CONFIG_WL_USE_$(v)),$(v))))
71
72# Module file names use lowercase of the suffix
73wps_suffix      := $(shell echo "$(WPS_SUFFIX)" | tr A-Z a-z)
74
75# Always do variants build
76wpssubdirs := $(addprefix wps_,$(shell echo "$(VLIST)" | tr A-Z a-z))
77
78#
79# Set CFLAGS
80#
81CFLAGS += -DWPS_AP_M2D
82
83# Enable WWTP option cause the security hole described in WSC 2.0 specification section 4.3.1
84# But WPS 2 Test plan 4.1.13 still need this feature support.
85CFLAGS += -DWPS_ADDCLIENT_WWTP
86
87CFLAGS += -Wall -Wnested-externs -D_REENTRANT -D__linux__
88#CFLAGS += -Werror
89
90ifeq ($(BLDTYPE), debug)
91CFLAGS += -g
92endif
93
94
95CFLAGS += -I$(SRCBASE)/include -I$(SRCBASE)/common/include -I$(SRCBASE)/wps/common/include	\
96	-I$(SRCBASE)/router/libbcm -I$(SRCBASE)/router/eapd${BCMEX}	\
97	-I$(SRCBASE)/router/shared -I$(SRCBASE)/wps/brcm_apps/include	\
98	-I$(SRCBASE)/include/bcmcrypto ${WLAN_ComponentIncPath}
99
100LDFLAGS += -lgcc_s
101
102ifeq ($(RTCONFIG_QTN),y)
103LDFLAGS += -L$(TOP)/libqcsapi_client -lqcsapi_client
104endif
105
106WPSM_LIBS = -lnvram -lbcm -lshared -lbcmcrypto -lm
107# Set link libraries search path
108export LIBPATH  = -L$(TOP)/libbcmcrypto -L$(INSTALLDIR)/libbcmcrypto/usr/lib
109export LIBPATH += -L$(TOP)/libbcm -L$(INSTALLDIR)/libbcm/usr/lib
110export LIBPATH += -L$(TOP)/shared -L$(INSTALLDIR)/shared/usr/lib
111export LIBPATH += -L$(TOP)/nvram${BCMEX} -L$(INSTALLDIR)/nvram/usr/lib
112export LIBPATH += -L$(SRCBASE)/router/wps${BCMEX}/lib
113export LIBPATH += -L$(SRCBASE)/router/wps${BCMEX}/prebuilt
114ifeq ($(WPS_UPNP_DEVICE),1)
115# Always use LIBUPNP
116export LIBPATH += -L$(TOP)/libupnp${BCMEX}$(EX7) -L$(INSTALLDIR)/libupnp/usr/lib
117WPSM_LIBS += -lupnp
118CFLAGS += -I$(SRCBASE)/router/libupnp${BCMEX}$(EX7)/include -I$(SRCBASE)/wps/brcm_apps/upnp/WFADevice
119endif
120
121ifeq ($(WPS_NFC_DEVICE),1)
122export LIBPATH += -L$(TOP)/nfc -L$(INSTALLDIR)/nfc/usr/lib
123WPSM_LIBS += -lnsa -lipcnsa -lpthread
124CFLAGS += -I$(SRCBASE)/wps/brcm_apps/nfc
125CFLAGS += -I$(BASEDIR)/components/apps/nfc/3rdparty/embedded/nsa_examples/linux/libnsa/include
126CFLAGS += -include $(BASEDIR)/components/apps/nfc/3rdparty/embedded/nsa_examples/linux/libnsa/include/buildcfg.h
127endif
128
129WPS_OSL := $(WPS_ROUTERHALFILES)
130WPS_OSL += src/wps/brcm_apps/linux/wps_linux_main.c
131
132WPS_OSL += src/wps/brcm_apps/linux/wps_linux_osl.c
133ifneq ($(WL_MODE), ap)
134WPS_OSL += src/wps/brcm_apps/linux/wps_enr_linux_osl.c
135endif
136
137WPS_OSLOBJS := $(foreach file, $(WPS_OSL), \
138	 $(patsubst src/%.c,obj/%.o,$(file)))
139
140WPS_DIRS := $(foreach file, $(WPS_OSLOBJS), \
141	 $(dir $(file)))
142
143WPS_DIRLIST = $(sort $(WPS_DIRS)) 
144
145
146ifneq ($(wildcard ./prebuilt),)
147all: osl wps_monitor
148else
149all: mkversion sta_build_check dirs variants_build osl wps_monitor
150endif
151
152osl:
153	mkdir -p $(WPS_DIRLIST)
154	@echo "==>$(WPS_CONF_FILE)"
155
156ifneq ($(wildcard ./prebuilt),)
157objs:
158else
159objs: variants_build
160endif
161	+$(MAKE) parallel=true $(WPS_OSLOBJS)
162
163$(WPS_OSLOBJS) : obj%.o: $(addprefix $(SRCBASE)/../,src%.c)
164	$(CC) -c $(CFLAGS) $(EXTRA_CFLAGS) -o $@ $<
165
166# Variants build rules
167variants_build: $(patsubst %, _dir_%, $(wpssubdirs))
168$(patsubst %, _dir_%, $(wpssubdirs)):
169	$(if $(wildcard $(patsubst _dir_%, %, $@)),+$(MAKE) -C $(patsubst _dir_%, %, $@))
170
171# Set link libraries search path
172export LIBPATH += -L. -L./prebuilt
173
174
175sta_build_check:
176ifeq ($(WL_MODE),sta)
177ifeq ($(WPS_UPNP_DEVICE),1)
178	@echo "ERROR: UPNP_WFA_DEVICE is not supported on STA mode"
179	@exit 1
180endif
181endif
182	@true
183
184
185dirs :
186	mkdir -p lib
187
188mkversion :
189	$(SRCBASE)/router/wps${BCMEX}/mkversion.sh $(WPSSRC)/common/include/version.h.in $(WPSSRC)/common/include/wps_version.h "$(PROD_TAG)"
190
191# target
192# force compile wps_monitor in case the library changed.
193ifeq ($(wildcard ./prebuilt),)
194wps_monitor : objs FORCE
195	$(CC) $(LIBPATH) $(WPS_OSLOBJS) -l$(WPS_LIB_FILE) $(WPSM_LIBS) $(LDFLAGS) -o $@
196else
197wps_monitor :
198endif
199
200FORCE:
201
202
203clean:
204	find . \( -name '*.[od]' -o -name '*.tmp' \) -type f -print | xargs rm -f
205	find -name obj | xargs rm -rf
206	rm -rf lib
207ifeq ($(REBUILD),1)
208	find -name wps_monitor | xargs rm -f
209endif
210
211# install
212install: all
213	install -d $(INSTALLDIR)/wps${BCMEX}/bin
214ifeq ($(REBUILD),0)
215	install prebuilt/wps_monitor $(INSTALLDIR)/wps${BCMEX}/bin
216else
217	install wps_monitor $(INSTALLDIR)/wps${BCMEX}/bin
218endif
219	$(STRIP) $(INSTALLDIR)/wps${BCMEX}/bin/wps_monitor
220
221.PHONY: all clean install libs dirs osl
222