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