diff --git a/Makefile b/Makefile index f1a2c7f..552f8ad 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,19 @@ -CC := gcc -LIB_DIRECTORY := -L/usr/lib/arm-linux-gnueabihf +# Default to the host architecture +ARCH ?= $(shell uname -m) + +ifeq ($(ARCH),x86_64) + CC := gcc +else ifeq ($(ARCH),arm) + CC := arm-linux-gnueabihf-gcc + CFLAGS += -marm +else ifeq ($(ARCH),aarch64) + CC := aarch64-linux-gnu-gcc +endif + +LIB_DIRECTORY := -L/usr/lib/$(ARCH)-linux-gnu INC_DIRECTORY := -I/usr/include/bluetooth -LIB := /usr/lib/arm-linux-gnueabihf/libbluetooth.a -CFLAGS := -Wall -fPIC +LIB := -lbluetooth +CFLAGS += -Wall -fPIC .c.o: $(CC) $(INC_DIRECTORY) $(CFLAGS) -c $< @@ -11,11 +22,11 @@ all: make tool make lib -tool: bletool.o - gcc -o bletool $(INC_DIRECTORY) $(LIB_DIRECTORY) $< -lbluetooth +tool: bletool.o + $(CC) -o bletool $(INC_DIRECTORY) $(LIB_DIRECTORY) $< $(LIB) -lib: bletool.o - gcc $(CFLAGS) -shared -o libbletool.so $< $(LIB) +lib: bletool.o + $(CC) $(CFLAGS) -shared -o libbletool.so $< $(LIB_DIRECTORY) $(LIB) install -m 644 libbletool.so ../ clean: diff --git a/README.md b/README.md index 1f6b571..52e0c13 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ Raw BLE advertisement tool This tool is for receiving/sending raw BLE advertisement messages. The project is based on the Linux Bluetooth protocol stack, [BlueZ](http://www.bluez.org/). -The is configured for Raspberry Pi 3 and LIB_DIRECTORY needs to be set properly for other environments. +The is configured for Raspberry Pi 3 and 4, also X86_64 Ubuntu 22.04. ## Preparation Install dependencies. ``` -sudo apt update && sudo apt-get -y install libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libical-dev libreadline-dev libudev-dev libusb-dev make bluetooth bluez-utils libbluetooth-dev +sudo apt update && sudo apt-get -y install libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libical-dev libreadline-dev libudev-dev libusb-dev make bluetooth libbluetooth-dev ``` ## Compilation