forked from lucianoforks/tetris-os
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
83 lines (61 loc) · 2.31 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
UNAME := $(shell uname)
ifeq ($(UNAME),Linux)
CC=gcc -elf_i386
AS=as --32
LD=ld -m elf_i386
else
CC=i386-elf-gcc
AS=i386-elf-as
LD=i386-elf-ld
endif
SOUND_FLAGS=-DSOUND_SB16
ifeq ($(SOUND),1)
SOUND_FLAGS=-DSOUND_PCSPK
endif
GFLAGS=
CCFLAGS=-m32 -std=c11 -O2 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing
CCFLAGS+=-Wno-pointer-arith -Wno-unused-parameter
CCFLAGS+=-nostdlib -nostdinc -ffreestanding -fno-pie -fno-stack-protector
CCFLAGS+=-fno-builtin-function -fno-builtin
CCFLAGS+=$(SOUND_FLAGS)
ASFLAGS=
LDFLAGS=
BOOTSECT_SRCS=\
src/stage0.S
BOOTSECT_OBJS=$(BOOTSECT_SRCS:.S=.o)
KERNEL_C_SRCS=$(wildcard src/*.c)
KERNEL_S_SRCS=$(filter-out $(BOOTSECT_SRCS), $(wildcard src/*.S))
KERNEL_OBJS=$(KERNEL_C_SRCS:.c=.o) $(KERNEL_S_SRCS:.S=.o)
BOOTSECT=bootsect.bin
KERNEL=kernel.bin
IMG=boot.img
all: img
clean:
rm -f ./**/*.o
rm -f ./*.img
rm -f ./**/*.elf
rm -f ./**/*.bin
%.o: %.c
$(CC) -o $@ -c $< $(GFLAGS) $(CCFLAGS)
%.o: %.S
$(AS) -o $@ -c $< $(GFLAGS) $(ASFLAGS)
dirs:
mkdir -p bin
bootsect: $(BOOTSECT_OBJS)
$(LD) -o ./bin/$(BOOTSECT) $^ -Ttext 0x7C00 --oformat=binary
kernel: $(KERNEL_OBJS)
$(LD) -o ./bin/$(KERNEL) $^ $(LDFLAGS) -Tsrc/link.ld
img: dirs bootsect kernel
dd if=/dev/zero of=$(IMG) bs=512 count=2880
dd if=./bin/$(BOOTSECT) of=$(IMG) conv=notrunc bs=512 seek=0 count=1
dd if=./bin/$(KERNEL) of=$(IMG) conv=notrunc bs=512 seek=1 count=2048
qemu-mac: img
qemu-system-i386 -drive format=raw,file=boot.img -d cpu_reset -monitor stdio -device sb16 -audiodev coreaudio,id=coreaudio,out.frequency=48000,out.channels=2,out.format=s32 -machine pcspk-audiodev=coresound
qemu-pulse: img
qemu-system-i386 -drive format=raw,file=boot.img -d cpu_reset -monitor stdio -device sb16 -audiodev pulseaudio,id=pulseaudio,out.frequency=48000,out.channels=2,out.format=s32 -machine pcspk-audiodev=pulseaudio
qemu-sdl: img
qemu-system-i386 -display sdl -drive format=raw,file=boot.img -d cpu_reset -monitor stdio -audiodev sdl,id=sdl,out.frequency=48000,out.channels=2,out.format=s32 -device sb16,audiodev=sdl -machine pcspk-audiodev=sdl
qemu-no-audio: img
qemu-system-i386 -drive format=raw,file=$(IMG) -d cpu_reset -monitor stdio
qemu-win: img
qemu-system-i386 -display sdl -drive format=raw,file=boot.img -d cpu_reset -monitor stdio -audiodev dsound,id=dsound -device sb16,audiodev=dsound -machine pcspk-audiodev=dsound