# Set our CommEngine directory (by splitting the pwd into two words
# at /userspace and taking the first word only).
# Then include the common defines under CommEngine.
#
CURR_DIR := $(shell pwd)
BUILD_DIR:=$(subst /userspace, /userspace,$(CURR_DIR))
BUILD_DIR:=$(word 1, $(BUILD_DIR))

include $(BUILD_DIR)/make.common


#LIBS = -lcms_dal -lcms_msg $(CMS_COMMON_LIBS) -ldl $(CMS_CORE_LIBS)

#
# Private apps and libs are allowed to link with libraries from the
# private and public directories.
#
# WARNING: Do not modify this section unless you understand the
# license implications of what you are doing.
#
#ALLOWED_LIB_DIRS := /lib:/lib/private:/lib/public

LIBS = -lZBDevice

EXE = zigbeetest
OBJS = test.o
EXE2 = zigbee
OBJS2 = zigbee.o

#MFG Test program is use for RF EMI test.
EXE3 = zigbeeMFG
OBJS3 = MFG_test.o

all:  $(EXE) $(EXE2) $(EXE3)

CURR_DIR := $(shell pwd)
BUILD_DIR:=$(subst /userspace, /userspace,$(CURR_DIR))
BUILD_DIR:=$(word 1, $(BUILD_DIR))
 
include $(BUILD_DIR)/make.common


dynamic: all install cpall_image cpall_lib

install:
	install -m 755 $(TOOLCHAIN)/mips-linux-uclibc/lib/libstdc++.so.6 $(INSTALL_DIR)/lib
#	mkdir -p $(INSTALL_DIR)/usr/lib
	install -m 755 ../lib/libZBDevice.so ../lib/libTCPClient.so ../lib/libZ101b.so ../lib/libZ101a.so ../lib/libB2A.so $(INSTALL_DIR)/lib
#	mkdir -p $(INSTALL_DIR)/netvox
#	install -m 755 $(EXE) $(INSTALL_DIR)/netvox

#	$(STRIP) $(INSTALL_DIR)/netvox/$(EXE)

	install -m 755 $(EXE2) $(INSTALL_DIR)/bin
	install -m 755 $(EXE) $(INSTALL_DIR)/bin
	install -m 755 $(EXE3) $(INSTALL_DIR)/bin
#	install -m 755 ./lib/libTCPClient4l.so1 ./lib/libTCPClient.so libTCPClient4l.so ./lib/libZ101b.so $(INSTALL_DIR)/netvox
#	install -m 755 ./lib/libTCPClient.so ./lib/libZ101b.so $(INSTALL_DIR)/netvox
#	install -m 755 ./lib/libTCPClient.so ./lib/libZ101b.so $(INSTALL_DIR)/lib
        
$(EXE): $(OBJS)
#	$(CXX) -o $@ $(OBJS) -lZBDevice -Wl,--rpath-link ./lib -I/opt/toolchains/uclibc-crosstools-gcc-4.4.2-1/usr/include -L./lib
	$(CXX) -o $@ $(OBJS) -Wl,-allow-shlib-undefined  -L../lib/ -lpthread -ldl $(LIBS)

$(EXE2): $(OBJS2)
#	$(CXX) -o $@ $(OBJS2) -lZBDevice -Wl,--rpath-link ./lib -I/opt/toolchains/uclibc-crosstools-gcc-4.4.2-1/usr/include -L./lib
	$(CXX) -o $@ $(OBJS2) -Wl,-allow-shlib-undefined  -L../lib/ -lpthread -ldl $(LIBS)

$(EXE3): $(OBJS3)
#	$(CXX) -o $@ $(OBJS2) -lZBDevice -Wl,--rpath-link ./lib -I/opt/toolchains/uclibc-crosstools-gcc-4.4.2-1/usr/include -L./lib
	$(CXX) -o $@ $(OBJS3) -Wl,-allow-shlib-undefined  -L../lib/ -lpthread -ldl $(LIBS)

ifeq ($(strip $(BUILD_DLNA)),)
cpall_lib:
	cp -f $(PROFILE_DIR)/hf_zigbee/lib/* $(INSTALL_DIR)/lib/
else
cpall_lib:
endif

cpall_image:
	cp -f $(PROFILE_DIR)/hf_zigbee/bin/iihf-upload $(INSTALL_DIR)/bin/
	cp -f $(PROFILE_DIR)/hf_zigbee/bin/iihf-wd $(INSTALL_DIR)/bin/
	cp -f $(PROFILE_DIR)/hf_zigbee/bin/iihf-zigbee $(INSTALL_DIR)/bin/
	cp -f $(PROFILE_DIR)/hf_zigbee/bin/sqlite3 $(INSTALL_DIR)/bin/
	cp -f $(PROFILE_DIR)/hf_zigbee/bin/zjt $(INSTALL_DIR)/bin/
	cp -f $(PROFILE_DIR)/hf_zigbee/bin/zjt3 $(INSTALL_DIR)/bin/
	cp -f $(PROFILE_DIR)/hf_zigbee/bin/zjt4 $(INSTALL_DIR)/bin/
	cp -f $(PROFILE_DIR)/hf_zigbee/etc/lighttpd.conf.es $(INSTALL_DIR)/etc/
	cp -f $(PROFILE_DIR)/hf_zigbee/etc/iihf-zigbee.conf $(INSTALL_DIR)/etc/
	cp -f $(PROFILE_DIR)/hf_zigbee/webs/energy_services.html $(INSTALL_DIR)/webs/
	cp -f $(PROFILE_DIR)/hf_zigbee/webs/smart_life.html $(INSTALL_DIR)/webs/
	mkdir -p $(INSTALL_DIR)/webs/cgi/
	cp -f $(PROFILE_DIR)/hf_zigbee/webs/cgi/es.cgi $(INSTALL_DIR)/webs/cgi
	cp -f $(PROFILE_DIR)/hf_zigbee/fw/* $(INSTALL_DIR)/bin
	
$(EXE).a: $(OBJS)
	$(AR) rcs $@ $(OBJS)

$(EXE2).a: $(OBJS2)
	$(AR) rcs $@ $(OBJS2)

$(EXE3).a: $(OBJS3)
	$(AR) rcs $@ $(OBJS3)
	
clean:
	-rm -f $(EXE) *.o *.d  $(EXE).a $(EXE2) $(EXE2).a $(EXE3) $(EXE3).a

include ../../../../../make.deprules

-include $(OBJS:.o=.d)
