Commit ad71fa9971aeb0340221f82884b7794c497322be
Committed by
Tom Rini
1 parent
ea531e3afd
Exists in
master
and in
49 other branches
Makefile.host.tmp: add a new script to refactor tools
This commit adds scripts/Makefile.host.tmp which will be used in the next commit to convert makefiles under tools/ directory to Kbuild style. Notice this script, scripts/Makefile.host.tmp is temporary. When switching over to real Kbuild, it will be replaced with scripts/Makefile.host of Linux Kernel. Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Showing 2 changed files with 75 additions and 3 deletions Side-by-side Diff
scripts/Makefile.build
... | ... | @@ -7,15 +7,23 @@ |
7 | 7 | LIB := $(obj)built-in.o |
8 | 8 | LIBGCC = $(obj)libgcc.o |
9 | 9 | SRCS := |
10 | +subdir-y := | |
11 | +obj-dirs := | |
10 | 12 | |
11 | 13 | include Makefile |
12 | 14 | |
15 | +# Do not include host rules unless needed | |
16 | +ifneq ($(hostprogs-y)$(hostprogs-m),) | |
17 | +include $(SRCTREE)/scripts/Makefile.host.tmp | |
18 | +endif | |
19 | + | |
13 | 20 | # Going forward use the following |
14 | 21 | obj-y := $(sort $(obj-y)) |
15 | 22 | extra-y := $(sort $(extra-y)) |
23 | +always := $(sort $(always)) | |
16 | 24 | lib-y := $(sort $(lib-y)) |
17 | 25 | |
18 | -subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) | |
26 | +subdir-y += $(patsubst %/,%,$(filter %/, $(obj-y))) | |
19 | 27 | obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) |
20 | 28 | subdir-obj-y := $(filter %/built-in.o, $(obj-y)) |
21 | 29 | subdir-obj-y := $(addprefix $(obj),$(subdir-obj-y)) |
22 | 30 | |
23 | 31 | |
... | ... | @@ -25,15 +33,16 @@ |
25 | 33 | OBJS := $(addprefix $(obj),$(obj-y)) |
26 | 34 | |
27 | 35 | # $(obj-dirs) is a list of directories that contain object files |
28 | -obj-dirs := $(dir $(OBJS)) | |
29 | 36 | |
37 | +obj-dirs += $(dir $(OBJS)) | |
38 | + | |
30 | 39 | # Create directories for object files if directory does not exist |
31 | 40 | # Needed when obj-y := dir/file.o syntax is used |
32 | 41 | _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) |
33 | 42 | |
34 | 43 | LGOBJS := $(addprefix $(obj),$(sort $(lib-y))) |
35 | 44 | |
36 | -all: $(LIB) $(addprefix $(obj),$(extra-y)) | |
45 | +all: $(LIB) $(addprefix $(obj),$(extra-y) $(always)) $(subdir-y) | |
37 | 46 | |
38 | 47 | $(LIB): $(obj).depend $(OBJS) |
39 | 48 | $(call cmd_link_o_target, $(OBJS)) |
40 | 49 | |
... | ... | @@ -48,7 +57,9 @@ |
48 | 57 | ifneq ($(subdir-obj-y),) |
49 | 58 | # Descending |
50 | 59 | $(subdir-obj-y): $(subdir-y) |
60 | +endif | |
51 | 61 | |
62 | +ifneq ($(subdir-y),) | |
52 | 63 | $(subdir-y): FORCE |
53 | 64 | $(MAKE) -C $@ -f $(TOPDIR)/scripts/Makefile.build |
54 | 65 | endif |
scripts/Makefile.host.tmp
1 | + | |
2 | +__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) | |
3 | + | |
4 | +# C code | |
5 | +# Executables compiled from a single .c file | |
6 | +host-csingle := $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m))) | |
7 | + | |
8 | +# C executables linked based on several .o files | |
9 | +host-cmulti := $(foreach m,$(__hostprogs),$(if $($(m)-objs),$(m))) | |
10 | + | |
11 | +# Object (.o) files compiled from .c files | |
12 | +host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs))) | |
13 | + | |
14 | +# output directory for programs/.o files | |
15 | +# hostprogs-y := tools/build may have been specified. Retrieve directory | |
16 | +host-objdirs := $(foreach f,$(__hostprogs), $(if $(dir $(f)),$(dir $(f)))) | |
17 | +# directory of .o files from prog-objs notation | |
18 | +host-objdirs += $(foreach f,$(host-cmulti), \ | |
19 | + $(foreach m,$($(f)-objs), \ | |
20 | + $(if $(dir $(m)),$(dir $(m))))) | |
21 | + | |
22 | +host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs)))) | |
23 | + | |
24 | +__hostprogs := $(addprefix $(obj),$(__hostprogs)) | |
25 | +host-csingle := $(addprefix $(obj),$(host-csingle)) | |
26 | +host-cmulti := $(addprefix $(obj),$(host-cmulti)) | |
27 | +host-cobjs := $(addprefix $(obj),$(host-cobjs)) | |
28 | +host-objdirs := $(addprefix $(obj),$(host-objdirs)) | |
29 | + | |
30 | +obj-dirs += $(host-objdirs) | |
31 | + | |
32 | +##### | |
33 | +# Handle options to gcc. Support building with separate output directory | |
34 | + | |
35 | +_hostc_flags = $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ | |
36 | + $(HOSTCFLAGS_$(basetarget).o) | |
37 | + | |
38 | +# Find all -I options and call addtree | |
39 | +flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) | |
40 | + | |
41 | +ifeq ($(OBJTREE),$(SRCTREE)) | |
42 | +__hostc_flags = $(_hostc_flags) | |
43 | +else | |
44 | +__hostc_flags = -I$(obj) $(call flags,_hostc_flags) | |
45 | +endif | |
46 | + | |
47 | +hostc_flags = $(__hostc_flags) | |
48 | + | |
49 | +##### | |
50 | +# Compile programs on the host | |
51 | + | |
52 | +$(host-csingle): $(obj)%: %.c | |
53 | + $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(HOSTLDFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< | |
54 | + | |
55 | +$(host-cmulti): $(obj)%: $(host-cobjs) | |
56 | + $(HOSTCC) $(HOSTLDFLAGS) -o $@ $(addprefix $(obj),$($(@F)-objs)) $(HOSTLOADLIBES_$(@F)) | |
57 | + | |
58 | +$(host-cobjs): $(obj)%.o: %.c | |
59 | + $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c | |
60 | + | |
61 | +targets += $(host-csingle) $(host-cmulti) $(host-cobjs) |