1# our default target 2.PHONY: all 3all: 4 5include $(srctree)/scripts/Kbuild.include 6include $(TOPDIR)/config.mk 7 8# variable LIB is used in examples/standalone/Makefile 9__LIB := $(obj)built-in.o 10LIBGCC = $(obj)libgcc.o 11SRCS := 12subdir-y := 13obj-dirs := 14 15include Makefile 16 17# Do not include host rules unless needed 18ifneq ($(hostprogs-y)$(hostprogs-m),) 19include $(SRCTREE)/scripts/Makefile.host.tmp 20endif 21 22# Going forward use the following 23obj-y := $(sort $(obj-y)) 24extra-y := $(sort $(extra-y)) 25always := $(sort $(always)) 26lib-y := $(sort $(lib-y)) 27 28subdir-y += $(patsubst %/,%,$(filter %/, $(obj-y))) 29obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) 30subdir-obj-y := $(filter %/built-in.o, $(obj-y)) 31subdir-obj-y := $(addprefix $(obj),$(subdir-obj-y)) 32 33SRCS += $(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)) 35OBJS := $(addprefix $(obj),$(obj-y)) 36 37# $(obj-dirs) is a list of directories that contain object files 38 39obj-dirs += $(dir $(OBJS)) 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 45LGOBJS := $(addprefix $(obj),$(sort $(lib-y))) 46 47all: $(__LIB) $(addprefix $(obj),$(extra-y) $(always)) $(subdir-y) 48 49$(__LIB): $(obj).depend $(OBJS) 50 $(call cmd_link_o_target, $(OBJS)) 51 52ifneq ($(strip $(lib-y)),) 53all: $(LIBGCC) 54 55$(LIBGCC): $(obj).depend $(LGOBJS) 56 $(call cmd_link_o_target, $(LGOBJS)) 57endif 58 59ifneq ($(subdir-obj-y),) 60# Descending 61$(subdir-obj-y): $(subdir-y) 62endif 63 64ifneq ($(subdir-y),) 65$(subdir-y): FORCE 66 $(MAKE) -C $@ -f $(TOPDIR)/scripts/Makefile.build 67endif 68 69######################################################################### 70 71# Allow boards to use custom optimize flags on a per dir/file basis 72ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR)) 73ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) 74EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR)) 75ALL_CFLAGS += $(EXTRA_CPPFLAGS) 76 77# The _DEP version uses the $< file target (for dependency generation) 78# See rules.mk 79EXTRA_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 86ifneq ($(CHECKSRC),0) 87 $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $< 88endif 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 96cmd_link_o_target = $(if $(strip $1),\ 97 $(LD) $(LDFLAGS) -r -o $@ $1,\ 98 rm -f $@; $(AR) rcs $@ ) 99 100######################################################################### 101 102# defines $(obj).depend target 103 104include $(TOPDIR)/rules.mk 105 106sinclude $(obj).depend 107 108######################################################################### 109 110.PHONY: FORCE 111