-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
174 lines (132 loc) · 4.63 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
PROJECT_NAME := nytcoin
PRJ_PATH = .
OBJECT_DIRECTORY = _build
OUTPUT_BINARY_DIRECTORY = .
OUTPUT_FILENAME := $(PROJECT_NAME)
export OUTPUT_FILENAME
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
#GNU_PREFIX := arm-none-eabi-
MK := mkdir
RM := rm -rf
#echo suspend
ifeq ("$(VERBOSE)","1")
NO_ECHO :=
else
NO_ECHO := @
endif
# Toolchain commands
CC := "$(GNU_PREFIX)gcc"
#CC := "$(GNU_PREFIX)clang"
AS := "$(GNU_PREFIX)as"
AR := "$(GNU_PREFIX)ar" -r
LD := "$(GNU_PREFIX)ld"
NM := "$(GNU_PREFIX)nm"
OBJDUMP := "$(GNU_PREFIX)objdump"
OBJCOPY := "$(GNU_PREFIX)objcopy"
SIZE := "$(GNU_PREFIX)size"
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
#sources project
C_SOURCE_FILES += $(PRJ_PATH)/src/bc_proto.c
C_SOURCE_FILES += $(PRJ_PATH)/src/bc_flash.c
C_SOURCE_FILES += $(PRJ_PATH)/src/bc_network.c
C_SOURCE_FILES += $(PRJ_PATH)/src/main.c
#assembly files common to all targets
#ASM_SOURCE_FILES = $(SDK_PATH)/some.s
#includes
INC_PATHS += -I$(PRJ_PATH)/include
INC_PATHS += -Ilibs
INC_PATHS += -Ilibs/ptarmbtc/include
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
######################################
#CFLAGS
######################################
# cpu
#CFLAGS += -mcpu=cortex-m0
#CFLAGS += -mthumb -mabi=aapcs
#CFLAGS += -mfloat-abi=soft
CFLAGS += --std=gnu99
CFLAGS += -Wall
# keep every function in separate section. This will allow linker to dump unused functions
#CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
#CFLAGS += -flto -fno-builtin
# others
######################################
#LDFLAGS
######################################
# cpu
#LDFLAGS += -mcpu=cortex-m0
# keep every function in separate section. This will allow linker to dump unused functions
#LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
# let linker to dump unused sections
#LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
#LDFLAGS += --specs=nano.specs -lc -lnosys
#POSIX thread
LDFLAGS += -pthread
#Link Library
LIBSTT += \
libs/libbloom/build/libbloom.a \
libs/ptarmbtc/lib/libbtc.a \
libs/ptarmbtc/lib/libutl.a \
libs/ptarmbtc/lib/libmbedcrypto.a \
libs/ptarmbtc/lib/libbase58.a
LIBDYN += -lm
#default target - first one defined
default: all
#building all targets
all: libbloom .Depend
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e debug
#target for printing all targets
help:
@echo following targets are available:
@echo debug release
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
vpath %.c $(C_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
debug: CFLAGS += -DDEBUG
debug: CFLAGS += -ggdb3 -O0
debug: ASMFLAGS += -DDEBUG -ggdb3 -O0
debug: LDFLAGS += -ggdb3 -O0
debug: $(BUILD_DIRECTORIES) $(OBJECTS)
@echo [DEBUG]Linking target: $(OUTPUT_FILENAME)
@echo [DEBUG]CFLAGS=$(CFLAGS)
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBSTT) $(LIBDYN) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME)
release: CFLAGS += -DNDEBUG -O3
release: ASMFLAGS += -DNDEBUG -O3
release: LDFLAGS += -O3
release: $(BUILD_DIRECTORIES) $(OBJECTS)
@echo [RELEASE]Linking target: $(OUTPUT_FILENAME)
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME)
## Create build directories
$(BUILD_DIRECTORIES):
$(MK) $@
# Create objects from C SRC files
$(OBJECT_DIRECTORY)/%.o: %.c
@echo Compiling C file: $(notdir $<): $(CFLAGS)
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
@echo Compiling ASM file: $(notdir $<)
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
libbloom:
git submodule update --init --recursive
make -C libs/libbloom MURMURHASH_VERSION=3
# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME): $(BUILD_DIRECTORIES) $(OBJECTS)
@echo Linking target: $(OUTPUT_FILENAME)
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME)
clean:
$(RM) $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).exe $(OUTPUT_BINARY_DIRECTORY)/*.stackdump .Depend
distclean: clean
@make -C libs/libbloom clean
.Depend:
ifneq ($(MAKECMDGOALS),clean)
@$(foreach SRC,$(C_SOURCE_FILES),$(CC) $(CFLAGS) $(CFLAGS_ONLY) $(INC_PATHS) -MM -MT $(OBJECT_DIRECTORY)/$(notdir $(SRC:%.c=%.o)) $(SRC) >> .Depend; )
endif
-include .Depend