1: #
2: # ----------------------------------------------------------------------
3: # T-Kernel 2.0 Software Package
4: #
5: # Copyright 2011 by Ken Sakamura.
6: # This software is distributed under the latest version of T-License 2.x.
7: # ----------------------------------------------------------------------
8: #
9: # Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
10: # Modified by T-Engine Forum at 2012/11/07.
11: # Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
12: #
13: # ----------------------------------------------------------------------
14: #
15:
16: #
17: # makerules
18: # for GNU make
19: #
20: # default rules - system-dependent (EM1-D512)
21: #
22: # MACHINE target CPU
23: # em1d : EM1-D512
24: #
25: # TETYPE target T-Engine type
26: # tef : T-Engine Forum Reference Board
27: #
28: # GNUARM_2 GNU development tool for ARM
29: #
30:
31: # check environmental variables
32: ifndef GNU_BD
33: $(error 'GNU_BD' is not defined)
34: endif
35: ifndef GNUARM_2
36: ifndef GNUarm_2
37: $(error 'GNUARM_2' is not defined)
38: endif
39: # for compatibitily
40: GNUARM_2 = $(GNUarm_2)
41: endif
42:
43: # command path
44: PATH = .
45: ifneq ($(filter "$(origin GNUARM_2)", $(TOOL_ORIGIN)), )
46: PATH := $(PATH):$(GNUARM_2)/bin
47: endif
48: ifneq ($(filter "$(origin GNUs)", $(TOOL_ORIGIN)), )
49: PATH := $(PATH):$(GNUs)/bin
50: endif
51: ifneq ($(filter Linux-%, $(CROSS_ARCH)), )
52: PATH := $(PATH):/usr/local/bin:/bin:/usr/bin
53: endif
54: ifneq ($(filter Cygwin-%, $(CROSS_ARCH)), )
55: PATH := $(PATH):/usr/local/bin:/bin:/usr/bin
56: endif
57:
58: # ----- T-Engine Reference Board (EM1-D512) ----------------------------
59:
60: # GCC environment
61: TARGET_ARCH =
62:
63: # target type
64: _CPUTYPE_FLAGS = -mcpu=arm1176jzf-s -msoft-float -mfpu=vfp
65: _CPUTYPE_FLAGS_AS = -mcpu=arm1176jzf-s -mfpu=softvfp
66: _TE_SYSTEM_NAME_ = _TEF_EM1D_
67:
68: # code set
69: _CODESET_FLAGS = -mthumb-interwork
70:
71: ### build option ###
72: CFLAGS +=
73: CPPFLAGS +=
74: ASFLAGS +=
75: LDFLAGS +=
76:
77: ### C ###
78: CC := $(GNUARM_2)/bin/gcc4arm
79: OUTPUT_OPTION = -o $@
80: ifeq ($(mode), debug)
81: CFLAGS += -g
82: CPPFLAGS += $(HEADER:%=-I%) -D$(_TE_SYSTEM_NAME_) -DDEBUG
83: else
84: CFLAGS += -O2
85: CPPFLAGS += $(HEADER:%=-I%) -D$(_TE_SYSTEM_NAME_)
86: endif
87:
88: CFLAGS += $(_CPUTYPE_FLAGS) $(_CODESET_FLAGS) -mstructure-size-boundary=8 -ffreestanding
89:
90: CFLAGS_WARNING = -Wall -Wno-pointer-sign
91: CFLAGS_WARNING_FULL = -pedantic -W -Wall
92:
93: COMPILE.c = $(CC) $(TARGET_ARCH) $(CFLAGS) $(CPPFLAGS) -c
94: LINK.c = $(CC) $(TARGET_ARCH) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
95:
96: %.o: %.c
97: $(COMPILE.c) $< $(OUTPUT_OPTION)
98:
99: %.s: %.c
100: $(CC) $(TARGET_ARCH) $(CFLAGS) $(CPPFLAGS) -S $<
101:
102: %.i: %.c
103: $(CC) $(TARGET_ARCH) $(CFLAGS) $(CPPFLAGS) -E $< $(OUTPUT_OPTION)
104:
105: ### C++ ###
106: CXX := $(GNUARM_2)/bin/gcc4arm
107: CXXFLAGS = $(CFLAGS)
108:
109: COMPILE.cc = $(CXX) $(TARGET_ARCH) $(CXXFLAGS) $(CPPFLAGS) -c
110: LINK.cc = $(CXX) $(TARGET_ARCH) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
111:
112: %.o: %.cc
113: $(COMPILE.cc) $< $(OUTPUT_OPTION)
114:
115: %.s: %.cc
116: $(CXX) $(TARGET_ARCH) $(CXXFLAGS) $(CPPFLAGS) -S $<
117:
118: %.i: %.cc
119: $(CXX) $(TARGET_ARCH) $(CXXFLAGS) $(CPPFLAGS) -E $< $(OUTPUT_OPTION)
120:
121: ### asm ###
122: AS = $(GNUARM_2)/bin/as
123: ifeq ($(mode), debug)
124: ASFLAGS += -g
125: else
126: ASFLAGS +=
127: endif
128:
129: ASFLAGS += $(_CPUTYPE_FLAGS) $(_CODESET_FLAGS)
130: ASFLAGS.s = $(_CPUTYPE_FLAGS_AS) $(_CODESET_FLAGS)
131:
132: COMPILE.S = $(CC) $(TARGET_ARCH) $(ASFLAGS) $(CPPFLAGS) -c
133: COMPILE.s = $(AS) $(ASFLAGS.s)
134:
135: %.o: %.S
136: $(COMPILE.S) $< $(OUTPUT_OPTION)
137:
138: %.o: %.s
139: $(COMPILE.s) $< $(OUTPUT_OPTION)
140:
141: %.i: %.S
142: $(CC) $(TARGET_ARCH) $(ASFLAGS) $(CPPFLAGS) -E $< $(OUTPUT_OPTION)
143:
144: ### linker ###
145: LD = $(GNUARM_2)/bin/ld
146: ifeq ($(mode), debug)
147: LDFLAGS += $(LIBDIR:%=-L%)
148: else
149: LDFLAGS += $(LIBDIR:%=-L%)
150: endif
151:
152: LDFLAGS += $(_CPUTYPE_FLAGS) $(_CODESET_FLAGS)
153:
154: LIBDIR = $(COMMONLIB)
155: LOADLIBES =
156: LDOBJS =
157: LDLIBS =
158:
159: # additional linker option
160: ifneq ($(filter sl, $(options)), )
161: LDFLAGS2 = -static
162: else
163: # no effect
164: LDFLAGS2 = -static
165: endif
166: LDFLAGS3 = -static -T $(COMMONLIB)/static.lnk
167: START_ADR =
168:
169: # create executable
170: LINK.o = $(CC) $(TARGET_ARCH) $(LDFLAGS) $(LDFLAGS2) $(START_ADR)
171:
172: # link objects
173: LINK_R.o = $(CC) $(TARGET_ARCH) $(LDFLAGS) -r -nostdlib
174:
175: # link objects and libraries
176: LINK_A.o = $(CC) $(TARGET_ARCH) $(LDFLAGS) -r
177:
178: # create executable (location only)
179: LOCATE.o = $(CC) $(TARGET_ARCH) $(LDFLAGS) -nostdlib $(LDFLAGS3) $(START_ADR)
180:
181: %: %.o
182: $(LINK.o) $(LDOBJS) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
183:
184: %.out: %.o
185: $(LINK.o) $(LDOBJS) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
186:
187: %.abs: %.o
188: $(LINK_A.o) $(LDOBJS) $^ $(LOADLIBES) $(LDLIBS) -o _$@
189: $(LOCATE.o) _$@ $(OUTPUT_OPTION)
190: $(RM) _$@
191:
192: ### library ###
193: AR = $(GNUARM_2)/bin/ar
194: ARFLAGS = rv
195: RANLIB = $(GNUARM_2)/bin/ranlib
196:
197: (%): %
198: $(AR) $(ARFLAGS) $@ $%
199:
200: ### create name list ###
201: NM = $(GNUARM_2)/bin/nm
202: NMFLAGS = -n
203:
204: %.map: %
205: $(NM) $(NMFLAGS) $< > $@
206:
207: %.map: %.out
208: $(NM) $(NMFLAGS) $< > $@
209:
210: %.map: %.abs
211: $(NM) $(NMFLAGS) $< > $@
212:
213: %.map: %.dll
214: $(NM) $(NMFLAGS) $< > $@
215:
216: ### data box ###
217: DBCPPFLAGS = -D$(_TE_SYSTEM_NAME_)
218: DB_CPP = $(CPP) -nostdinc -traditional -P $(DATABOX_HEADER:%=-I%) $(DBCPPFLAGS)
219: DB = $(ETCBIN)/databox
220: DBFLAGS =
221: DBSRCFLAGS = -s
222: DATABOX = $(DB) $(DBFLAGS)
223:
224: %.dbx: %.d
225: $(DB_CPP) $< $@.tmp
226: $(DATABOX) $@.tmp $@
227: $(RM) $@.tmp
228:
229: %.fsn: %.f
230: $(DB_CPP) $< $@.tmp
231: $(DATABOX) -n $@.tmp $@
232: $(RM) $@.tmp
233:
234: %.c: %.d
235: $(DB_CPP) $< $@.tmp
236: $(DATABOX) -n $(DBSRCFLAGS) $@.tmp $@
237: $(RM) $@.tmp
238:
239: ### other ###
240: ifndef CPP
241: CPP = $(GNU_BD)/bin/arm_2-unknown-tkernel-cpp
242: endif
243: STRIP = $(GNUARM_2)/bin/strip --strip-unneeded
244:
245: OBJCOPY = $(GNU_BD)/bin/arm_2-unknown-tkernel-objcopy
246: OUTPUT_SREC = -O srec --srec-forceS3 --srec-len 32