summaryrefslogtreecommitdiff
path: root/src/Makefile
blob: 07f1cb5b2c030f184f7ba9e9f25354f35561768d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 -O3 -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 obj/platform/3ds.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