ifndef COMPILING_WHOLE_TREE
TOPDIR:=$(shell pwd)
TOPDIR:=$(shell dirname $(TOPDIR))
TOPDIR:=$(shell dirname $(TOPDIR))
TOPDIR:=$(shell dirname $(TOPDIR))
TOPDIR:=$(shell dirname $(TOPDIR))
TOPDIR:=$(shell dirname $(TOPDIR))
endif

ifndef GOLINUX
include $(TOPDIR)/Rules.make
else
include $(TOPDIR)/Rules_GoLinux.make
endif 

OBJECTS:= bluetooth.o \
hci.o  \


CFLAGS-y =-DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1\
 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1\
 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1  -I../include -O2 -fPIC

ifneq ($(sort $(filter y,$(CONFIG_SAGEM_LB2) $(CONFIG_GENERATION_SAGEM_MINI))),y)
CFLAGS-y += -mips32
endif 


CFLAGS-$(CONFIG_LINUX_2_4) += -g-

CFLAGS = $(CFLAGS-y)

ifeq ($(strip $(CONFIG_MMS)), y)
#CCTH: No mips-linux-gcc mms base (DECT35 / DECT37)
all : libbluetooth.so libsdp.so
else
all : libbluetooth_libc.a libbluetooth.so libsdp.so libbluetooth.a
	if ( ! diff libbluetooth_libc.a  $(TOPDIR)/libs/libbluetooth_libc.a ) ; then    cp libbluetooth_libc.a $(TOPDIR)/libs ; fi;
	if ( ! diff libbluetooth.a  $(TOPDIR)/libs/libbluetooth.a ) ; then    cp libbluetooth.a $(TOPDIR)/libs ; fi;
endif
	cp libbluetooth.so $(TOPDIR)/libs
	ln -sf libbluetooth.so $(TOPDIR)/libs/libbluetooth.so.1

%.o: %.c
	$(CC) $(CFLAGS) -o $@ -c $<

bluetooth_libc.o : bluetooth.c
	$(CC_GLIBC) $(CFLAGS) -o bluetooth_libc.o -c bluetooth.c

hci_libc.o : hci.c
	$(CC_GLIBC) $(CFLAGS) -o hci_libc.o -c hci.c

libbluetooth.so : $(OBJECTS)
	$(CC) -shared $(OBJECTS) -Wl,-soname -Wl,libbluetooth.so -o $@

libsdp.so: sdp.o
	$(CC) -shared $^ -Wl,-soname -Wl,libsdp.so -o $@
	cp libsdp.so $(TOPDIR)/libs


libbluetooth_libc.a : bluetooth_libc.o hci_libc.o
	$(AR_GLIBC) -r libbluetooth_libc.a bluetooth_libc.o hci_libc.o

libbluetooth.a : bluetooth.o hci.o
	$(AR) -r libbluetooth.a bluetooth.o hci.o
	

clean :
	rm -f *.o libbluetooth.so libbluetooth_libc.a $(TOPDIR)/libs/libbluetooth.so $(TOPDIR)/libs/libbluetooth_libc.a \
		libsdp.so $(TOPDIR)/libs/libsdp.so
