2018-05-19 00:54:38 +02:00
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
.SUFFIXES:
|
|
|
|
#---------------------------------------------------------------------------------
|
2018-02-25 20:00:50 +01:00
|
|
|
|
|
|
|
ifeq ($(strip $(DEVKITPRO)),)
|
2018-05-19 00:54:38 +02:00
|
|
|
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
2018-02-25 20:00:50 +01:00
|
|
|
endif
|
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
TOPDIR ?= $(CURDIR)
|
|
|
|
include $(DEVKITPRO)/devkitA64/base_rules
|
|
|
|
|
2018-11-13 21:42:35 +01:00
|
|
|
AMSBRANCH := $(shell git symbolic-ref --short HEAD)
|
|
|
|
AMSREV := $(AMSBRANCH)-$(shell git rev-parse --short HEAD)
|
|
|
|
|
|
|
|
ifneq (, $(strip $(shell git status --porcelain 2>/dev/null)))
|
|
|
|
AMSREV := $(AMSREV)-dirty
|
|
|
|
endif
|
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
# TARGET is the name of the output
|
|
|
|
# BUILD is the directory where object files & intermediate files will be placed
|
|
|
|
# SOURCES is a list of directories containing source code
|
|
|
|
# DATA is a list of directories containing data files
|
|
|
|
# INCLUDES is a list of directories containing header files
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
TARGET := $(notdir $(CURDIR))
|
|
|
|
BUILD := build
|
|
|
|
SOURCES := src src/dbg
|
|
|
|
DATA := data
|
2018-10-17 02:54:50 +02:00
|
|
|
INCLUDES := include ../common/include
|
2018-05-19 00:54:38 +02:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
# options for code generation
|
|
|
|
#---------------------------------------------------------------------------------
|
2018-09-27 23:56:01 +02:00
|
|
|
ARCH := -march=armv8-a -mtune=cortex-a57 -mgeneral-regs-only #<- important
|
2018-11-13 21:42:35 +01:00
|
|
|
DEFINES := -D__CCPLEX__ -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
|
2018-05-19 00:54:38 +02:00
|
|
|
CFLAGS := \
|
2018-02-25 20:00:50 +01:00
|
|
|
-g \
|
|
|
|
-O2 \
|
|
|
|
-ffunction-sections \
|
|
|
|
-fdata-sections \
|
|
|
|
-fomit-frame-pointer \
|
2018-07-29 20:02:06 +02:00
|
|
|
-fno-asynchronous-unwind-tables \
|
|
|
|
-fno-unwind-tables \
|
2018-02-25 20:00:50 +01:00
|
|
|
-std=gnu11 \
|
|
|
|
-Werror \
|
2018-05-19 00:54:38 +02:00
|
|
|
-Wall \
|
|
|
|
$(ARCH) $(DEFINES)
|
|
|
|
|
2018-07-29 20:02:06 +02:00
|
|
|
CFLAGS += $(INCLUDE)
|
2018-05-19 00:54:38 +02:00
|
|
|
|
|
|
|
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
2018-02-25 20:00:50 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
ASFLAGS := -g $(ARCH)
|
2018-09-27 23:56:01 +02:00
|
|
|
LDFLAGS = -specs=$(TOPDIR)/linker.specs -nostartfiles -nostdlib -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
2018-02-25 20:00:50 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
LIBS :=
|
2018-02-27 01:00:58 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
# list of directories containing libraries, this must be the top level containing
|
|
|
|
# include and lib
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
LIBDIRS :=
|
2018-02-25 20:00:50 +01:00
|
|
|
|
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
# no real need to edit anything past this point unless you need to add additional
|
|
|
|
# rules for different file extensions
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
|
|
|
export TOPDIR := $(CURDIR)
|
|
|
|
|
|
|
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
|
|
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
|
|
|
|
$(TOPDIR)/bpmpfw
|
|
|
|
|
|
|
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
|
|
|
|
|
|
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
|
|
|
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
|
|
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
|
|
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) bpmpfw.bin
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
# use CXX for linking C++ projects, CC for standard C
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
ifeq ($(strip $(CPPFILES)),)
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
export LD := $(CC)
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
else
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
export LD := $(CXX)
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
endif
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
|
|
|
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
|
|
|
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
|
|
|
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
|
|
|
|
|
|
|
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
|
|
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
|
|
|
-I$(CURDIR)/$(BUILD)
|
|
|
|
|
|
|
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
|
|
|
|
|
|
|
.PHONY: $(BUILD) build_bpmpfw clean all
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
all: $(BUILD)
|
|
|
|
|
|
|
|
check_bpmpfw:
|
|
|
|
@$(MAKE) -C bpmpfw all
|
|
|
|
|
|
|
|
$(BUILD): check_bpmpfw
|
|
|
|
@[ -d $@ ] || mkdir -p $@
|
|
|
|
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------
|
2018-02-25 20:00:50 +01:00
|
|
|
clean:
|
2018-05-19 00:54:38 +02:00
|
|
|
@echo clean ...
|
|
|
|
@$(MAKE) -C $(TOPDIR)/bpmpfw clean
|
|
|
|
@rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf
|
|
|
|
|
2018-02-25 20:00:50 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
else
|
|
|
|
.PHONY: all
|
2018-02-25 20:00:50 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
DEPENDS := $(OFILES:.o=.d)
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
# main targets
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
all : $(OUTPUT).bin
|
|
|
|
|
|
|
|
$(OUTPUT).bin : $(OUTPUT).elf
|
2018-02-25 20:00:50 +01:00
|
|
|
$(OBJCOPY) -S -O binary $< $@
|
2018-05-19 00:54:38 +02:00
|
|
|
@echo built ... $(notdir $@)
|
2018-02-25 20:00:50 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
$(OUTPUT).elf : $(OFILES)
|
2018-02-25 20:00:50 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
%.elf:
|
|
|
|
@echo linking $(notdir $@)
|
|
|
|
$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
|
|
|
@$(NM) -CSn $@ > $(notdir $*.lst)
|
2018-02-25 20:00:50 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
$(OFILES_SRC) : $(HFILES_BIN)
|
2018-02-26 22:09:35 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
# you need a rule like this for each extension you use as binary data
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
%.bin.o %_bin.h: %.bin
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
@echo $(notdir $<)
|
2018-02-25 20:00:50 +01:00
|
|
|
@$(bin2o)
|
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
-include $(DEPENDS)
|
2018-02-25 20:00:50 +01:00
|
|
|
|
2018-05-19 00:54:38 +02:00
|
|
|
#---------------------------------------------------------------------------------------
|
|
|
|
endif
|
|
|
|
#---------------------------------------------------------------------------------------
|