forked from Cellivar/stellaris-enc28j60
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
150 lines (114 loc) · 3.58 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Configurable variables
# Compiler setup
CC_PREFIX=arm-none-eabi-
CXX=$(CC_PREFIX)g++
CC=$(CC_PREFIX)gcc
OBJCOPY=$(CC_PREFIX)objcopy
SIZE=$(CC_PREFIX)size
# Build directory
BUILD_DIR=build/
STELLARIS=$(HOME)/opt/stellaris-launchpad
UIP_DIR=uip-1.0
# Flash setup
LM4FLASH=$(STELLARIS)/lm4flash
# Base name of the binary targets (.elf, .bin)
TARGET_NAME=enc28j60
# Target CPU configuration
CPU=-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
LINKER_SCRIPT=LM4F.ld
# Used to give some useful statistics after linking
FLASH_SIZE=262144
RAM_SIZE=32768
# Common C/C++ compiler flags
COMMON_FLAGS=$(CPU) -ffunction-sections -fdata-sections -Os
# C/C++ pre-processor defines and include paths
DEFINES=$(DEFS) -DTARGET_IS_BLIZZARD_RA2 -DPART_LM4F120H5QR -DUART_BUFFERED -D_DEBUG
INCLUDES=-I$(STELLARIS) -Iuip-1.0 -I. -I uip-1.0/uip
# C++ compiler specific flags
CXXFLAGS=-fno-rtti -fno-exceptions
# C compiler specific flags
CFLAGS=--std=gnu99
# Linker flags
LDFLAGS=$(CPU) -nodefaultlibs -T$(LINKER_SCRIPT)
# Libraries to link against
LIBS=-lm -lc
# We need to extend VPATH in order to be able to
# find the source files which are located in deep paths
SRC_DIRS += $(UIP_DIR)/uip
SRC_DIRS += $(UIP_DIR)/apps/dhcpc
UIP_SRCS=$(UIP_DIR)/uip/uip.c \
$(UIP_DIR)/uip/uip_timer.c \
$(UIP_DIR)/uip/psock.c \
$(UIP_DIR)/uip/uip_arp.c \
$(UIP_DIR)/apps/dhcpc/dhcpc.c
# C++ source code files
CXX_SRCS=main.cpp enc28j60.cpp
# C source code
C_SRCS=dummyfuncs.c \
startup_gcc.c \
$(UIP_SRCS) \
httpd.c
# End of configuriable variables
SHELL=bash
SRCS=$(CXX_SRCS) $(C_SRCS)
OBJS=$(addprefix $(BUILD_DIR), $(notdir $(CXX_SRCS:.cpp=.o)) $(C_SRCS:.c=.o))
DEPS=$(OBJS:.o=.d)
TARGET_ELF=$(BUILD_DIR)$(TARGET_NAME).elf
TARGET_BIN=$(BUILD_DIR)$(TARGET_NAME).bin
GCC_DEP_GEN=-MD -MP -MF $(BUILD_DIR)$(@F:.o=.d)
_CXXFLAGS=$(COMMON_FLAGS) $(CXXFLAGS) $(GCC_DEP_GEN) $(DEFINES) $(INCLUDES)
_CFLAGS=$(COMMON_FLAGS) $(CFLAGS) $(GCC_DEP_GEN) $(DEFINES) $(INCLUDES)
BUILD_DIRS=$(sort $(dir $(OBJS)))
define print-memory-usage
FLASH_USAGE=$$($(SIZE) $@ | tail -1 | cut -f 1 | tr -d ' '); \
DATA_USAGE=$$($(SIZE) $@ | tail -1 | cut -f 2 | tr -d ' '); \
BSS_USAGE=$$($(SIZE) $@ | tail -1 | cut -f 3 | tr -d ' '); \
let "FLASH_P=$$FLASH_USAGE*100 / $(FLASH_SIZE)"; \
let "RAM_USAGE=$$DATA_USAGE+$$BSS_USAGE"; \
let "RAM_P=$$RAM_USAGE*100 / $(RAM_SIZE)"; \
printf "Flash usage : %6dB / %6dB = %2d%%\n" "$$FLASH_USAGE" "$(FLASH_SIZE)" "$$FLASH_P"; \
printf "Static RAM usage: %6dB / %6dB = %2d%%\n" "$$RAM_USAGE" "$(RAM_SIZE)" "$$RAM_P"
endef
.PHONY: print-config
all: print-config $(BUILD_DIR) $(TARGET_BIN)
load: $(TARGET_BIN)
@echo "Flashing $(TARGET_BIN) to target"
$(LM4FLASH) $(TARGET_BIN)
print-config:
@echo "SETTINGS:"
@echo "---------"
@echo "Compiler prefix: $(CC_PREFIX)"
@echo "Commong flags : $(COMMON_FLAGS)"
@echo "Defines : $(DEFINES)"
@echo "C flags : $(CFLAGS)"
@echo "C++ flags : $(CXXFLAGS)"
@echo
print-config-verbose: print-config
@echo $(OBJS)
@echo $(BUILD_DIRS)
$(OBJS): Makefile
$(BUILD_DIR):
@mkdir -p $(BUILD_DIRS)
$(TARGET_ELF): $(OBJS) $(LINKER_SCRIPT)
@echo "Linking $@"
$(CXX) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)
@echo
@$(print-memory-usage)
@echo
$(TARGET_BIN): $(TARGET_ELF)
@echo "$(TARGET_ELF) -> $(TARGET_BIN)"
@$(OBJCOPY) -O binary $(TARGET_ELF) $(TARGET_BIN)
clean:
@echo "Removing '$(BUILD_DIR)'"
@rm -rf $(BUILD_DIR)
$(BUILD_DIR)%.o: %.cpp
@echo "C++ compiling '$<'"
@echo " -> $@"
@$(CXX) -c $(_CXXFLAGS) $< -o $@
@echo
$(BUILD_DIR)%.o: %.c
@echo "C compiling '$<'"
@echo " -> $@"
@$(CC) -c $(_CFLAGS) $< -o $@
@echo
-include $(DEPS)