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 Inline Diff
scripts/Makefile.build
1 | # our default target | 1 | # our default target |
2 | .PHONY: all | 2 | .PHONY: all |
3 | all: | 3 | all: |
4 | 4 | ||
5 | include $(TOPDIR)/config.mk | 5 | include $(TOPDIR)/config.mk |
6 | 6 | ||
7 | LIB := $(obj)built-in.o | 7 | LIB := $(obj)built-in.o |
8 | LIBGCC = $(obj)libgcc.o | 8 | LIBGCC = $(obj)libgcc.o |
9 | SRCS := | 9 | SRCS := |
10 | subdir-y := | ||
11 | obj-dirs := | ||
10 | 12 | ||
11 | include Makefile | 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 | # Going forward use the following | 20 | # Going forward use the following |
14 | obj-y := $(sort $(obj-y)) | 21 | obj-y := $(sort $(obj-y)) |
15 | extra-y := $(sort $(extra-y)) | 22 | extra-y := $(sort $(extra-y)) |
23 | always := $(sort $(always)) | ||
16 | lib-y := $(sort $(lib-y)) | 24 | lib-y := $(sort $(lib-y)) |
17 | 25 | ||
18 | subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) | 26 | subdir-y += $(patsubst %/,%,$(filter %/, $(obj-y))) |
19 | obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) | 27 | obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) |
20 | subdir-obj-y := $(filter %/built-in.o, $(obj-y)) | 28 | subdir-obj-y := $(filter %/built-in.o, $(obj-y)) |
21 | subdir-obj-y := $(addprefix $(obj),$(subdir-obj-y)) | 29 | subdir-obj-y := $(addprefix $(obj),$(subdir-obj-y)) |
22 | 30 | ||
23 | SRCS += $(wildcard $(obj-y:.o=.c) $(obj-y:.o=.S) $(lib-y:.o=.c) \ | 31 | SRCS += $(wildcard $(obj-y:.o=.c) $(obj-y:.o=.S) $(lib-y:.o=.c) \ |
24 | $(lib-y:.o=.S) $(extra-y:.o=.c) $(extra-y:.o=.S)) | 32 | $(lib-y:.o=.S) $(extra-y:.o=.c) $(extra-y:.o=.S)) |
25 | OBJS := $(addprefix $(obj),$(obj-y)) | 33 | OBJS := $(addprefix $(obj),$(obj-y)) |
26 | 34 | ||
27 | # $(obj-dirs) is a list of directories that contain object files | 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 | # Create directories for object files if directory does not exist | 39 | # Create directories for object files if directory does not exist |
31 | # Needed when obj-y := dir/file.o syntax is used | 40 | # Needed when obj-y := dir/file.o syntax is used |
32 | _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) | 41 | _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) |
33 | 42 | ||
34 | LGOBJS := $(addprefix $(obj),$(sort $(lib-y))) | 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 | $(LIB): $(obj).depend $(OBJS) | 47 | $(LIB): $(obj).depend $(OBJS) |
39 | $(call cmd_link_o_target, $(OBJS)) | 48 | $(call cmd_link_o_target, $(OBJS)) |
40 | 49 | ||
41 | ifneq ($(strip $(lib-y)),) | 50 | ifneq ($(strip $(lib-y)),) |
42 | all: $(LIBGCC) | 51 | all: $(LIBGCC) |
43 | 52 | ||
44 | $(LIBGCC): $(obj).depend $(LGOBJS) | 53 | $(LIBGCC): $(obj).depend $(LGOBJS) |
45 | $(call cmd_link_o_target, $(LGOBJS)) | 54 | $(call cmd_link_o_target, $(LGOBJS)) |
46 | endif | 55 | endif |
47 | 56 | ||
48 | ifneq ($(subdir-obj-y),) | 57 | ifneq ($(subdir-obj-y),) |
49 | # Descending | 58 | # Descending |
50 | $(subdir-obj-y): $(subdir-y) | 59 | $(subdir-obj-y): $(subdir-y) |
60 | endif | ||
51 | 61 | ||
62 | ifneq ($(subdir-y),) | ||
52 | $(subdir-y): FORCE | 63 | $(subdir-y): FORCE |
53 | $(MAKE) -C $@ -f $(TOPDIR)/scripts/Makefile.build | 64 | $(MAKE) -C $@ -f $(TOPDIR)/scripts/Makefile.build |
54 | endif | 65 | endif |
55 | 66 | ||
56 | ######################################################################### | 67 | ######################################################################### |
57 | 68 | ||
58 | # defines $(obj).depend target | 69 | # defines $(obj).depend target |
59 | 70 | ||
60 | include $(TOPDIR)/rules.mk | 71 | include $(TOPDIR)/rules.mk |
61 | 72 | ||
62 | sinclude $(obj).depend | 73 | sinclude $(obj).depend |
63 | 74 | ||
64 | ######################################################################### | 75 | ######################################################################### |
65 | 76 | ||
66 | .PHONY: FORCE | 77 | .PHONY: FORCE |
scripts/Makefile.host.tmp
File was created | 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) | ||
62 |