# はてなダイアリー解説用OSのMakefile

# 変数の定義

AS = as

CC = gcc
CFLAGS =

DC = gdc
DFLAGS = -nostdlib -fno-builtin -frelease -Wall -O3 -inline

LD = ld
LDFLAGS = 

OBJS = \
	ipl.o\
	setup.o\
	object.o\
	std/aApply.o\
	std/arraycast.o\
	std/cast.o\
	std/deh.o\
	std/gc.o\
	std/math.o\
	std/moduleinit.o\
	std/stdint.o\
	std/string.o\
	std/unwind.o\
	std/utf.o\
	std/c/string.o\
	std/c/process.o\
	std/typeinfo/ti_AC.o\
	std/typeinfo/ti_Acdouble.o\
	std/typeinfo/ti_Acfloat.o\
	std/typeinfo/ti_Acreal.o\
	std/typeinfo/ti_Adouble.o\
	std/typeinfo/ti_Afloat.o\
	std/typeinfo/ti_Ag.o\
	std/typeinfo/ti_Aint.o\
	std/typeinfo/ti_Along.o\
	std/typeinfo/ti_Areal.o\
	std/typeinfo/ti_Ashort.o\
	std/typeinfo/ti_byte.o\
	std/typeinfo/ti_C.o\
	std/typeinfo/ti_cdouble.o\
	std/typeinfo/ti_cfloat.o\
	std/typeinfo/ti_char.o\
	std/typeinfo/ti_creal.o\
	std/typeinfo/ti_dchar.o\
	std/typeinfo/ti_delegate.o\
	std/typeinfo/ti_double.o\
	std/typeinfo/ti_float.o\
	std/typeinfo/ti_idouble.o\
	std/typeinfo/ti_ifloat.o\
	std/typeinfo/ti_int.o\
	std/typeinfo/ti_ireal.o\
	std/typeinfo/ti_long.o\
	std/typeinfo/ti_ptr.o\
	std/typeinfo/ti_real.o\
	std/typeinfo/ti_short.o\
	std/typeinfo/ti_ubyte.o\
	std/typeinfo/ti_uint.o\
	std/typeinfo/ti_ulong.o\
	std/typeinfo/ti_ushort.o\
	std/typeinfo/ti_void.o\
	std/typeinfo/ti_wchar.o\
	outlandish/os/memorymap.o\
	outlandish/os/startup.o\
	outlandish/os/io.o\
	outlandish/os/serial.o\
	outlandish/os/page.o\

# これらは実際のファイル・ディレクトリと関係ないターゲット。
.PHONY: clean run

# 拡張子規則
%.o : %.d
	$(DC) $(DFLAGS) $(INCLUDES) -o $@ -c $<

%.o : %.c
	$(CC) $(CFLAGS) $(INCLUDES) -o $@  -c $<

%.o : %.s
	$(AS) $(ASFLAGS) $(INCLUDES) -o $@ $<

# FDイメージを元にOSを実行する。
run: fd.img
	./qemu/qemu.exe -L ./qemu -m 128 -fda $<

# 生成物・中間生成物の削除。
clean:
	-rm fd.img ipl.bin $(OBJS)

# FDイメージの生成。
fd.img: ipl.bin
	dd if=/dev/zero of=$@ count=2880
	dd if=$< of=$@ conv=notrunc

# バイナリイメージの生成。
ipl.bin: ipl.exe
	objcopy -S -O binary $< $@

# オブジェクト・ファイルのリンク。
ipl.exe: $(OBJS) ipl.ls
	$(LD) $(LDFLAGS) -o $@ -T ipl.ls $(OBJS)

# オブジェクト・ファイルの依存関係。
ipl.o: ipl.s
setup.o: setup.s

object.o: object.d
std/aApply.o: std/aApply.d
std/arraycast.o: std/arraycast.d
std/cast.o: std/cast.d
std/deh.o: std/deh.d
std/gc.o: std/gc.d
std/math.o: std/math.d
std/moduleinit.o: std/moduleinit.d
std/stdint.o: std/stdint.d
std/string.o: std/string.d
std/unwind.o: std/unwind.d
std/utf.o: std/utf.d
std/c/process.o: std/c/process.d
std/c/string.o: std/c/string.d
outlandish/os/memorymap.o: outlandish/os/memorymap.d
outlandish/os/startup.o: outlandish/os/startup.d
outlandish/os/io.o: outlandish/os/io.d
outlandish/os/serial.o: outlandish/os/serial.d
outlandish/os/page.o: outlandish/os/page.d
std/typeinfo/ti_AC.o: std/typeinfo/ti_AC.d
std/typeinfo/ti_Acdouble.o: std/typeinfo/ti_Acdouble.d
std/typeinfo/ti_Acfloat.o: std/typeinfo/ti_Acfloat.d
std/typeinfo/ti_Acreal.o: std/typeinfo/ti_Acreal.d
std/typeinfo/ti_Adouble.o: std/typeinfo/ti_Adouble.d
std/typeinfo/ti_Afloat.o: std/typeinfo/ti_Afloat.d
std/typeinfo/ti_Ag.o: std/typeinfo/ti_Ag.d
std/typeinfo/ti_Aint.o: std/typeinfo/ti_Aint.d
std/typeinfo/ti_Along.o: std/typeinfo/ti_Along.d
std/typeinfo/ti_Areal.o: std/typeinfo/ti_Areal.d
std/typeinfo/ti_Ashort.o: std/typeinfo/ti_Ashort.d
std/typeinfo/ti_byte.o: std/typeinfo/ti_byte.d
std/typeinfo/ti_C.o: std/typeinfo/ti_C.d
std/typeinfo/ti_cdouble.o: std/typeinfo/ti_cdouble.d
std/typeinfo/ti_cfloat.o: std/typeinfo/ti_cfloat.d
std/typeinfo/ti_char.o: std/typeinfo/ti_char.d
std/typeinfo/ti_creal.o: std/typeinfo/ti_creal.d
std/typeinfo/ti_dchar.o: std/typeinfo/ti_dchar.d
std/typeinfo/ti_delegate.o: std/typeinfo/ti_delegate.d
std/typeinfo/ti_double.o: std/typeinfo/ti_double.d
std/typeinfo/ti_float.o: std/typeinfo/ti_float.d
std/typeinfo/ti_idouble.o: std/typeinfo/ti_idouble.d
std/typeinfo/ti_ifloat.o: std/typeinfo/ti_ifloat.d
std/typeinfo/ti_int.o: std/typeinfo/ti_int.d
std/typeinfo/ti_ireal.o: std/typeinfo/ti_ireal.d
std/typeinfo/ti_long.o: std/typeinfo/ti_long.d
std/typeinfo/ti_ptr.o: std/typeinfo/ti_ptr.d
std/typeinfo/ti_real.o: std/typeinfo/ti_real.d
std/typeinfo/ti_short.o: std/typeinfo/ti_short.d
std/typeinfo/ti_ubyte.o: std/typeinfo/ti_ubyte.d
std/typeinfo/ti_uint.o: std/typeinfo/ti_uint.d
std/typeinfo/ti_ulong.o: std/typeinfo/ti_ulong.d
std/typeinfo/ti_ushort.o: std/typeinfo/ti_ushort.d
std/typeinfo/ti_void.o: std/typeinfo/ti_void.d
std/typeinfo/ti_wchar.d: std/typeinfo/ti_wchar.o