-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenwrt-mips.mk
170 lines (128 loc) · 4.74 KB
/
openwrt-mips.mk
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
# Copyright (C) 2015 Eugene Hutorny <[email protected]>
#
# host.mk - make script to build COJSON Library tests for the host
#
# This file is part of COJSON Library. http://hutorny.in.ua/projects/cojson
#
# The COJSON Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License v2
# as published by the Free Software Foundation;
#
# The COJSON Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with the COJSON Library; if not, see
# <http://www.gnu.org/licenses/gpl-2.0.html>.
# This makefile builds unit tests for cojson
# It is not intended to build any other applications
# variable expected from the outer Makefile:
# BASE-DIR SRC-DIRS INCLUDES TARGET TARGET-DIR
PREFIX ?= mips-openwrt-linux-
CC := @$(PREFIX)gcc$(SUFFIX)
CXX := @$(PREFIX)g++$(SUFFIX)
LD := @$(PREFIX)g++$(SUFFIX)
SIZE:= @$(PREFIX)size
#STAGING_DIR
BOLD:=$(shell tput bold)
NORM:=$(shell tput sgr0)
FIND = find $(STAGING_DIR) \( -readable -or \! -prune \) \
\( -type f -o -type l \) -name $(PREFIX)g++$(SUFFIX) | tail -1
MAKEFLAGS += --no-builtin-rules
-include $(BASE-DIR)/openwrt-mips.vars
export PATH
export STAGING_DIR
COJSON-OBJS := \
common.o \
cojson.o \
cojson_libdep.o \
chartypetable.o \
coop.o \
host.o \
METRIC-OBJS := \
common.o \
cojson.o \
cojson_libdep.o \
chartypetable.o \
TESTS-BASIC := $(wildcard $(addprefix $(BASE-DIR)/suites/basic/, *.c *.cpp))
TESTS-BENCH := $(wildcard $(addprefix $(BASE-DIR)/suites/bench/, *.c *.cpp))
TESTS-HOST := 100.cpp 101.cpp #compilation fails on 102.cpp
TESTS-ALL := $(sort $(notdir $(TESTS-BASIC) $(TESTS-BENCH) $(TESTS-HOST)))
openwrt-mips-OBJS := $(patsubst %.c,%.o,$(TESTS-ALL:.cpp=.o))
openwrt-mips-uchar-OBJS := $(openwrt-mips-OBJS)
OBJS := \
$(COJSON-OBJS) \
CPPFLAGS += \
$(addprefix -I,$($(TARGET)-INCLUDES) $(INCLUDES)) \
$(addprefix -D,$($(TARGET)-DEFS) $(CXX-DEFS)) \
-Wall \
-Wextra \
-pedantic \
-pedantic-errors \
-O3 \
-fmessage-length=0 \
-ffunction-sections \
-fdata-sections \
-std=c++1y \
CFLAGS += \
$(addprefix -I,$(INCLUDES)) \
$(addprefix -D,$(CXX-DEFS)) \
-Wall \
-O3 \
-ffunction-sections \
-fdata-sections \
-std=gnu99 \
LDFLAGS += \
-s \
-L$(LIBPATH) \
METRIC-FLAGS := \
-Os \
METRIC-SRCS := $(notdir $(wildcard $(BASE-DIR)/suites/metrics/*.cpp))
METRICS := $(METRIC-SRCS:.cpp=.size)
vpath %.cpp $(subst $(eval) ,:,$(SRC-DIRS))
vpath %.c $(subst $(eval) ,:,$(SRC-DIRS))
.DEFAULT:
.SECONDARY:
.SUFFIXES:
.SUFFIXES: .hex .elf .o
$(TARGET)-uchar: CPPFLAGS += -funsigned-char
$(BASE-DIR)/openwrt-mips.vars:
@$(if $(filter-out clean,$(MAKECMDGOALS)), \
$(if $(STAGING_DIR), \
echo STAGING_DIR:=$(STAGING_DIR) > $@;, \
$(error STAGING_DIR is not set)))
@echo "# lookup for $(PREFIX)g++$(SUFFIX)" >> $@
@echo $(if $(shell which $(PREFIX)g++$(SUFFIX)), \
"# found in path\n# "$(shell which $(PREFIX)g++$(SUFFIX)), \
PATH=$(dir $(shell $(FIND))):$$PATH) >> $@
@echo LIBPATH=$(realpath $(dir $(shell $(FIND)))/../usr/lib) >> $@
%.o: %.c
@echo " $(BOLD)cc$(NORM)" $(notdir $<)
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.cpp
@echo " $(BOLD)c++$(NORM)" $(notdir $<)
$(CXX) $(CPPFLAGS) -c -o $@ $<
%.size: %.
$(SIZE) $< > $@
%.: %.cpp 00-base.o $(METRIC-OBJS)
@echo " $(BOLD)c++$(NORM)" $(notdir $<)
$(CXX) $(CPPFLAGS) $(FILE-FLAGS) $(METRIC-FLAGS) -o $@ $(filter-out $@o,$^)
$(TARGET-DIR)/%: $(OBJS) $($(TARGET)-OBJS)
@echo " $(BOLD)ld$(NORM) " $(notdir $@)
$(LD) $(LDFLAGS) -o $@ $^
$(TARGET-DIR):
@mkdir -p $(TARGET-DIR)
$(TARGET): $(BASE-DIR)/openwrt-mips.vars $(TARGET-DIR)/$(TARGET)
$(BASE-DIR)/openwrt-mips.metrics.txt: $(METRICS)
@head -1 $< > $@
@grep -h -v filename $(sort $^) >> $@
@cat $@
metrics: $(BASE-DIR)/openwrt-mips.metrics.txt
run: $(TARGET)
@echo " $(BOLD)run$(NORM) " $(TARGET)
@$(TARGET-DIR)/$(TARGET)
rebuild: clean $(TARGET)
clean:
@rm -f *.o *.map $(TARGET-DIR)/$(TARGET)