Skip to content

Instantly share code, notes, and snippets.

@xiongyihui
Last active August 29, 2015 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiongyihui/0c82af0c4555c11df226 to your computer and use it in GitHub Desktop.
Save xiongyihui/0c82af0c4555c11df226 to your computer and use it in GitHub Desktop.
Makefile for BLE_API (https://github.com/xiongyihui/BLE_API)
GCC_BIN =
LIBRARY = ble_api
SRC_DIR := common public services
BUILD_DIR := $(addprefix build/,$(SRC_DIR))
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
OBJ := $(patsubst %.cpp,build/%.o,$(SRC))
INCLUDES := $(addprefix -I,$(SRC_DIR))
# remove UARTService.o
OBJ := $(filter-out build/services/UARTService.o,$(OBJ))
vpath %.cpp $(SRC_DIR)
###############################################################################
AS = $(GCC_BIN)arm-none-eabi-as
CC = $(GCC_BIN)arm-none-eabi-gcc
CPP = $(GCC_BIN)arm-none-eabi-g++
AR = $(GCC_BIN)arm-none-eabi-ar
LD = $(GCC_BIN)arm-none-eabi-gcc
OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy
CPU = -mcpu=cortex-m0 -mthumb
CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-rtti
define make-goal
$1/%.o: %.cpp
$(CPP) $(cc_FLAGS) -std=gnu++98 $(INCLUDES) -c $$< -o $$@
endef
.PHONY: all checkdirs clean
all: checkdirs lib$(LIBRARY).a
lib$(LIBRARY).a: $(OBJ)
$(AR) rcs $@ $^
%.o: %.cpp
$(CPP) $(CC_FLAGS) -std=gnu++98 $(INCLUDES) -c $< -o $@
checkdirs: $(BUILD_DIR)
$(BUILD_DIR):
@mkdir -p $@
clean:
@rm -rf $(BUILD_DIR)
$(foreach bdir,$(BUILD_DIR),$(eval $(call make-goal,$(bdir))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment