summaryrefslogtreecommitdiff
path: root/Makefile
blob: 061914ed954ff87ca0eda19c72962654e415f334 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
prefix         = /usr/local
exec_prefix    = $(prefix)
bindir         = $(exec_prefix)/bin
sharedir       = $(prefix)/share/saturn-tools

CFLAGS         = -Os -pipe -std=c99 -D_POSIX_C_SOURCE=200809L
LDFLAGS        =
SATURN_CROSS   = saturn-
SATURN_CC      = $(SATURN_CROSS)gcc -m2 -mb
SATURN_OBJCOPY = $(SATURN_CROSS)objcopy
SATURN_CFLAGS  = -Os -pipe -std=c99 -nostdlib
SATURN_LDFLAGS =

INSTALL        = ./tools/install.sh

-include config.mak

BOOTSRCS = $(sort $(wildcard boot/*.c))
BOOTOBJS = $(patsubst %.c,%.o,$(BOOTSRCS))
BOOTELFS = $(patsubst %.c,%.elf,$(BOOTSRCS))
BOOTBINS = $(patsubst boot/%.c,share/boot/%,$(BOOTSRCS))

SRCS = $(sort $(wildcard src/*.c))
DATA = $(sort $(wildcard src/*.bin))
OBJS = $(SRCS:.c=.o) $(DATA:.bin=.o)
BINS = bin/saturn-mkboot bin/saturn-mkiso

DEPENDS = $(SRCS:.c=.d) $(BOOTSRCS:.c=.d)

.PHONY: all clean install install-bins install-data

all: $(BINS) $(BOOTBINS)

-include $(DEPENDS)

install: install-bins install-data

clean:
	rm -f $(BINS) $(OBJS) $(BOOTBINS) $(BOOTELFS) $(BOOTOBJS) $(DEPENDS)

bin/saturn-mkboot: src/securitycode.o src/symbols.o

bin/%: src/%.o
	$(CC) $(LDFLAGS) $^ -o $@

share/boot/%: boot/%.elf
	$(SATURN_OBJCOPY) -O binary $< $@

%.elf: %.o boot/ldscript
	$(SATURN_CC) $(SATURN_CFLAGS) $(SATURN_LDFLAGS) -T boot/ldscript $< -o $@

%.c: %.bin
	tools/bin2c $< > $@

boot/%.o: boot/%.c
	$(SATURN_CC) $(SATURN_CFLAGS) -c $< -o $@
	$(SATURN_CC) -MM $(SATURN_CFLAGS) $< -MT $@ > boot/$*.d

src/%.o: src/%.c
	$(CC) $(CFLAGS) -c $< -o $@
	$(CC) -MM $(CFLAGS) $< -MT $@ > src/$*.d

src/paths.h: config.mak
	echo "#define DATA_PATH \"$(sharedir)\"" > $@

$(DESTDIR)$(bindir)/%: bin/%
	$(INSTALL) -D $< $@

$(DESTDIR)$(sharedir)/%: share/%
	$(INSTALL) -D -m 644 $< $@

install-bins: $(BINS:bin/%=$(DESTDIR)$(bindir)/%)

install-data: $(BOOTBINS:share/%=$(DESTDIR)$(sharedir)/%)

.PRECIOUS: src/%.o boot/%.o %.elf %.c