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