2011-02-11 08:55:03 +03:00
|
|
|
#CC = gcc
|
|
|
|
CC = clang
|
2011-03-22 07:50:50 +03:00
|
|
|
# Sometimes we just have to use GCC
|
2011-02-21 12:11:30 +03:00
|
|
|
GCC = gcc
|
2011-03-22 07:50:50 +03:00
|
|
|
# CFLAGS for core components
|
2011-03-02 02:48:39 +03:00
|
|
|
CFLAGS = -Wall -Wextra -pedantic -m32 -O0 -std=c99 -finline-functions -fno-stack-protector -nostdinc -ffreestanding -Wno-unused-function -Wno-unused-parameter -g
|
2011-03-22 07:50:50 +03:00
|
|
|
# CFLAGS for native utils
|
2011-03-22 07:51:30 +03:00
|
|
|
NATIVEFLAGS = -std=c99 -g -pedantic -Wall -Wextra -Wno-unused-parameter
|
2011-03-22 07:50:50 +03:00
|
|
|
# Linker for core
|
2011-02-11 08:55:03 +03:00
|
|
|
LD = ld -m elf_i386
|
2011-02-21 05:15:39 +03:00
|
|
|
YASM = yasm
|
2011-02-09 23:32:49 +03:00
|
|
|
ECHO = `which echo` -e
|
2011-03-22 07:50:50 +03:00
|
|
|
# Feel free to be specific, but I'd rather you not be.
|
2011-02-13 01:47:20 +03:00
|
|
|
MODULES = $(patsubst %.c,%.o,$(wildcard kernel/core/*.c))
|
|
|
|
FILESYSTEMS = $(patsubst %.c,%.o,$(wildcard kernel/core/fs/*.c))
|
2011-02-10 09:59:06 +03:00
|
|
|
EMU = qemu
|
2011-02-10 00:33:03 +03:00
|
|
|
GENEXT = genext2fs
|
2011-02-19 07:22:25 +03:00
|
|
|
DD = dd conv=notrunc
|
2011-01-17 22:58:31 +03:00
|
|
|
|
2011-03-19 03:35:51 +03:00
|
|
|
.PHONY: all system clean install run docs
|
2011-01-17 22:58:31 +03:00
|
|
|
|
2011-03-18 05:45:26 +03:00
|
|
|
all: system bootdisk.img docs
|
|
|
|
system: toaruos-initrd toaruos-kernel
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2011-02-21 21:03:58 +03:00
|
|
|
install: toaruos-initrd toaruos-kernel
|
2011-02-10 21:59:44 +03:00
|
|
|
@${ECHO} -n "\033[34m -- Installing to /boot...\033[0m"
|
2011-02-13 01:47:20 +03:00
|
|
|
@cp toaruos-kernel /boot/toaruos-kernel
|
|
|
|
@cp toaruos-initrd /boot/toaruos-initrd
|
2011-02-10 21:59:44 +03:00
|
|
|
@${ECHO} "\r\033[34;1m -- Kernel and ramdisk installed.\033[0m"
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2011-02-13 01:47:20 +03:00
|
|
|
run: toaruos-kernel toaruos-initrd
|
|
|
|
${EMU} -kernel toaruos-kernel -initrd toaruos-initrd -serial stdio
|
2011-01-29 23:52:44 +03:00
|
|
|
|
2011-03-18 05:45:26 +03:00
|
|
|
#################
|
|
|
|
# Documentation #
|
|
|
|
#################
|
2011-03-19 03:18:08 +03:00
|
|
|
docs: docs/core.pdf
|
2011-03-18 05:45:26 +03:00
|
|
|
|
2011-03-19 03:18:08 +03:00
|
|
|
docs/core.pdf: docs/*.tex
|
|
|
|
@${ECHO} -n "\033[32m docs Generating documentation..."
|
2011-03-19 03:57:10 +03:00
|
|
|
@pdflatex -draftmode -halt-on-error -output-directory docs/ docs/core.tex > /dev/null
|
2011-03-19 03:18:08 +03:00
|
|
|
@makeindex -q docs/*.idx
|
|
|
|
@pdflatex -halt-on-error -output-directory docs/ docs/core.tex > /dev/null
|
|
|
|
@${ECHO} "\r\033[32;1m docs Generated documentation PDF."
|
2011-03-18 05:45:26 +03:00
|
|
|
|
2011-02-19 07:22:25 +03:00
|
|
|
################
|
|
|
|
# Kernel #
|
|
|
|
################
|
2011-02-13 01:47:20 +03:00
|
|
|
toaruos-kernel: kernel/start.o kernel/link.ld kernel/main.o ${MODULES} ${FILESYSTEMS}
|
2011-02-10 21:59:44 +03:00
|
|
|
@${ECHO} -n "\033[32m LD $<\033[0m"
|
2011-02-13 01:47:20 +03:00
|
|
|
@${LD} -T kernel/link.ld -o toaruos-kernel kernel/*.o kernel/core/*.o kernel/core/fs/*.o
|
2011-02-10 21:59:44 +03:00
|
|
|
@${ECHO} "\r\033[32;1m LD $<\033[0m"
|
2011-02-22 04:44:09 +03:00
|
|
|
@${ECHO} "\033[34;1m -- Kernel is ready!\033[0m"
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2011-02-28 06:08:55 +03:00
|
|
|
kernel/start.o: kernel/start.s
|
2011-02-21 22:21:28 +03:00
|
|
|
@${ECHO} -n "\033[32m yasm $<\033[0m"
|
2011-02-28 06:08:55 +03:00
|
|
|
@${YASM} -f elf -o kernel/start.o kernel/start.s
|
2011-02-21 22:21:28 +03:00
|
|
|
@${ECHO} "\r\033[32;1m yasm $<\033[0m"
|
2011-02-05 22:27:04 +03:00
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
%.o: %.c
|
2011-02-10 21:59:44 +03:00
|
|
|
@${ECHO} -n "\033[32m CC $<\033[0m"
|
2011-02-13 01:47:20 +03:00
|
|
|
@${CC} ${CFLAGS} -I./kernel/include -c -o $@ $<
|
2011-02-10 21:59:44 +03:00
|
|
|
@${ECHO} "\r\033[32;1m CC $<\033[0m"
|
2011-01-17 22:58:31 +03:00
|
|
|
|
2011-02-19 07:22:25 +03:00
|
|
|
################
|
|
|
|
# Ram disk #
|
|
|
|
################
|
2011-02-22 04:41:37 +03:00
|
|
|
toaruos-initrd: initrd/kernel
|
2011-02-21 05:15:39 +03:00
|
|
|
@${ECHO} -n "\033[32m initrd Generating initial RAM disk\033[0m"
|
2011-02-13 01:47:20 +03:00
|
|
|
@-rm -f toaruos-initrd
|
|
|
|
@${GENEXT} -d initrd -q -b 249 toaruos-initrd
|
2011-02-21 05:15:39 +03:00
|
|
|
@${ECHO} "\r\033[32;1m initrd Generated initial RAM disk image\033[0m"
|
2011-02-22 04:44:09 +03:00
|
|
|
@${ECHO} "\033[34;1m -- HDD image is ready!\033[0m"
|
2011-02-21 05:15:39 +03:00
|
|
|
|
|
|
|
### Ram Disk installers...
|
|
|
|
|
|
|
|
# Kernel
|
2011-02-21 22:29:09 +03:00
|
|
|
initrd/kernel: toaruos-kernel
|
|
|
|
@cp toaruos-kernel initrd/kernel
|
2011-02-21 05:15:39 +03:00
|
|
|
|
2011-03-22 07:50:50 +03:00
|
|
|
################
|
|
|
|
# Utilities #
|
|
|
|
################
|
|
|
|
|
|
|
|
util/bin/mrboots-installer: util/mrboots-installer.c
|
|
|
|
@${ECHO} -n "\033[32m CC $<\033[0m"
|
|
|
|
@${CC} ${NATIVEFLAGS} -o $@ $<
|
|
|
|
@${ECHO} "\r\033[32;1m CC $<\033[0m"
|
|
|
|
|
2011-02-19 07:22:25 +03:00
|
|
|
################
|
|
|
|
# Bootloader #
|
|
|
|
################
|
2011-02-21 22:29:09 +03:00
|
|
|
|
|
|
|
# Stage 1
|
2011-02-21 12:11:30 +03:00
|
|
|
bootloader/stage1/main.o: bootloader/stage1/main.c
|
|
|
|
@${ECHO} -n "\033[32m CC $<\033[0m"
|
2011-02-22 04:36:18 +03:00
|
|
|
@${GCC} ${CFLAGS} -c -o $@ $<
|
2011-02-21 12:11:30 +03:00
|
|
|
@${ECHO} "\r\033[32;1m CC $<\033[0m"
|
2011-02-19 07:22:25 +03:00
|
|
|
|
2011-02-21 12:11:30 +03:00
|
|
|
bootloader/stage1/start.o: bootloader/stage1/start.s
|
2011-02-21 05:15:39 +03:00
|
|
|
@${ECHO} -n "\033[32m yasm $<\033[0m"
|
2011-02-21 12:11:30 +03:00
|
|
|
@${YASM} -f elf32 -p gas -o $@ $<
|
2011-02-21 05:15:39 +03:00
|
|
|
@${ECHO} "\r\033[32;1m yasm $<\033[0m"
|
|
|
|
|
2011-02-21 12:11:30 +03:00
|
|
|
bootloader/stage1.bin: bootloader/stage1/main.o bootloader/stage1/start.o bootloader/stage1/link.ld
|
|
|
|
@${ECHO} -n "\033[32m ld $<\033[0m"
|
|
|
|
@${LD} -o bootloader/stage1.bin -T bootloader/stage1/link.ld bootloader/stage1/start.o bootloader/stage1/main.o
|
|
|
|
@${ECHO} "\r\033[32;1m ld $<\033[0m"
|
2011-02-19 07:22:25 +03:00
|
|
|
|
2011-02-21 22:29:09 +03:00
|
|
|
# Stage 2
|
|
|
|
bootloader/stage2/main.o: bootloader/stage2/main.c
|
|
|
|
@${ECHO} -n "\033[32m CC $<\033[0m"
|
2011-02-22 08:51:06 +03:00
|
|
|
@${GCC} ${CFLAGS} -I./kernel/include -c -o $@ $<
|
2011-02-21 22:29:09 +03:00
|
|
|
@${ECHO} "\r\033[32;1m CC $<\033[0m"
|
|
|
|
|
2011-02-22 04:36:18 +03:00
|
|
|
bootloader/stage2/start.o: bootloader/stage2/start.s
|
2011-02-21 22:29:09 +03:00
|
|
|
@${ECHO} -n "\033[32m yasm $<\033[0m"
|
|
|
|
@${YASM} -f elf32 -p gas -o $@ $<
|
|
|
|
@${ECHO} "\r\033[32;1m yasm $<\033[0m"
|
|
|
|
|
2011-02-22 04:36:18 +03:00
|
|
|
bootloader/stage2.bin: bootloader/stage2/main.o bootloader/stage2/start.o bootloader/stage2/link.ld
|
2011-02-21 22:29:09 +03:00
|
|
|
@${ECHO} -n "\033[32m ld $<\033[0m"
|
2011-02-22 04:36:18 +03:00
|
|
|
@${LD} -o bootloader/stage2.bin -T bootloader/stage2/link.ld bootloader/stage2/start.o bootloader/stage2/main.o
|
2011-02-21 22:29:09 +03:00
|
|
|
@${ECHO} "\r\033[32;1m ld $<\033[0m"
|
|
|
|
|
2011-02-22 05:35:37 +03:00
|
|
|
##############
|
|
|
|
# bootdisk #
|
|
|
|
##############
|
2011-03-22 07:50:50 +03:00
|
|
|
bootdisk.img: bootloader/stage1.bin bootloader/stage2.bin util/bin/mrboots-installer
|
2011-02-22 04:41:37 +03:00
|
|
|
@${ECHO} -n "\033[34m -- Building bootdisk.img...\033[0m"
|
|
|
|
@cat bootloader/stage1.bin bootloader/stage2.bin > bootdisk.img
|
|
|
|
@${ECHO} "\r\033[34;1m -- Bootdisk is ready! \033[0m"
|
2011-02-22 04:36:18 +03:00
|
|
|
|
2011-02-21 22:29:09 +03:00
|
|
|
###############
|
|
|
|
# clean #
|
|
|
|
###############
|
2011-01-16 04:01:19 +03:00
|
|
|
clean:
|
2011-02-21 05:15:39 +03:00
|
|
|
@${ECHO} -n "\033[31m RM Cleaning... \033[0m"
|
2011-02-13 01:47:20 +03:00
|
|
|
@-rm -f toaruos-kernel
|
|
|
|
@-rm -f toaruos-initrd
|
|
|
|
@-rm -f kernel/*.o
|
|
|
|
@-rm -f kernel/core/*.o
|
|
|
|
@-rm -f kernel/core/fs/*.o
|
2011-02-21 12:11:30 +03:00
|
|
|
@-rm -f bootloader/stage1.bin
|
|
|
|
@-rm -f bootloader/stage1/*.o
|
2011-02-21 22:29:09 +03:00
|
|
|
@-rm -f bootloader/stage2.bin
|
|
|
|
@-rm -f bootloader/stage2/*.o
|
|
|
|
@-rm -f initrd/kernel
|
2011-02-22 08:51:59 +03:00
|
|
|
@-rm -f bootdisk.img
|
2011-03-19 03:18:08 +03:00
|
|
|
@-rm -f docs/*.pdf docs/*.aux docs/*.log docs/*.out
|
|
|
|
@-rm -f docs/*.idx docs/*.ind docs/*.toc docs/*.ilg
|
2011-03-22 07:50:50 +03:00
|
|
|
@-rm -f util/bin/*
|
2011-02-21 05:15:39 +03:00
|
|
|
@${ECHO} "\r\033[31;1m RM Finished cleaning.\033[0m\033[K"
|