diff --git a/Makefile.am b/Makefile.am index 59f231edc..79321a621 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = src example +SUBDIRS = platforms/posix/src example package: ./package.sh \ No newline at end of file diff --git a/configure.in b/configure.in index 58a70ffbb..5f61efd43 100644 --- a/configure.in +++ b/configure.in @@ -6,7 +6,7 @@ AC_INIT(BTstack, 0.1) AC_CONFIG_AUX_DIR(config) AM_INIT_AUTOMAKE(BTstack,0.1) -AC_ARG_WITH(hci-transport, [AS_HELP_STRING([--with-hci-transport=transportType], [Specify BT type to use: h4, usb (experimental)])], HCI_TRANSPORT=$withval, HCI_TRANSPORT="h4") +AC_ARG_WITH(hci-transport, [AS_HELP_STRING([--with-hci-transport=transportType], [Specify BT type to use: h4, usb])], HCI_TRANSPORT=$withval, HCI_TRANSPORT="h4") AC_ARG_WITH(uart-device, [AS_HELP_STRING([--with-uart-device=uartDevice], [Specify BT UART device to use])], UART_DEVICE=$withval, UART_DEVICE="DEFAULT") AC_ARG_WITH(uart-speed, [AS_HELP_STRING([--with-uart-speed=uartSpeed], [Specify BT UART speed to use])], UART_SPEED=$withval, UART_SPEED="115200") AC_ARG_ENABLE(powermanagement, [AS_HELP_STRING([--disable-powermanagement],[Disable powermanagement])], USE_POWERMANAGEMENT=$enableval, USE_POWERMANAGEMENT="yes") @@ -25,6 +25,14 @@ AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET +# iPhone/iPod touch cross-compilation uses theos +SDK_PATH="$DEVELOPER_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk" +if test "x$target" = xiphone; then + echo "Cross-compiling for iPhone/iPod touch uses theos" + ./config-iphone.sh + exit 0 +fi + # use capitals for transport type if test "x$HCI_TRANSPORT" = xusb; then HCI_TRANSPORT="USB" @@ -33,7 +41,6 @@ if test "x$HCI_TRANSPORT" = xh4; then HCI_TRANSPORT="H4" fi - # validate USB support if test "x$HCI_TRANSPORT" = xUSB; then # pkg-config needed @@ -53,15 +60,18 @@ echo "BTstack configured for HCI $HCI_TRANSPORT Transport" HAVE_SO_NOSIGPIPE="no" -RUN_LOOP_SOURCES="run_loop_posix.c" +# from platform/posix/src +BTSTACK_ROOT="../../../" + +RUN_LOOP_SOURCES="$BTSTACK_ROOT/platforms/posix/src/run_loop_posix.c" case "$host_os" in darwin*) - RUN_LOOP_SOURCES="$RUN_LOOP_SOURCES ../platforms/cocoa/run_loop_cocoa.m" + RUN_LOOP_SOURCES="$RUN_LOOP_SOURCES $BTSTACK_ROOT/platforms/cocoa/run_loop_cocoa.m" LDFLAGS="$LDFLAGS -framework CoreFoundation -framework Foundation" USE_COCOA_RUN_LOOP="yes" BTSTACK_LIB_LDFLAGS="-dynamiclib -install_name \$(prefix)/lib/libBTstack.dylib" BTSTACK_LIB_EXTENSION="dylib" - REMOTE_DEVICE_DB_SOURCES="../platforms/cocoa/remote_device_db_cocoa.m" + REMOTE_DEVICE_DB_SOURCES="$BTSTACK_ROOT/platforms/cocoa/remote_device_db_cocoa.m" REMOTE_DEVICE_DB="remote_device_db_iphone" HAVE_SO_NOSIGPIPE="yes"; ;; @@ -74,13 +84,6 @@ case "$host_os" in ;; esac -# iPhone/iPod touch cross-compilation uses theos -SDK_PATH="$DEVELOPER_PATH/SDKs/iPhoneOS$SDK_VERSION.sdk" -if test "x$target" = xiphone; then - echo "Cross-compiling for iPhone/iPod touch using theos" - ./config-iphone.sh - exit 0 -fi # treat warnings seriously CPPFLAGS="$CPPFLAGS -Werror -Wall -Wpointer-arith" @@ -114,7 +117,7 @@ echo rm -f btstack-config.h echo "// btstack-config.h created by configure for BTstack " `date`> btstack-config.h if test "x$HCI_TRANSPORT" = xUSB; then - USB_SOURCES=hci_transport_usb.c + USB_SOURCES=hci_transport_h2_libusb.c.c echo "#define HAVE_TRANSPORT_USB" >> btstack-config.h echo "#define USB_PRODUCT_ID $USB_PRODUCT_ID" >> btstack-config.h echo "#define USB_VENDOR_ID $USB_VENDOR_ID" >> btstack-config.h @@ -160,4 +163,4 @@ AC_SUBST(CFLAGS) AC_SUBST(CPPFLAGS) AC_SUBST(BTSTACK_LIB_LDFLAGS) AC_SUBST(BTSTACK_LIB_EXTENSION) -AC_OUTPUT(Makefile src/Makefile example/Makefile) +AC_OUTPUT(Makefile platforms/posix/src/Makefile example/Makefile) diff --git a/example/libusb/Makefile b/example/libusb/Makefile index 54ea2ca3e..ec614f35c 100644 --- a/example/libusb/Makefile +++ b/example/libusb/Makefile @@ -1,4 +1,5 @@ BTSTACK_ROOT = ../.. +POSIX_ROOT= ${BTSTACK_ROOT}/platforms/posix CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include CFLAGS += -I${BTSTACK_ROOT}/chipset-cc256x @@ -9,18 +10,16 @@ LDFLAGS = -L/usr/local/lib -lusb-1.0 LDFLAGS += -framework IOKit -framework CoreFoundation -framework Foundation CORE = \ - ${BTSTACK_ROOT}/src/btstack_memory.c \ - ${BTSTACK_ROOT}/src/linked_list.c \ - ${BTSTACK_ROOT}/src/memory_pool.c \ - ${BTSTACK_ROOT}/src/run_loop.c \ - ${BTSTACK_ROOT}/src/run_loop_posix.c \ + ${BTSTACK_ROOT}/src/btstack_memory.c \ + ${BTSTACK_ROOT}/src/linked_list.c \ + ${BTSTACK_ROOT}/src/memory_pool.c \ + ${BTSTACK_ROOT}/src/run_loop.c \ + ${POSIX_ROOT}/src/run_loop_posix.c \ COMMON = \ ${BTSTACK_ROOT}/src/hci.c \ ${BTSTACK_ROOT}/src/hci_cmds.c \ ${BTSTACK_ROOT}/src/hci_dump.c \ - ${BTSTACK_ROOT}/src/hci_transport_h4.c \ - ${BTSTACK_ROOT}/src/hci_transport_usb.c \ ${BTSTACK_ROOT}/src/l2cap.c \ ${BTSTACK_ROOT}/src/l2cap_signaling.c \ ${BTSTACK_ROOT}/src/remote_device_db_memory.c \ @@ -32,6 +31,8 @@ COMMON = \ ${BTSTACK_ROOT}/src/sdp_parser.c \ ${BTSTACK_ROOT}/src/sdp_query_util.c \ ${BTSTACK_ROOT}/src/sdp_query_rfcomm.c \ + ${POSIX_ROOT}/src/hci_transport_h4.c \ + ${POSIX_ROOT}/src/hci_transport_h2_libusb.c \ ATT = \ ${BTSTACK_ROOT}/ble/att_dispatch.c \ @@ -94,7 +95,7 @@ spp_counter: ${CORE_OBJ} ${COMMON_OBJ} spp_counter.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ spp_and_le_counter: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_REAL_OBJ} spp_and_le_counter.c spp_and_le_counter.h - ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ + ${CC} ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_REAL_OBJ} spp_and_le_counter.c ${CFLAGS} ${LDFLAGS} -o $@ spp_counter_ssp: ${CORE_OBJ} ${COMMON_OBJ} spp_counter_ssp.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ diff --git a/platforms/posix/src/Makefile.in b/platforms/posix/src/Makefile.in new file mode 100644 index 000000000..a5321ace0 --- /dev/null +++ b/platforms/posix/src/Makefile.in @@ -0,0 +1,73 @@ +BTSTACK_ROOT = ../../.. + +prefix = @prefix@ + +CC = @CC@ +LDFLAGS = @LDFLAGS@ +CPPFLAGS = @CPPFLAGS@ -I $(BTSTACK_ROOT)/include -I $(BTSTACK_ROOT)/ble -I $(BTSTACK_ROOT)/src -I $(BTSTACK_ROOT) +BTSTACK_LIB_LDFLAGS = @BTSTACK_LIB_LDFLAGS@ +BTSTACK_LIB_EXTENSION = @BTSTACK_LIB_EXTENSION@ + +remote_device_db_sources = @REMOTE_DEVICE_DB_SOURCES@ +run_loop_sources = @RUN_LOOP_SOURCES@ +usb_sources = @USB_SOURCES@ + +libBTstack_SOURCES = \ + btstack.c \ + socket_connection.c \ + $(BTSTACK_ROOT)/src/hci_cmds.c \ + $(BTSTACK_ROOT)/src/linked_list.c \ + $(BTSTACK_ROOT)/src/run_loop.c \ + $(BTSTACK_ROOT)/src/sdp_util.c \ + $(BTSTACK_ROOT)/src/utils.c \ + $(run_loop_sources) \ + +BTdaemon_SOURCES = \ + daemon.c \ + hci_transport_h4.c \ + $(libBTstack_SOURCES) \ + $(BTSTACK_ROOT)/src/btstack_memory.c \ + $(BTSTACK_ROOT)/src/hci.c \ + $(BTSTACK_ROOT)/src/hci_dump.c \ + $(BTSTACK_ROOT)/src/l2cap.c \ + $(BTSTACK_ROOT)/src/l2cap_signaling.c \ + $(BTSTACK_ROOT)/src/memory_pool.c \ + $(BTSTACK_ROOT)/src/rfcomm.c \ + $(BTSTACK_ROOT)/src/sdp.c \ + $(BTSTACK_ROOT)/src/sdp_client.c \ + $(BTSTACK_ROOT)/src/sdp_parser.c \ + $(BTSTACK_ROOT)/src/sdp_query_rfcomm.c \ + $(BTSTACK_ROOT)/src/sdp_query_util.c \ + $(BTSTACK_ROOT)/ble/att_dispatch.c \ + $(BTSTACK_ROOT)/ble/gatt_client.c \ + $(BTSTACK_ROOT)/ble/sm.c \ + $(BTSTACK_ROOT)/ble/central_device_db_memory.c \ + $(usb_sources) \ + $(remote_device_db_sources) \ + +# use $(CC) for Objective-C files +.m.o: + $(CC) $(CPPFLAGS) -c -o $@ $< + +all: $(BTSTACK_ROOT)/src/libBTstack.$(BTSTACK_LIB_EXTENSION) $(BTSTACK_ROOT)/src/libBTstack.a $(BTSTACK_ROOT)/src/BTdaemon + +$(BTSTACK_ROOT)/src/libBTstack.$(BTSTACK_LIB_EXTENSION): $(libBTstack_SOURCES) + $(BTSTACK_ROOT)/src/get_version.sh + $(CC) $(CPPFLAGS) $(BTSTACK_LIB_LDFLAGS) -o $@ $(libBTstack_SOURCES) $(LDFLAGS) + +$(BTSTACK_ROOT)/src/libBTstack.a: $(libBTstack_SOURCES:.c=.o) $(libBTstack_SOURCES:.m=.o) + ar cru $@ $(libBTstack_SOURCES:.c=.o) $(libBTstack_SOURCES:.m=.o) + ranlib $@ + +$(BTSTACK_ROOT)/src/BTdaemon: $(BTdaemon_SOURCES) + $(CC) $(CPPFLAGS) -DHAVE_HCI_DUMP -o $@ $(BTdaemon_SOURCES) $(LDFLAGS) + +clean: + rm -rf $(BTSTACK_ROOT)/src/libBTstack* $(BTSTACK_ROOT)/src/BTdaemon *.o + +install: + echo "installing BTdaemon in $(prefix)..." + mkdir -p $(prefix)/bin $(prefix)/lib $(prefix)/include + cp $(BTSTACK_ROOT)/src/libBTstack.a libBTstack.dylib $(prefix)/lib/ + cp $(BTSTACK_ROOT)/src/BTdaemon $(prefix)/bin/ + cp -r $(BTSTACK_ROOT)/include/btstack $(prefix)/include diff --git a/src/btstack.c b/platforms/posix/src/btstack.c similarity index 100% rename from src/btstack.c rename to platforms/posix/src/btstack.c diff --git a/src/daemon.c b/platforms/posix/src/daemon.c similarity index 100% rename from src/daemon.c rename to platforms/posix/src/daemon.c diff --git a/src/hci_transport_usb.c b/platforms/posix/src/hci_transport_h2_libusb.c similarity index 100% rename from src/hci_transport_usb.c rename to platforms/posix/src/hci_transport_h2_libusb.c diff --git a/src/hci_transport_h4.c b/platforms/posix/src/hci_transport_h4.c similarity index 100% rename from src/hci_transport_h4.c rename to platforms/posix/src/hci_transport_h4.c diff --git a/src/run_loop_posix.c b/platforms/posix/src/run_loop_posix.c similarity index 100% rename from src/run_loop_posix.c rename to platforms/posix/src/run_loop_posix.c diff --git a/src/socket_connection.c b/platforms/posix/src/socket_connection.c similarity index 100% rename from src/socket_connection.c rename to platforms/posix/src/socket_connection.c diff --git a/src/socket_connection.h b/platforms/posix/src/socket_connection.h similarity index 100% rename from src/socket_connection.h rename to platforms/posix/src/socket_connection.h diff --git a/src/Makefile.in b/src/Makefile.in deleted file mode 100644 index 666d72a7a..000000000 --- a/src/Makefile.in +++ /dev/null @@ -1,66 +0,0 @@ -prefix = @prefix@ - -CC = @CC@ -LDFLAGS = @LDFLAGS@ -CPPFLAGS = @CPPFLAGS@ -I../include -I../ble -I../src -I.. -BTSTACK_LIB_LDFLAGS = @BTSTACK_LIB_LDFLAGS@ -BTSTACK_LIB_EXTENSION = @BTSTACK_LIB_EXTENSION@ - -remote_device_db_sources = @REMOTE_DEVICE_DB_SOURCES@ -run_loop_sources = @RUN_LOOP_SOURCES@ -usb_sources = @USB_SOURCES@ - -libBTstack_SOURCES = btstack.c hci_cmds.c linked_list.c run_loop.c $(run_loop_sources) sdp_util.c socket_connection.c utils.c - -BTdaemon_SOURCES = $(libBTstack_SOURCES) \ - $(platform_sources) \ - btstack_memory.c \ - daemon.c \ - hci.c \ - hci_dump.c \ - hci_transport_h4.c \ - $(usb_sources) \ - l2cap.c \ - l2cap_signaling.c \ - memory_pool.c \ - $(remote_device_db_sources) \ - rfcomm.c \ - sdp.c \ - sdp_client.c \ - sdp_parser.c \ - sdp_query_rfcomm.c \ - sdp_query_util.c \ - $(springboard_access_sources) \ - ../ble/att_dispatch.c \ - ../ble/gatt_client.c \ - ../ble/sm.c \ - ../ble/central_device_db_memory.c \ - - - -# use $(CC) for Objective-C files -.m.o: - $(CC) $(CPPFLAGS) -c -o $@ $< - -all: libBTstack.$(BTSTACK_LIB_EXTENSION) libBTstack.a BTdaemon - -libBTstack.$(BTSTACK_LIB_EXTENSION): $(libBTstack_SOURCES) - ./get_version.sh - $(CC) $(CPPFLAGS) $(BTSTACK_LIB_LDFLAGS) -o $@ $(libBTstack_SOURCES) $(LDFLAGS) - -libBTstack.a: $(libBTstack_SOURCES:.c=.o) $(libBTstack_SOURCES:.m=.o) - ar cru $@ $(libBTstack_SOURCES:.c=.o) $(libBTstack_SOURCES:.m=.o) - ranlib $@ - -BTdaemon: $(BTdaemon_SOURCES) - $(CC) $(CPPFLAGS) -DHAVE_HCI_DUMP -o $@ $(BTdaemon_SOURCES) $(LDFLAGS) - -clean: - rm -rf libBTstack* BTdaemon *.o - -install: - echo "installing BTdaemon in $(prefix)..." - mkdir -p $(prefix)/bin $(prefix)/lib $(prefix)/include - cp libBTstack.a libBTstack.dylib $(prefix)/lib/ - cp BTdaemon $(prefix)/bin/ - cp -r ../include/btstack $(prefix)/include