Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 1 | # our default target |
| 2 | .PHONY: all |
| 3 | all: |
| 4 | |
Masahiro Yamada | bf4b3de | 2014-02-04 17:24:18 +0900 | [diff] [blame] | 5 | include $(srctree)/scripts/Kbuild.include |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 6 | include $(TOPDIR)/config.mk |
| 7 | |
Masahiro Yamada | 4a20df3 | 2014-02-04 17:24:12 +0900 | [diff] [blame] | 8 | # variable LIB is used in examples/standalone/Makefile |
| 9 | __LIB := $(obj)built-in.o |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 10 | LIBGCC = $(obj)libgcc.o |
| 11 | SRCS := |
Masahiro Yamada | ad71fa9 | 2014-02-04 17:24:09 +0900 | [diff] [blame] | 12 | subdir-y := |
| 13 | obj-dirs := |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 14 | |
| 15 | include Makefile |
| 16 | |
Masahiro Yamada | ad71fa9 | 2014-02-04 17:24:09 +0900 | [diff] [blame] | 17 | # Do not include host rules unless needed |
| 18 | ifneq ($(hostprogs-y)$(hostprogs-m),) |
| 19 | include $(SRCTREE)/scripts/Makefile.host.tmp |
| 20 | endif |
| 21 | |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 22 | # Going forward use the following |
| 23 | obj-y := $(sort $(obj-y)) |
| 24 | extra-y := $(sort $(extra-y)) |
Masahiro Yamada | ad71fa9 | 2014-02-04 17:24:09 +0900 | [diff] [blame] | 25 | always := $(sort $(always)) |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 26 | lib-y := $(sort $(lib-y)) |
| 27 | |
Masahiro Yamada | ad71fa9 | 2014-02-04 17:24:09 +0900 | [diff] [blame] | 28 | subdir-y += $(patsubst %/,%,$(filter %/, $(obj-y))) |
Masahiro Yamada | ac7e735 | 2013-10-17 20:38:51 +0900 | [diff] [blame] | 29 | obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) |
| 30 | subdir-obj-y := $(filter %/built-in.o, $(obj-y)) |
| 31 | subdir-obj-y := $(addprefix $(obj),$(subdir-obj-y)) |
| 32 | |
Masahiro Yamada | 3fdf5c8 | 2013-11-11 14:35:49 +0900 | [diff] [blame] | 33 | SRCS += $(wildcard $(obj-y:.o=.c) $(obj-y:.o=.S) $(lib-y:.o=.c) \ |
| 34 | $(lib-y:.o=.S) $(extra-y:.o=.c) $(extra-y:.o=.S)) |
| 35 | OBJS := $(addprefix $(obj),$(obj-y)) |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 36 | |
Masahiro Yamada | e5c5301 | 2013-11-11 14:35:54 +0900 | [diff] [blame] | 37 | # $(obj-dirs) is a list of directories that contain object files |
Masahiro Yamada | ad71fa9 | 2014-02-04 17:24:09 +0900 | [diff] [blame] | 38 | |
| 39 | obj-dirs += $(dir $(OBJS)) |
Masahiro Yamada | e5c5301 | 2013-11-11 14:35:54 +0900 | [diff] [blame] | 40 | |
| 41 | # Create directories for object files if directory does not exist |
| 42 | # Needed when obj-y := dir/file.o syntax is used |
| 43 | _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) |
| 44 | |
Masahiro Yamada | 3fdf5c8 | 2013-11-11 14:35:49 +0900 | [diff] [blame] | 45 | LGOBJS := $(addprefix $(obj),$(sort $(lib-y))) |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 46 | |
Masahiro Yamada | 4a20df3 | 2014-02-04 17:24:12 +0900 | [diff] [blame] | 47 | all: $(__LIB) $(addprefix $(obj),$(extra-y) $(always)) $(subdir-y) |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 48 | |
Masahiro Yamada | 4a20df3 | 2014-02-04 17:24:12 +0900 | [diff] [blame] | 49 | $(__LIB): $(obj).depend $(OBJS) |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 50 | $(call cmd_link_o_target, $(OBJS)) |
| 51 | |
| 52 | ifneq ($(strip $(lib-y)),) |
| 53 | all: $(LIBGCC) |
| 54 | |
| 55 | $(LIBGCC): $(obj).depend $(LGOBJS) |
| 56 | $(call cmd_link_o_target, $(LGOBJS)) |
| 57 | endif |
| 58 | |
Masahiro Yamada | ac7e735 | 2013-10-17 20:38:51 +0900 | [diff] [blame] | 59 | ifneq ($(subdir-obj-y),) |
| 60 | # Descending |
| 61 | $(subdir-obj-y): $(subdir-y) |
Masahiro Yamada | ad71fa9 | 2014-02-04 17:24:09 +0900 | [diff] [blame] | 62 | endif |
Masahiro Yamada | ac7e735 | 2013-10-17 20:38:51 +0900 | [diff] [blame] | 63 | |
Masahiro Yamada | ad71fa9 | 2014-02-04 17:24:09 +0900 | [diff] [blame] | 64 | ifneq ($(subdir-y),) |
Masahiro Yamada | ac7e735 | 2013-10-17 20:38:51 +0900 | [diff] [blame] | 65 | $(subdir-y): FORCE |
| 66 | $(MAKE) -C $@ -f $(TOPDIR)/scripts/Makefile.build |
| 67 | endif |
| 68 | |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 69 | ######################################################################### |
| 70 | |
Masahiro Yamada | 5651ccf | 2014-02-04 17:24:14 +0900 | [diff] [blame] | 71 | # Allow boards to use custom optimize flags on a per dir/file basis |
| 72 | ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR)) |
| 73 | ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) |
| 74 | EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR)) |
| 75 | ALL_CFLAGS += $(EXTRA_CPPFLAGS) |
| 76 | |
| 77 | # The _DEP version uses the $< file target (for dependency generation) |
| 78 | # See rules.mk |
| 79 | EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \ |
| 80 | $(CPPFLAGS_$(BCURDIR)) |
| 81 | $(obj)%.s: %.S |
| 82 | $(CPP) $(ALL_AFLAGS) -o $@ $< |
| 83 | $(obj)%.o: %.S |
| 84 | $(CC) $(ALL_AFLAGS) -o $@ $< -c |
| 85 | $(obj)%.o: %.c |
| 86 | ifneq ($(CHECKSRC),0) |
| 87 | $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $< |
| 88 | endif |
| 89 | $(CC) $(ALL_CFLAGS) -o $@ $< -c |
| 90 | $(obj)%.i: %.c |
| 91 | $(CPP) $(ALL_CFLAGS) -o $@ $< -c |
| 92 | $(obj)%.s: %.c |
| 93 | $(CC) $(ALL_CFLAGS) -o $@ $< -c -S |
| 94 | |
| 95 | # If the list of objects to link is empty, just create an empty built-in.o |
| 96 | cmd_link_o_target = $(if $(strip $1),\ |
| 97 | $(LD) $(LDFLAGS) -r -o $@ $1,\ |
| 98 | rm -f $@; $(AR) rcs $@ ) |
| 99 | |
| 100 | ######################################################################### |
| 101 | |
Masahiro Yamada | ce28d7a | 2013-10-17 17:34:47 +0900 | [diff] [blame] | 102 | # defines $(obj).depend target |
| 103 | |
| 104 | include $(TOPDIR)/rules.mk |
| 105 | |
| 106 | sinclude $(obj).depend |
| 107 | |
| 108 | ######################################################################### |
Masahiro Yamada | ac7e735 | 2013-10-17 20:38:51 +0900 | [diff] [blame] | 109 | |
| 110 | .PHONY: FORCE |