Skip to content

Commit d984fed

Browse files
Scott Woodwdenx
Scott Wood
authored andcommitted
makefiles: fixes for building build tools
Currently, some of the tools instead set CC to be HOSTCC in order to re-use some pattern rules -- but this fails when the user overrides CC on the make command line. Also, the HOSTCFLAGS in tools/Makefile are currently not being used because config.mk overwrites them. This patch adds static pattern rules for files that have been requested to be built with the native compiler using $(HOSTSRCS) and $(HOSTOBJS), and converts the tools to use them. It restores easylogo to using the host compiler, which was broken by commit 38d299c (if this was an intentional change, please let me know -- but it seems to be a build tool). It restores -pedantic and the special flags for darwin and cygwin that were requested in tools/makefile (but keeps the flags added by config.mk) -- hopefully someone can test this on those platforms. It no longer conditionalizes -pedantic on not being darwin; it wasn't clear that that was intentional, and unless there's a real problem it's just inviting people to contribute non-pedantic patches to those files (I'm not a fan of -pedantic personally, but if it's on for one platform it should be on for all). HOST_LDFLAGS is renamed HOSTLDFLAGS for consistency with the previous HOST_CFLAGS to HOSTCFLAGS rename. A new HOSTCFLAGS_NOPED is made available for those files which currently cannot be built with -pedantic, and replaces the old FIT_CFLAGS. imls now uses the cross compiler properly, rather than by trying to reconstruct CC using the typoed $(CROSS_COMPILER). envcrc.c is now dependency-processed unconditionally -- previously it would be built without being on (HOST)SRCS if CONFIG_ENV_IS_EMBEDDED was not selected. Signed-off-by: Scott Wood <scottwood@freescale.com>
1 parent bf44f3f commit d984fed

File tree

6 files changed

+98
-123
lines changed

6 files changed

+98
-123
lines changed

config.mk

+31-3
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,41 @@ PLATFORM_LDFLAGS =
4646

4747
#########################################################################
4848

49+
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
50+
$(HOSTCPPFLAGS)
51+
HOSTSTRIP = strip
52+
53+
#
54+
# Mac OS X / Darwin's C preprocessor is Apple specific. It
55+
# generates numerous errors and warnings. We want to bypass it
56+
# and use GNU C's cpp. To do this we pass the -traditional-cpp
57+
# option to the compiler. Note that the -traditional-cpp flag
58+
# DOES NOT have the same semantics as GNU C's flag, all it does
59+
# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
60+
#
61+
# Apple's linker is similar, thanks to the new 2 stage linking
62+
# multiple symbol definitions are treated as errors, hence the
63+
# -multiply_defined suppress option to turn off this error.
64+
#
65+
4966
ifeq ($(HOSTOS),darwin)
5067
HOSTCC = cc
68+
HOSTCFLAGS += -traditional-cpp
69+
HOSTLDFLAGS += -multiply_defined suppress
5170
else
5271
HOSTCC = gcc
5372
endif
54-
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
55-
HOSTSTRIP = strip
73+
74+
ifeq ($(HOSTOS),cygwin)
75+
HOSTCFLAGS += -ansi
76+
endif
77+
78+
# We build some files with extra pedantic flags to try to minimize things
79+
# that won't build on some weird host compiler -- though there are lots of
80+
# exceptions for files that aren't complaint.
81+
82+
HOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS))
83+
HOSTCFLAGS += -pedantic
5684

5785
#########################################################################
5886
#
@@ -200,7 +228,7 @@ endif
200228

201229
#########################################################################
202230

203-
export HOSTCC HOSTCFLAGS CROSS_COMPILE \
231+
export HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
204232
AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
205233
export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
206234

rules.mk

+11-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@
2525

2626
_depend: $(obj).depend
2727

28-
$(obj).depend: $(src)Makefile $(TOPDIR)/config.mk $(SRCS)
28+
$(obj).depend: $(src)Makefile $(TOPDIR)/config.mk $(SRCS) $(HOSTSRCS)
2929
@rm -f $@
3030
@for f in $(SRCS); do \
3131
g=`basename $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \
32-
$(CC) -M $(HOSTCFLAGS) $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \
32+
$(CC) -M $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \
3333
done
34+
@for f in $(HOSTSRCS); do \
35+
g=`basename $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \
36+
$(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \
37+
done
38+
39+
$(HOSTOBJS): $(obj)%.o: %.c
40+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c
41+
$(NOPEDOBJS): $(obj)%.o: %.c
42+
$(HOSTCC) $(HOSTCFLAGS_NOPED) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c
3443

3544
#########################################################################

tools/Makefile

+34-87
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,6 @@
2323

2424
TOOLSUBDIRS =
2525

26-
#
27-
# Mac OS X / Darwin's C preprocessor is Apple specific. It
28-
# generates numerous errors and warnings. We want to bypass it
29-
# and use GNU C's cpp. To do this we pass the -traditional-cpp
30-
# option to the compiler. Note that the -traditional-cpp flag
31-
# DOES NOT have the same semantics as GNU C's flag, all it does
32-
# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
33-
#
34-
# Apple's linker is similar, thanks to the new 2 stage linking
35-
# multiple symbol definitions are treated as errors, hence the
36-
# -multiply_defined suppress option to turn off this error.
37-
#
38-
39-
HOSTCFLAGS = -Wall
40-
HOST_LDFLAGS =
41-
42-
ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
43-
HOSTCFLAGS += -traditional-cpp
44-
HOST_LDFLAGS += -multiply_defined suppress
45-
else
46-
HOSTCFLAGS += -pedantic
47-
endif
48-
49-
ifeq ($(HOSTOS),cygwin)
50-
HOSTCFLAGS += -ansi
51-
endif
52-
5326
#
5427
# toolchains targeting win32 generate .exe files
5528
#
@@ -93,16 +66,16 @@ EXT_OBJ_FILES-y += lib_generic/sha1.o
9366
# Source files located in the tools directory
9467
OBJ_FILES-$(CONFIG_LCD_LOGO) += bmp_logo.o
9568
OBJ_FILES-$(CONFIG_VIDEO_LOGO) += bmp_logo.o
96-
OBJ_FILES-y += default_image.o
97-
OBJ_FILES-$(CONFIG_ENV_IS_EMBEDDED) += envcrc.o
98-
OBJ_FILES-y += fit_image.o
69+
NOPED_OBJ_FILES-y += default_image.o
70+
OBJ_FILES-y += envcrc.o
71+
NOPED_OBJ_FILES-y += fit_image.o
9972
OBJ_FILES-$(CONFIG_CMD_NET) += gen_eth_addr.o
10073
OBJ_FILES-$(CONFIG_CMD_LOADS) += img2srec.o
10174
OBJ_FILES-$(CONFIG_INCA_IP) += inca-swap-bytes.o
102-
OBJ_FILES-y += kwbimage.o
103-
OBJ_FILES-y += mkimage.o
75+
NOPED_OBJ_FILES-y += kwbimage.o
76+
NOPED_OBJ_FILES-y += mkimage.o
10477
OBJ_FILES-$(CONFIG_NETCONSOLE) += ncb.o
105-
OBJ_FILES-y += os_support.o
78+
NOPED_OBJ_FILES-y += os_support.o
10679
OBJ_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1.o
10780

10881
# Don't build by default
@@ -134,57 +107,52 @@ LOGO_BMP= logos/ronetix.bmp
134107
endif
135108

136109
# now $(obj) is defined
137-
SRCS += $(addprefix $(SRCTREE)/,$(EXT_OBJ_FILES-y:.o=.c))
138-
SRCS += $(addprefix $(SRCTREE)/tools/,$(OBJ_FILES-y:.o=.c))
139-
SRCS += $(addprefix $(SRCTREE)/libfdt/,$(LIBFDT_OBJ_FILES-y:.o=.c))
110+
HOSTSRCS += $(addprefix $(SRCTREE)/,$(EXT_OBJ_FILES-y:.o=.c))
111+
HOSTSRCS += $(addprefix $(SRCTREE)/tools/,$(OBJ_FILES-y:.o=.c))
112+
HOSTSRCS += $(addprefix $(SRCTREE)/libfdt/,$(LIBFDT_OBJ_FILES-y:.o=.c))
140113
BINS := $(addprefix $(obj),$(sort $(BIN_FILES-y)))
141114
LIBFDT_OBJS := $(addprefix $(obj),$(LIBFDT_OBJ_FILES-y))
142115

116+
HOSTOBJS := $(addprefix $(obj),$(OBJ_FILES-y))
117+
NOPEDOBJS := $(addprefix $(obj),$(NOPED_OBJ_FILES-y))
118+
143119
#
144120
# Use native tools and options
145121
# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
146122
#
147-
CPPFLAGS = -idirafter $(SRCTREE)/include \
123+
HOSTCPPFLAGS = -idirafter $(SRCTREE)/include \
148124
-idirafter $(OBJTREE)/include2 \
149125
-idirafter $(OBJTREE)/include \
150126
-I $(SRCTREE)/libfdt \
151127
-I $(SRCTREE)/tools \
152128
-DTEXT_BASE=$(TEXT_BASE) -DUSE_HOSTCC \
153129
-D__KERNEL_STRICT_NAMES
154-
CFLAGS = $(HOSTCFLAGS) $(CPPFLAGS) -O
155-
156-
# No -pedantic switch to avoid libfdt compilation warnings
157-
FIT_CFLAGS = -Wall $(CPPFLAGS) -O
158130

159-
AFLAGS = -D__ASSEMBLY__ $(CPPFLAGS)
160-
CC = $(HOSTCC)
161-
STRIP = $(HOSTSTRIP)
162-
MAKEDEPEND = makedepend
163131

164132
all: $(obj).depend $(BINS) $(LOGO-y) subdirs
165133

166134
$(obj)bin2header$(SFX): $(obj)bin2header.o
167-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
168-
$(STRIP) $@
135+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
136+
$(HOSTSTRIP) $@
169137

170138
$(obj)bmp_logo$(SFX): $(obj)bmp_logo.o
171-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
172-
$(STRIP) $@
139+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
140+
$(HOSTSTRIP) $@
173141

174142
$(obj)envcrc$(SFX): $(obj)crc32.o $(obj)env_embedded.o $(obj)envcrc.o $(obj)sha1.o
175-
$(CC) $(CFLAGS) -o $@ $^
143+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
176144

177145
$(obj)gen_eth_addr$(SFX): $(obj)gen_eth_addr.o
178-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
179-
$(STRIP) $@
146+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
147+
$(HOSTSTRIP) $@
180148

181149
$(obj)img2srec$(SFX): $(obj)img2srec.o
182-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
183-
$(STRIP) $@
150+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
151+
$(HOSTSTRIP) $@
184152

185153
$(obj)inca-swap-bytes$(SFX): $(obj)inca-swap-bytes.o
186-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
187-
$(STRIP) $@
154+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
155+
$(HOSTSTRIP) $@
188156

189157
$(obj)mkimage$(SFX): $(obj)crc32.o \
190158
$(obj)default_image.o \
@@ -196,48 +164,29 @@ $(obj)mkimage$(SFX): $(obj)crc32.o \
196164
$(obj)os_support.o \
197165
$(obj)sha1.o \
198166
$(LIBFDT_OBJS)
199-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
200-
$(STRIP) $@
167+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
168+
$(HOSTSTRIP) $@
201169

202170
$(obj)mpc86x_clk$(SFX): $(obj)mpc86x_clk.o
203-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
204-
$(STRIP) $@
171+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
172+
$(HOSTSTRIP) $@
205173

206174
$(obj)ncb$(SFX): $(obj)ncb.o
207-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
208-
$(STRIP) $@
175+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
176+
$(HOSTSTRIP) $@
209177

210178
$(obj)ubsha1$(SFX): $(obj)os_support.o $(obj)sha1.o $(obj)ubsha1.o
211-
$(CC) $(CFLAGS) -o $@ $^
212-
213-
# Some files complain if compiled with -pedantic, use FIT_CFLAGS
214-
$(obj)default_image.o: $(SRCTREE)/tools/default_image.c
215-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
216-
217-
$(obj)fit_image.o: $(SRCTREE)/tools/fit_image.c
218-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
219-
220-
$(obj)image.o: $(SRCTREE)/common/image.c
221-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
222-
223-
$(obj)kwbimage.o: $(SRCTREE)/tools/kwbimage.c
224-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
225-
226-
$(obj)mkimage.o: $(SRCTREE)/tools/mkimage.c
227-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
228-
229-
$(obj)os_support.o: $(SRCTREE)/tools/os_support.c
230-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
179+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
231180

232181
# Some of the tool objects need to be accessed from outside the tools directory
233182
$(obj)%.o: $(SRCTREE)/common/%.c
234-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
183+
$(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
235184

236185
$(obj)%.o: $(SRCTREE)/lib_generic/%.c
237-
$(CC) -g $(CFLAGS) -c -o $@ $<
186+
$(HOSTCC) -g $(HOSTCFLAGS) -c -o $@ $<
238187

239188
$(LIBFDT_OBJS):
240-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
189+
$(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
241190

242191
subdirs:
243192
ifeq ($(TOOLSUBDIRS),)
@@ -247,8 +196,6 @@ else
247196
$(MAKE) \
248197
HOSTOS=$(HOSTOS) \
249198
HOSTARCH=$(HOSTARCH) \
250-
HOSTCFLAGS="$(HOSTCFLAGS)" \
251-
HOST_LDFLAGS="$(HOST_LDFLAGS)" \
252199
-C $$dir || exit 1 ; \
253200
done
254201
endif

tools/easylogo/Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
CFLAGS += -Wall
1+
include $(TOPDIR)/config.mk
22

3-
all: easylogo
3+
all: $(obj)easylogo
4+
5+
$(obj)easylogo: $(SRCTREE)/tools/easylogo/easylogo.c
6+
$(HOSTCC) $(HOSTCFLAGS_NOPED) $(HOSTLDFLAGS) -o $@ $^
47

58
clean:
6-
rm -f easylogo *.o
9+
rm -f $(obj)easylogo
710

811
.PHONY: all clean

tools/gdb/Makefile

+6-9
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,14 @@ BINS = gdbsend gdbcont
3030

3131
COBJS = gdbsend.o gdbcont.o error.o remote.o serial.o
3232

33-
OBJS := $(addprefix $(obj),$(COBJS))
34-
SRCS := $(COBJS:.o=.c)
33+
HOSTOBJS := $(addprefix $(obj),$(COBJS))
34+
HOSTSRCS := $(COBJS:.o=.c)
3535
BINS := $(addprefix $(obj),$(BINS))
3636

3737
#
3838
# Use native tools and options
3939
#
40-
CPPFLAGS = -I$(BFD_ROOT_DIR)/include
41-
CFLAGS = $(HOSTCFLAGS) -O $(CPPFLAGS)
42-
CC = $(HOSTCC)
43-
MAKEDEPEND = makedepend
40+
HOSTCPPFLAGS = -I$(BFD_ROOT_DIR)/include
4441

4542
HOSTOS := $(shell uname -s | sed -e 's/\([Cc][Yy][Gg][Ww][Ii][Nn]\).*/cygwin/')
4643

@@ -54,13 +51,13 @@ else # ! CYGWIN
5451
all: $(obj).depend $(BINS)
5552

5653
$(obj)gdbsend: $(obj)gdbsend.o $(obj)error.o $(obj)remote.o $(obj)serial.o
57-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
54+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
5855

5956
$(obj)gdbcont: $(obj)gdbcont.o $(obj)error.o $(obj)remote.o $(obj)serial.o
60-
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
57+
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
6158

6259
clean:
63-
rm -f $(OBJS)
60+
rm -f $(HOSTOBJS)
6461

6562
distclean: clean
6663
rm -f $(BINS) $(obj)core $(obj)*.bak $(obj).depend

tools/imls/Makefile

+10-19
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
include $(TOPDIR)/config.mk
2121

22-
HOSTCFLAGS = -Wall -pedantic
23-
2422
# Generated executable files
2523
BIN_FILES-y += imls
2624

@@ -48,50 +46,43 @@ BINS := $(addprefix $(obj),$(sort $(BIN_FILES-y)))
4846
LIBFDT_OBJS := $(addprefix $(obj),$(LIBFDT_OBJ_FILES-y))
4947

5048
#
51-
# Use native tools and options
49+
# Compile for a hosted environment on the target
5250
# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
5351
#
54-
CPPFLAGS = -idirafter $(SRCTREE)/include \
52+
HOSTCPPFLAGS = -idirafter $(SRCTREE)/include \
5553
-idirafter $(OBJTREE)/include2 \
5654
-idirafter $(OBJTREE)/include \
5755
-I $(SRCTREE)/libfdt \
5856
-I $(SRCTREE)/tools \
5957
-DUSE_HOSTCC -D__KERNEL_STRICT_NAMES
60-
CFLAGS = $(HOSTCFLAGS) $(CPPFLAGS) -O
61-
62-
# No -pedantic switch to avoid libfdt compilation warnings
63-
FIT_CFLAGS = -Wall $(CPPFLAGS) -O
64-
65-
CC = $(CROSS_COMPILER)gcc
66-
STRIP = $(CROSS_COMPILER)strip
6758

6859
ifeq ($(MTD_VERSION),old)
69-
CPPFLAGS += -DMTD_OLD
60+
HOSTCPPFLAGS += -DMTD_OLD
7061
endif
7162

7263
all: $(BINS)
7364

7465
$(obj)imls: $(obj)imls.o $(obj)crc32.o $(obj)image.o $(obj)md5.o \
7566
$(obj)sha1.o $(LIBFDT_OBJS)
76-
$(CC) $(CFLAGS) -o $@ $^
67+
$(CC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
7768
$(STRIP) $@
7869

7970
# Some files complain if compiled with -pedantic, use FIT_CFLAGS
8071
$(obj)image.o: $(SRCTREE)/common/image.c
81-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
72+
$(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
8273

83-
$(obj)imls.o: imls.c
84-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
74+
$(obj)imls.o: $(SRCTREE)/tools/imls/imls.c
75+
$(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
8576

8677
# Some of the tool objects need to be accessed from outside the tools/imls directory
8778
$(obj)%.o: $(SRCTREE)/common/%.c
88-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
79+
$(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
8980

9081
$(obj)%.o: $(SRCTREE)/lib_generic/%.c
91-
$(CC) -g $(CFLAGS) -c -o $@ $<
82+
$(CC) -g $(HOSTCFLAGS) -c -o $@ $<
9283

9384
$(obj)%.o: $(SRCTREE)/libfdt/%.c
94-
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
85+
$(CC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
9586

9687
clean:
9788
rm -rf *.o imls

0 commit comments

Comments
 (0)