summaryrefslogtreecommitdiff
path: root/src/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'src/Makefile')
-rw-r--r--src/Makefile61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
new file mode 100644
index 0000000..432b331
--- /dev/null
+++ b/src/Makefile
@@ -0,0 +1,61 @@
+ifeq ($(strip $(DEVKITPRO)),)
+$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO")
+endif
+
+SRCS = $(sort $(wildcard $(srcdir)/*.c))
+OBJS = $(patsubst $(srcdir)/%.c,obj/%.o,$(SRCS))
+DEPS = $(patsubst $(srcdir)/%.c,obj/%.d,$(SRCS))
+
+CFLAGS =
+CPPFLAGS =
+LDFLAGS =
+
+CC = $(DEVKITPRO)/devkitARM/bin/arm-none-eabi-gcc
+
+CFLAGS_AUTO = -D__3DS__ -ffunction-sections -flto -g -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -mword-relocations -Og -std=c11 -Wall -Werror=implicit-function-declaration
+LDFLAGS_AUTO = -L$(DEVKITPRO)/libctru/lib -specs=3dsx.specs
+LDLIBS_AUTO = -lctru -lm
+
+CFLAGS_ALL = $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS)
+LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS)
+LDLIBS_ALL = $(LDLIBS_AUTO) $(LDLIBS)
+
+-include config.mak
+
+ifeq ($(CONFIGURED),)
+
+all:
+ @printf >&2 'Please run mk.sh, not make.\n'
+ @exit 1
+
+else
+
+all: imb3.3dsx
+3dslink: imb3.3dsx
+ $(DEVKITPRO)/tools/bin/3dslink $<
+.PHONY: 3dslink
+
+imb3.3dsx: imb3.elf
+ 3dsxtool $< $@
+
+imb3.elf: $(OBJS) obj/gc/gc.o
+ $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -o $@ $^ $(LDLIBS_ALL)
+imb3-debug.elf: $(OBJS) obj/gc/gc-debug.o
+ $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -o $@ $^ $(LDLIBS_ALL)
+
+obj/%.o: $(srcdir)/%.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS_ALL) -c -o $@ $<
+
+# https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html
+obj/%.d: $(srcdir)/%.c
+ @mkdir -p obj
+ @set -e; rm -f $@; \
+ $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
+ sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
+ rm -f $@.$$$$
+include $(DEPS)
+
+endif
+
+.PHONY: all