From 7544e5285600f2ac5b96c2a343648fb9c1e41a4a Mon Sep 17 00:00:00 2001 From: Yanyan Jiang Date: Fri, 2 Jun 2017 08:40:03 -0400 Subject: [PATCH] refactor makefile --- Makefile | 7 ++--- Makefile.app | 4 +-- Makefile.compile | 28 +++++++++++-------- tests/guitest/Makefile | 2 +- tests/guitest/{guitest-am.cpp => guitest.cpp} | 0 5 files changed, 20 insertions(+), 21 deletions(-) rename tests/guitest/{guitest-am.cpp => guitest.cpp} (100%) diff --git a/Makefile b/Makefile index 17960865..a0057b74 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,8 @@ AM_HOME ?= $(shell pwd) .PHONY: all clean all: - @cd am && make ARCH=$(ARCH) - @cd libs/klib && make ARCH=$(ARCH) - @cd libs/imgui && make ARCH=$(ARCH) + @cd am && make +# TODO: clean everything clean: @cd am && make clean - @cd libs/klib && make clean - @cd libs/imgui && make clean diff --git a/Makefile.app b/Makefile.app index b01b9ff1..2afd40d1 100644 --- a/Makefile.app +++ b/Makefile.app @@ -27,9 +27,7 @@ LINK_FILES += $(addsuffix -$(ARCH).a, $(join \ )) .PHONY: app run clean -app: $(OBJS) - @cd $(AM_HOME) && make ARCH=$(ARCH) - @echo $(LINK_FILES) +app: $(OBJS) am $(LIBS) @$(AM_HOME)/am/arch/$(ARCH)/img/build $(BINARY) $(LINK_FILES) run: app @$(AM_HOME)/am/arch/$(ARCH)/img/run $(BINARY) diff --git a/Makefile.compile b/Makefile.compile index 0df2082b..aad56c42 100644 --- a/Makefile.compile +++ b/Makefile.compile @@ -1,9 +1,4 @@ -objdest = $(addprefix $(DST_DIR)/, $(addsuffix .o, $(basename $(1)))) -depdest = $(addprefix $(DST_DIR)/, $(addsuffix .d, $(basename $(1)))) - -OBJS = $(call objdest, $(SRCS)) -DEPS = $(call depdest, $(SRCS)) - +# Compilation flags ARCH_SPLIT = $(subst -, ,$(ARCH)) REAL_ARCH = $(word 1,$(ARCH_SPLIT)) PLATFORM = $(word 2,$(ARCH_SPLIT)) @@ -17,13 +12,12 @@ CC = $(CROSS_COMPILE)gcc CXX = $(CROSS_COMPILE)g++ LD = $(CROSS_COMPILE)ld -# Basic compilation flags -INCLUDES = $(addprefix -I, $(INC_DIR)) -I$(AM_HOME)/am/ -I$(AM_HOME)/am/arch/$(ARCH)/include +INCLUDES = $(addprefix -I, $(INC_DIR)) -I$(AM_HOME)/am/ +INCLUDES += -I$(AM_HOME)/am/arch/$(ARCH)/include CFLAGS += -std=gnu99 -O2 -MMD -Wall -Werror -ggdb $(INCLUDES) CXXFLAGS += -std=c++11 -O2 -MMD -Wall -Werror -ggdb $(INCLUDES) -ASFLAGS += -MMD $(INCLUDES) +ASFLAGS += -MMD $(INCLUDES) -# Arch-dependent compilation flags ifeq ($(REAL_ARCH), mips32) CXX = $(CROSS_COMPILE)g++-5 CFLAGS_COMMON = -fno-pic -static -fno-strict-aliasing -fno-builtin -fno-stack-protector -fno-delayed-branch -mno-abicalls -march=mips32 -mno-check-zero-division -EL -mno-llsc -mno-imadd -mno-mad @@ -38,17 +32,27 @@ CXXFLAGS += -m32 -fno-builtin -fno-stack-protector -fno-omit-frame-pointer -ffre ASFLAGS += -m32 endif +# Files to be compiled +OBJS = $(addprefix $(DST_DIR)/, $(addsuffix .o, $(basename $(SRCS)))) + # Compilation patterns $(DST_DIR)/%.o: %.cpp @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -c -o $@ $< - $(DST_DIR)/%.o: %.c @mkdir -p $(dir $@) $(CC) $(CFLAGS) -c -o $@ $< - $(DST_DIR)/%.o: %.S @mkdir -p $(dir $@) $(AS) $(ASFLAGS) -c -o $@ $< +# Depencies +DEPS = $(addprefix $(DST_DIR)/, $(addsuffix .d, $(basename $(SRCS)))) -include $(DEPS) + +# Dependent AM and libraries +.PHONY: $(LIBS) am +am: + cd $(AM_HOME) && make +$(LIBS): %: + cd $(AM_HOME)/libs/$* && make diff --git a/tests/guitest/Makefile b/tests/guitest/Makefile index 97db3078..f8ba493c 100644 --- a/tests/guitest/Makefile +++ b/tests/guitest/Makefile @@ -1,4 +1,4 @@ NAME = guitest -SRCS = guitest-am.cpp +SRCS = guitest.cpp LIBS = klib imgui include $(AM_HOME)/Makefile.app diff --git a/tests/guitest/guitest-am.cpp b/tests/guitest/guitest.cpp similarity index 100% rename from tests/guitest/guitest-am.cpp rename to tests/guitest/guitest.cpp