From 6ba196e1dfb3b25c3e547f48839d2bae918dc71c Mon Sep 17 00:00:00 2001 From: Taku Shimosawa Date: Wed, 28 Sep 2011 16:11:27 +0900 Subject: [PATCH] new Makefile --- kernel/Makefile | 26 ++++++++++++++++++-------- kernel/Makefile.build | 34 +++++++++++++++------------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index c7730a71..67558dd4 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,27 +1,37 @@ BUILD_TARGET = mee knf -BUILD_DIR = ../../build/mcos -SRC = $PWD +SRC = $(CURDIR) + +AALBASE ?= $(SRC)/../../aal/manycore +O ?= $(KBUILD_OUTPUT) +V ?= $(VERBOSE) KERNEL = kernel.img -KERNELS = $(addsuffix /$(KERNEL),$(addprefix $(BUILD_DIR)/,$(BUILD_TARGET))) +KERNELS = $(addsuffix /$(KERNEL),$(addprefix $(O)/,$(BUILD_TARGET))) + +SUBCMD_OPTS = V='$(V)' + +$(if $(O),,$(error Specify the compilation target directory)) +$(if $(shell ls $(AALBASE)/Makefile.aal),,\ + $(error AAL is not found in $(AALBASE))) .PHONY: all clean all: $(KERNELS) %/kernel.img: %/Makefile - @echo 'MAKE TARGET' $(dir $@) - @make -C $(dir $@) + @echo 'Building for' $(dir $@) + @make --no-print-directory -C $(dir $@) $(SUBCMD_OPTS) %/Makefile: Makefile.build FORCE @mkdir -p $(dir $@) - @echo 'SRC = $(PWD)' > $@ + @echo 'SRC = $(SRC)' > $@ + @echo 'AALBASE = $(AALBASE)' >> $@ @echo 'TARGET = $(notdir $(patsubst %/,%,$(dir $@)))' >> $@ @cat Makefile.build >> $@ clean: $(addsuffix .clean,$(BUILD_TARGET)) -%.clean: $(BUILD_DIR)/%/Makefile - @make -C $(BUILD_DIR)/$(basename $@) clean +%.clean: $(O)/%/Makefile + @make -C $(O)/$(basename $@) $(SUBCMD_OPTS) clean FORCE: diff --git a/kernel/Makefile.build b/kernel/Makefile.build index bf8d09ac..c0cbb160 100644 --- a/kernel/Makefile.build +++ b/kernel/Makefile.build @@ -1,26 +1,21 @@ -AALBASE=$(SRC)/../../aal/manycore AALDIR=$(AALBASE)/$(TARGET) -SRCS=$(wildcard $(SRC)/*.c) -OBJS=$(notdir $(patsubst %.c,%.o,$(SRCS))) -CFLAGS=-Wall -nostdlib -nostdinc -isystem $(shell $(CC) -print-file-name=include) -O3 -I$(SRC)/include -mcmodel=kernel -LDFLAGS=-e arch_start -AALOBJ=$(AALDIR)/aal.o +OBJS=setup.o mem.o debug.o +DEPSRCS=$(wildcard $(SRC)/*.c) --include $(SRC)/configs/config.$(TARGET) -include $(AALDIR)/Makefile.config +include $(SRC)/configs/config.$(TARGET) include $(AALBASE)/Makefile.common +CFLAGS += -I$(SRC)/include -mcmodel=kernel +LDFLAGS += -e arch_start +AALOBJ = aal/aal.o + +SUBCMD_OPTS = TARGET=$(TARGET) O=$(CURDIR)/aal CC=$(CC) LD=$(LD) + ld_kern_cmd_base = $(LD) $(LDFLAGS) -o $@.elf $^ mkimage_cmd_base = [ -f $(SRC)/scripts/mkimage.$(TARGET) ] && sh $(SRC)/scripts/mkimage.$(TARGET) '$@.elf' '$@' '$(SRC)' || cp $@.elf $@ -ifeq ($(V),1) - ld_kern_cmd = $(ld_kern_cmd_base) - mkimage_cmd = $(mkimage_cmd_base) -else - ld_kern_cmd = @echo ' ' LDKERN $@; $(ld_kern_cmd_base) - mkimage_cmd = @echo ' ' MKIMAGE $@; $(mkimage_cmd_base) -endif - +ld_kern_cmd = $(call echo_cmd,LDKERN,$@)$(ld_kern_cmd_base) +mkimage_cmd = $(call echo_cmd,MKIMAGE,$@)$(mkimage_cmd_base) all: depend kernel.img @@ -30,15 +25,16 @@ kernel.img: $(OBJS) $(AALOBJ) clean: $(RM) $(OBJS) kernel.img kernel.img.elf Makefile.dep - @make -C $(AALDIR) clean + @$(submake) -C $(AALBASE) $(SUBCMD_OPTS) clean depend: Makefile.dep -Makefile.dep: $(SRCS) +Makefile.dep: $(DEPSRCS) $(dep_cmd) $(AALOBJ): FORCE - @make -C $(AALDIR) CC=$(CC) LD=$(LD) + @mkdir -p $(dir $(AALOBJ)) + $(call echo_cmd,BUILD AAL,$(TARGET))$(submake) -C $(AALBASE) $(SUBCMD_OPTS) %.o: $(SRC)/%.c $(cc_cmd)