编译时指定project,即包含project/$(PROJECT).mk。这个mk里指定了$(TARGET)。
接着会包含target/$(TARGET)/rules.mk。指定$(PLATFORM)。
接着会包含include platform/$(PLATFORM)/rules.mk。指定$(ARCH)和$(ARM_CPU)/$(CPU)和$(LINKER_SCRIPT)。
接着会包含include arch/$(ARCH)/rules.mk。定义了linker script的规则。
include project/$(PROJECT).mk
include target/$(TARGET)/rules.mk
include platform/$(PLATFORM)/rules.mk
include arch/$(ARCH)/rules.mk
include platform/rules.mk
include target/rules.mk
include kernel/rules.mk
include dev/rules.mk
include app/rules.mk
include project/$(PROJECT).mk
include target/$(TARGET)/rules.mk
include platform/$(PLATFORM)/rules.mk
include arch/$(ARCH)/rules.mk
include platform/rules.mk
include target/rules.mk
include kernel/rules.mk
include dev/rules.mk
include app/rules.mk
Example: make aboot-surf7k
Platform:msm7k
Target:aboot-surf7k
First
all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size
Extension
OUTBIN := $(BUILDDIR)/lk.bin
OUTELF := $(BUILDDIR)/lk
Next
$(OUTBIN): $(OUTELF)
Action
$(NOCOPY)$(OBJCOPY) -O binary $< $@
Extension
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
Next
$(OUTELF): $(ALLOBJS) $(LINKER_SCRIPT)
Action
$(NOECHO)$(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) $(ALLOBJS) $(LIBGCC) -o $@
Extension
LD := $(TOOLCHAIN_PREFIX)ld
LDFLAGS += -gc-sections
LINKER_SCRIPT += $(BUILDDIR)/system-onesegment.ld
BUILDDIR := build-$(PROJECT)
ALLOBJS :=
$(BOOTOBJS)
$(OBJS)
ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(CFLAGS) $(THUMBCFLAGS) -print-libgcc-file-name)
Next
BOOTOBJS +=
$(LOCAL_DIR)/crt0.o
OBJS由各个rules.mk里定义。具体例子:
build-aboot-surf7k/arch/arm/crt0.o
build-aboot-surf7k/target/surf-msm7k/init.o
build-aboot-surf7k/target/surf-msm7k/keypad.o
build-aboot-surf7k/target/surf-msm7k/panel.o
build-aboot-surf7k/platform/msm7k/platform.o
build-aboot-surf7k/platform/msm7k/interrupts.o
build-aboot-surf7k/platform/msm7k/mddi.o
build-aboot-surf7k/platform/msm7k/gpio.o
build-aboot-surf7k/platform/msm_shared/uart.o
build-aboot-surf7k/platform/msm_shared/timer.o
build-aboot-surf7k/platform/msm_shared/proc_comm.o
build-aboot-surf7k/platform/msm_shared/debug.o
build-aboot-surf7k/platform/msm_shared/smem.o
build-aboot-surf7k/platform/msm_shared/smem_ptable.o
build-aboot-surf7k/platform/msm_shared/hsusb.o
build-aboot-surf7k/platform/msm_shared/nand.o
build-aboot-surf7k/arch/arm/arch.Ao
build-aboot-surf7k/arch/arm/asm.o
build-aboot-surf7k/arch/arm/cache.o
build-aboot-surf7k/arch/arm/cache-ops.o
build-aboot-surf7k/arch/arm/ops.o
build-aboot-surf7k/arch/arm/exceptions.o
build-aboot-surf7k/arch/arm/faults.o
build-aboot-surf7k/arch/arm/mmu.o
build-aboot-surf7k/arch/arm/thread.o
build-aboot-surf7k/arch/arm/dcc.o
build-aboot-surf7k/platform/debug.o
build-aboot-surf7k/platform/init.o
build-aboot-surf7k/target/init.o
build-aboot-surf7k/kernel/debug.o
build-aboot-surf7k/kernel/dpc.o
build-aboot-surf7k/kernel/event.o
build-aboot-surf7k/kernel/main.o
build-aboot-surf7k/kernel/mutex.o
build-aboot-surf7k/kernel/thread.o
build-aboot-surf7k/kernel/timer.o
build-aboot-surf7k/dev/dev.o
build-aboot-surf7k/app/app.o
build-aboot-surf7k/app/aboot/aboot.o
build-aboot-surf7k/app/aboot/fastboot.o
build-aboot-surf7k/dev/fbcon/fbcon.o
build-aboot-surf7k/dev/keys/keys.o
build-aboot-surf7k/dev/keys/gpio_keypad.o
build-aboot-surf7k/lib/debug/debug.o
build-aboot-surf7k/lib/heap/heap.o
build-aboot-surf7k/lib/libc/atoi.o
build-aboot-surf7k/lib/libc/ctype.o
build-aboot-surf7k/lib/libc/printf.o
build-aboot-surf7k/lib/libc/malloc.o
build-aboot-surf7k/lib/libc/rand.o
build-aboot-surf7k/lib/libc/eabi.o
build-aboot-surf7k/lib/libc/string/arch/arm/memcpy.o
build-aboot-surf7k/lib/libc/string/arch/arm/memset.o
build-aboot-surf7k/lib/libc/string/memchr.o
build-aboot-surf7k/lib/libc/string/memcmp.o
build-aboot-surf7k/lib/libc/string/strcat.o
build-aboot-surf7k/lib/libc/string/strchr.o
build-aboot-surf7k/lib/libc/string/strcmp.o
build-aboot-surf7k/lib/libc/string/strcoll.o
build-aboot-surf7k/lib/libc/string/strcpy.o
build-aboot-surf7k/lib/libc/string/strdup.o
build-aboot-surf7k/lib/libc/string/strerror.o
build-aboot-surf7k/lib/libc/string/strlcat.o
build-aboot-surf7k/lib/libc/string/strlcpy.o
build-aboot-surf7k/lib/libc/string/strlen.o
build-aboot-surf7k/lib/libc/string/strncat.o
build-aboot-surf7k/lib/libc/string/strncpy.o
build-aboot-surf7k/lib/libc/string/strncmp.o
build-aboot-surf7k/lib/libc/string/strnicmp.o
build-aboot-surf7k/lib/libc/string/strnlen.o
build-aboot-surf7k/lib/libc/string/strpbrk.o
build-aboot-surf7k/lib/libc/string/strrchr.o
build-aboot-surf7k/lib/libc/string/strspn.o
build-aboot-surf7k/lib/libc/string/strstr.o
build-aboot-surf7k/lib/libc/string/strtok.o
build-aboot-surf7k/lib/libc/string/strxfrm.o
build-aboot-surf7k/lib/ptable/ptable.o
Next
OBJS里各个目标的默认规则:
$(BUILDDIR)/%.o: %.c $(SRCDEPS)
Action
$(NOECHO)$(CC) $(CFLAGS) $(THUMBCFLAGS) --std=c99 $(INCLUDES) -c $< -MD -MT $@ -MF $(@:%o=%d) -o $@
Extension
THUMBCFLAGS := -mthumb -D__thumb__
INCLUDES := -I$(BUILDDIR) -Iinclude
INCLUDES +=
-I$(LOCAL_DIR)/include
INCLUDES += -I$(LOCAL_DIR)/include
SRCDEPS := $(CONFIGHEADER)
CONFIGHEADER := $(BUILDDIR)/config.h