summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-05-03 16:30:16 +0100
committerVasil Zlatanov <v@skozl.com>2017-05-03 16:30:16 +0100
commita6ed1742539c62186fb903017b52dd48f145ae4f (patch)
treee9f49f0437e1f260b276b45fddcb66ea524f49e3 /Makefile
downloade2-switch-a6ed1742539c62186fb903017b52dd48f145ae4f.tar.gz
e2-switch-a6ed1742539c62186fb903017b52dd48f145ae4f.tar.bz2
e2-switch-a6ed1742539c62186fb903017b52dd48f145ae4f.zip
Add template and build environment.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile158
1 files changed, 158 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..94542db
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,158 @@
+LINKER_NAME = LPC1768
+STARTUP_NAME = startup_LPC17xx
+SYSTEM_NAME = system_LPC17xx
+TARGET_BOARD = TARGET_LPC1768
+TARGET_VENDOR = TARGET_NXP
+TARGET_FAMILY = TARGET_LPC176X
+TARGET_SPECIFIC = TARGET_MBED_LPC1768
+CPU = cortex-m3
+
+# path to the mbed library
+MBED_DIR = ext
+
+# toolchain specific
+TOOLCHAIN = arm-none-eabi-
+CC = $(TOOLCHAIN)gcc
+CXX = $(TOOLCHAIN)g++
+AS = $(TOOLCHAIN)gcc -x assembler-with-cpp
+LD = $(TOOLCHAIN)gcc
+OBJCP = $(TOOLCHAIN)objcopy
+AR = $(TOOLCHAIN)ar
+
+# application specific
+INSTRUCTION_MODE = thumb
+TARGET = mbed
+TARGET_EXT = elf
+LD_SCRIPT = $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/$(LINKER_NAME).ld
+
+CC_SYMBOLS = -D$(TARGET_BOARD) -DTOOLCHAIN_GCC_ARM -DNDEBUG
+
+LIB_DIRS = $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM
+LIBS = -lmbed -lstdc++ -lsupc++ -lm -lgcc -lc -lnosys
+
+MBED_OBJ = $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/board.o
+MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/cmsis_nvic.o
+MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/$(STARTUP_NAME).o
+MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/retarget.o
+MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/$(SYSTEM_NAME).o
+ifneq ("$(wildcard $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/mbed_overrides.o)","")
+ MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/mbed_overrides.o
+endif
+
+# directories
+INC_DIRS = $(MBED_DIR) $(MBED_DIR)/$(TARGET_BOARD) $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM
+INC_DIRS += $(MBED_DIR)/$(TARGET_BOARD)/$(TARGET_VENDOR)/$(TARGET_FAMILY)
+INC_DIRS += $(MBED_DIR)/$(TARGET_BOARD)/$(TARGET_VENDOR)/$(TARGET_FAMILY)/$(TARGET_SPECIFIC)
+
+SRC_DIRS = $(MBED_DIR) $(MBED_DIR)/$(TARGET_BOARD) $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM .
+SRC_DIRS += $(MBED_DIR)/$(TARGET_BOARD)/$(TARGET_VENDOR)/$(TARGET_FAMILY)
+SRC_DIRS += $(MBED_DIR)/$(TARGET_BOARD)/$(TARGET_VENDOR)/$(TARGET_FAMILY)/$(TARGET_SPECIFIC)
+SRC_DIRS += src
+# app source directories (remove comment and add more files)
+#SRC_DIRS +=
+
+OUT_DIR = build
+
+INC_DIRS_F = -I. $(patsubst %, -I%, $(INC_DIRS))
+
+ifeq ($(strip $(OUT_DIR)), )
+ OBJ_FOLDER =
+else
+ OBJ_FOLDER = $(strip $(OUT_DIR))/
+endif
+
+COMPILER_OPTIONS = -g -ggdb -Os -Wall -fno-strict-aliasing -fno-rtti
+COMPILER_OPTIONS += -ffunction-sections -fdata-sections -fno-exceptions -fno-delete-null-pointer-checks
+COMPILER_OPTIONS += -fmessage-length=0 -fno-builtin -m$(INSTRUCTION_MODE)
+COMPILER_OPTIONS += -mcpu=$(CPU) -MMD -MP $(CC_SYMBOLS)
+
+DEPEND_OPTS = -MF $(OBJ_FOLDER)$(@F:.o=.d)
+
+# Flags
+CFLAGS = $(COMPILER_OPTIONS) $(DEPEND_OPTS) $(INC_DIRS_F) -std=gnu99 -c
+
+CXXFLAGS = $(COMPILER_OPTIONS) $(DEPEND_OPTS) $(INC_DIRS_F) -std=gnu++98 -c
+
+ASFLAGS = $(COMPILER_OPTIONS) $(INC_DIRS_F) -c
+
+# Linker options
+LD_OPTIONS = -mcpu=$(CPU) -m$(INSTRUCTION_MODE) -Os -L $(LIB_DIRS) -T $(LD_SCRIPT) $(INC_DIRS_F)
+LD_OPTIONS += -specs=nano.specs
+#use this if %f is used, by default it's commented
+#LD_OPTIONS += -u _printf_float -u _scanf_float
+LD_OPTIONS += -Wl,-Map=$(OBJ_FOLDER)$(TARGET).map,--gc-sections
+
+OBJCPFLAGS = -O ihex
+
+ARFLAGS = cr
+
+RM = rm -rf
+
+USER_OBJS =
+C_SRCS =
+S_SRCS =
+C_OBJS =
+S_OBJS =
+
+# All source/object files inside SRC_DIRS
+C_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
+C_OBJS := $(patsubst %.c,$(OBJ_FOLDER)%.o,$(notdir $(C_SRCS)))
+
+CPP_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
+CPP_OBJS := $(patsubst %.cpp,$(OBJ_FOLDER)%.o,$(notdir $(CPP_SRCS)))
+
+S_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s))
+S_OBJS := $(patsubst %.s,$(OBJ_FOLDER)%.o,$(notdir $(S_SRCS)))
+
+VPATH := $(SRC_DIRS)
+
+$(OBJ_FOLDER)%.o : %.c
+ @echo 'Building file: $(@F)'
+ @echo 'Invoking: MCU C Compiler'
+ $(CC) $(CFLAGS) $< -o $@
+ @echo 'Finished building: $(@F)'
+ @echo ' '
+
+$(OBJ_FOLDER)%.o : %.cpp
+ @echo 'Building file: $(@F)'
+ @echo 'Invoking: MCU C++ Compiler'
+ $(CXX) $(CXXFLAGS) $< -o $@
+ @echo 'Finished building: $(@F)'
+ @echo ' '
+
+$(OBJ_FOLDER)%.o : %.s
+ @echo 'Building file: $(@F)'
+ @echo 'Invoking: MCU Assembler'
+ $(AS) $(ASFLAGS) $< -o $@
+ @echo 'Finished building: $(@F)'
+ @echo ' '
+
+all: create_outputdir $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) print_info
+
+create_outputdir:
+ $(shell mkdir $(OBJ_FOLDER) 2>/dev/null)
+
+# Tool invocations
+$(OBJ_FOLDER)$(TARGET).$(TARGET_EXT): $(LD_SCRIPT) $(C_OBJS) $(CPP_OBJS) $(S_OBJS) $(MBED_OBJ)
+ @echo 'Building target: $@'
+ @echo 'Invoking: MCU Linker'
+ $(LD) $(LD_OPTIONS) $(CPP_OBJS) $(C_OBJS) $(S_OBJS) $(MBED_OBJ) $(LIBS) -o $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT)
+ @echo 'Finished building target: $@'
+ @echo ' '
+
+# Other Targets
+clean:
+ @echo 'Removing entire out directory'
+ $(RM) $(TARGET).$(TARGET_EXT) $(TARGET).bin $(TARGET).map $(OBJ_FOLDER)*.* $(OBJ_FOLDER)
+ @echo ' '
+
+print_info:
+ @echo 'Printing size'
+ arm-none-eabi-size --totals $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT)
+ arm-none-eabi-objcopy -O srec $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) $(OBJ_FOLDER)$(TARGET).s19
+ arm-none-eabi-objcopy -O binary -v $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) $(OBJ_FOLDER)$(TARGET).bin
+ arm-none-eabi-objdump -D $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) > $(OBJ_FOLDER)$(TARGET).lst
+ arm-none-eabi-nm $(OBJ_FOLDER)$(TARGET).$(TARGET_EXT) > $(OBJ_FOLDER)$(TARGET)-symbol-table.txt
+ @echo ' '
+
+.PHONY: all clean print_info