-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
56 lines (44 loc) · 1.26 KB
/
Makefile
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
TARGET=pastaos
# Automatically detect sources in sub-folders
build-dirs = $(wildcard */)
SRCS=$(wildcard $(addsuffix *.c, $(build-dirs))) $(wildcard $(addsuffix *.S, $(build-dirs)))
OBJS=$(patsubst %.c, %.o, $(filter %c, $(SRCS))) $(patsubst %.S, %.o, $(filter %S, $(SRCS)))
# Compiler options
CFLAGS=-m32 -O2 -MD -g -Wall -Wextra -fno-builtin -fomit-frame-pointer -fno-stack-protector -Iinclude -fno-pie
LDFLAGS=-g -nostdlib -X -lc
ifeq ("$(origin V)", "command line")
Q=
else
Q=@
endif
# Build rules
%.o: %.S
@echo AS $<
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.c
@echo CC $<
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
$(TARGET): $(OBJS)
@echo LD $@
$(Q)$(LD) -m elf_i386 -T linker.ld $(OBJS) -o $(TARGET) -nostdlib -z noexecstack
# Makefile targets
all: $(TARGET)
iso: all
@echo MKISO $(TARGET).iso
$(Q)rm -f $(TARGET).iso
$(Q)mkdir -p isodir/boot/grub
$(Q)cp $(TARGET) isodir/boot/
$(Q)cp grub.cfg isodir/boot/grub/grub.cfg
$(Q)grub-mkrescue -o $(TARGET).iso isodir
$(Q)rm -rf isodir
run: iso
$(Q)qemu-system-x86_64 -cdrom $(TARGET).iso -boot d -display curses
tags:
@echo CTAGS $@
$(Q)ctags -R
clean:
@echo CLEAN
$(Q)rm -rf isodir
$(Q)rm -f $(OBJS) $(TARGET) $(patsubst %.o, %.d, $(OBJS)) *.iso tags
# Properly support header dependencies
-include $(OBJS:.o=.d)