|
| 1 | +#--------------------------------------------------------------------------------- |
| 2 | +.SUFFIXES: |
| 3 | +#--------------------------------------------------------------------------------- |
| 4 | + |
| 5 | +ifeq ($(strip $(DEVKITPRO)),) |
| 6 | +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro") |
| 7 | +endif |
| 8 | + |
| 9 | +include $(DEVKITPRO)/libnx/switch_rules |
| 10 | + |
| 11 | +#--------------------------------------------------------------------------------- |
| 12 | +# TARGET is the name of the output |
| 13 | +# SOURCES is a list of directories containing source code |
| 14 | +# DATA is a list of directories containing data files |
| 15 | +# INCLUDES is a list of directories containing header files |
| 16 | +#--------------------------------------------------------------------------------- |
| 17 | +TARGET := eiffel |
| 18 | +SOURCES := src |
| 19 | +DATA := data |
| 20 | +INCLUDES := include |
| 21 | + |
| 22 | +#--------------------------------------------------------------------------------- |
| 23 | +# options for code generation |
| 24 | +#--------------------------------------------------------------------------------- |
| 25 | +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec |
| 26 | + |
| 27 | +CFLAGS := -g -Wall -Werror \ |
| 28 | + -ffunction-sections \ |
| 29 | + -fdata-sections \ |
| 30 | + $(ARCH) \ |
| 31 | + $(BUILD_CFLAGS) |
| 32 | + |
| 33 | +CFLAGS += $(INCLUDE) |
| 34 | + |
| 35 | +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions |
| 36 | + |
| 37 | +ASFLAGS := -g $(ARCH) |
| 38 | + |
| 39 | +#--------------------------------------------------------------------------------- |
| 40 | +# list of directories containing libraries, this must be the top level containing |
| 41 | +# include and lib |
| 42 | +#--------------------------------------------------------------------------------- |
| 43 | +LIBDIRS := $(PORTLIBS) $(LIBNX) |
| 44 | + |
| 45 | +#--------------------------------------------------------------------------------- |
| 46 | +# no real need to edit anything past this point unless you need to add additional |
| 47 | +# rules for different file extensions |
| 48 | +#--------------------------------------------------------------------------------- |
| 49 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 50 | +#--------------------------------------------------------------------------------- |
| 51 | + |
| 52 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 53 | + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 54 | + |
| 55 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 56 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 57 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 58 | +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 59 | + |
| 60 | +#--------------------------------------------------------------------------------- |
| 61 | +# use CXX for linking C++ projects, CC for standard C |
| 62 | +#--------------------------------------------------------------------------------- |
| 63 | +ifeq ($(strip $(CPPFILES)),) |
| 64 | +#--------------------------------------------------------------------------------- |
| 65 | + export LD := $(CC) |
| 66 | +#--------------------------------------------------------------------------------- |
| 67 | +else |
| 68 | +#--------------------------------------------------------------------------------- |
| 69 | + export LD := $(CXX) |
| 70 | +#--------------------------------------------------------------------------------- |
| 71 | +endif |
| 72 | +#--------------------------------------------------------------------------------- |
| 73 | + |
| 74 | +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) |
| 75 | +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) |
| 76 | +export OFILES := $(OFILES_BIN) $(OFILES_SRC) |
| 77 | +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) |
| 78 | + |
| 79 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 80 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 81 | + -I$(CURDIR)/$(BUILD) |
| 82 | + |
| 83 | +.PHONY: clean all |
| 84 | + |
| 85 | +#--------------------------------------------------------------------------------- |
| 86 | +all: lib/lib$(TARGET).a lib/lib$(TARGET)d.a |
| 87 | + |
| 88 | +lib: |
| 89 | + @[ -d $@ ] || mkdir -p $@ |
| 90 | + |
| 91 | +release: |
| 92 | + @[ -d $@ ] || mkdir -p $@ |
| 93 | + |
| 94 | +debug: |
| 95 | + @[ -d $@ ] || mkdir -p $@ |
| 96 | + |
| 97 | +lib/lib$(TARGET).a : lib release $(SOURCES) $(INCLUDES) |
| 98 | + @$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \ |
| 99 | + BUILD_CFLAGS="-DNDEBUG=1 -O2" \ |
| 100 | + DEPSDIR=$(CURDIR)/release \ |
| 101 | + --no-print-directory -C release \ |
| 102 | + -f $(CURDIR)/Makefile |
| 103 | + |
| 104 | +lib/lib$(TARGET)d.a : lib debug $(SOURCES) $(INCLUDES) |
| 105 | + @$(MAKE) BUILD=debug OUTPUT=$(CURDIR)/$@ \ |
| 106 | + BUILD_CFLAGS="-DDEBUG=1 -Og" \ |
| 107 | + DEPSDIR=$(CURDIR)/debug \ |
| 108 | + --no-print-directory -C debug \ |
| 109 | + -f $(CURDIR)/Makefile |
| 110 | + |
| 111 | +dist-bin: all |
| 112 | + @tar --exclude=*~ -cjf lib$(TARGET).tar.bz2 include lib |
| 113 | + |
| 114 | +dist-src: |
| 115 | + @tar --exclude=*~ -cjf lib$(TARGET)-src.tar.bz2 include source Makefile |
| 116 | + |
| 117 | +dist: dist-src dist-bin |
| 118 | + |
| 119 | +#--------------------------------------------------------------------------------- |
| 120 | +clean: |
| 121 | + @echo clean ... |
| 122 | + @rm -fr release debug lib *.bz2 |
| 123 | + |
| 124 | +#--------------------------------------------------------------------------------- |
| 125 | +else |
| 126 | + |
| 127 | +DEPENDS := $(OFILES:.o=.d) |
| 128 | + |
| 129 | +#--------------------------------------------------------------------------------- |
| 130 | +# main targets |
| 131 | +#--------------------------------------------------------------------------------- |
| 132 | +$(OUTPUT) : $(OFILES) |
| 133 | + |
| 134 | +$(OFILES_SRC) : $(HFILES) |
| 135 | + |
| 136 | +#--------------------------------------------------------------------------------- |
| 137 | +%_bin.h %.bin.o : %.bin |
| 138 | +#--------------------------------------------------------------------------------- |
| 139 | + @echo $(notdir $<) |
| 140 | + @$(bin2o) |
| 141 | + |
| 142 | + |
| 143 | +-include $(DEPENDS) |
| 144 | + |
| 145 | +#--------------------------------------------------------------------------------------- |
| 146 | +endif |
| 147 | +#--------------------------------------------------------------------------------------- |
| 148 | + |
0 commit comments