-
Notifications
You must be signed in to change notification settings - Fork 193
/
Makefile
104 lines (79 loc) · 3.25 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
################################################################################
# Makefile to build the improved T-962 firmware without LPCXpresso
#
# Makes a 'build' directory in the root of the project.
################################################################################
BASE_NAME := T-962-controller
SRC_DIR := ./src/
BUILD_DIR := ./build/
TARGET := $(BUILD_DIR)$(BASE_NAME).axf
vpath %.c $(SRC_DIR)
vpath %.o $(BUILD_DIR)
vpath %.d $(BUILD_DIR)
CC := arm-none-eabi-gcc
RM := rm -rf
# Flash tool settings
FLASH_TOOL := ./lpc21isp
FLASH_TTY := /dev/ttyUSB0
FLASH_BAUD := 57600
MCU_CLOCK := 11059
COLOR_GREEN = $(shell echo "\033[0;32m")
COLOR_RED = $(shell echo "\033[0;31m")
COLOR_END = $(shell echo "\033[0m")
# Source files
C_SRCS += $(wildcard $(SRC_DIR)*.c) $(BUILD_DIR)version.c
S_SRCS += $(wildcard $(SRC_DIR)*.s)
OBJS := $(patsubst $(SRC_DIR)%.c,$(BUILD_DIR)%.o,$(C_SRCS)) $(patsubst $(SRC_DIR)%.s,$(BUILD_DIR)%.o,$(S_SRCS))
C_DEPS := $(wildcard *.d)
all: axf
$(BUILD_DIR)version.c: $(BUILD_DIR)tag
git describe --tag --always --dirty | \
sed 's/.*/const char* Version_GetGitVersion(void) { return "&"; }/' > $@
# Always regenerate the git version
.PHONY: $(BUILD_DIR)version.c
$(BUILD_DIR)tag:
mkdir -p $(BUILD_DIR)
touch $(BUILD_DIR)tag
$(BUILD_DIR)%.o: $(SRC_DIR)%.c $(BUILD_DIR)tag
@echo 'Building file: $<'
$(CC) -std=gnu99 -DNDEBUG -D__NEWLIB__ -Os -g -Wall -Wunused -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -flto -ffat-lto-objects -mcpu=arm7tdmi -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $(COLOR_GREEN)$<$(COLOR_END)'
@echo ' '
$(BUILD_DIR)%.o: $(SRC_DIR)%.s $(BUILD_DIR)tag
@echo 'Building file: $<'
$(CC) -c -x assembler-with-cpp -I $(BUILD_DIR) -DNDEBUG -D__NEWLIB__ -mcpu=arm7tdmi -o "$@" "$<"
@echo 'Finished building: $(COLOR_GREEN)$<$(COLOR_END)'
@echo ' '
axf: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: MCU Linker'
$(CC) -nostdlib -Xlinker -Map="$(BUILD_DIR)$(BASE_NAME).map" -Xlinker --gc-sections -flto -Os -mcpu=arm7tdmi --specs=nano.specs -u _printf_float -u _scanf_float -T "$(BASE_NAME).ld" -o "$(TARGET)" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $(COLOR_GREEN)$@$(COLOR_END)'
@echo ' '
$(MAKE) --no-print-directory post-build
clean:
-$(RM) $(BUILD_DIR)
-@echo ' '
post-build:
-@echo 'Performing post-build steps'
-arm-none-eabi-gcc --version
-arm-none-eabi-size "$(TARGET)";
-arm-none-eabi-objcopy -v -O ihex "$(TARGET)" "$(BUILD_DIR)$(BASE_NAME).hex"
-@echo ' '
lpc21isp: $(BUILD_DIR)tag
-@echo ''
-@echo 'Downloading lpc21isp 1.97 source from sourceforge'
wget http://sourceforge.net/projects/lpc21isp/files/lpc21isp/1.97/lpc21isp_197.zip/download -O $(BUILD_DIR)lpc21isp.zip
unzip -qq -o $(BUILD_DIR)lpc21isp.zip -d $(BUILD_DIR)
-@echo 'Making lpc21isp'
$(MAKE) -C $(BUILD_DIR)lpc21isp_197/
-@echo 'Copy lpc21isp binary to current directory'
cp $(BUILD_DIR)lpc21isp_197/lpc21isp .
-@echo ''
flash: axf lpc21isp
@echo ''
@echo 'Flashing $(COLOR_GREEN)$(BASE_NAME).hex$(COLOR_END) to $(COLOR_RED)$(FLASH_TTY)$(COLOR_END)'
$(FLASH_TOOL) "$(BUILD_DIR)$(BASE_NAME).hex" $(FLASH_TTY) $(FLASH_BAUD) $(MCU_CLOCK)
.PHONY: clean dependents
.SECONDARY: post-build
-include ../makefile.targets