2011-03-28 09:26:35 +04:00
|
|
|
#CC = gcc-4.3
|
2011-02-11 08:55:03 +03:00
|
|
|
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-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-03-26 06:29:54 +03:00
|
|
|
VIDEODRIVERS = $(patsubst %.c,%.o,$(wildcard kernel/core/video/*.c))
|
2011-04-18 02:44:29 +04:00
|
|
|
BINARIES = initrd/bin/hello initrd/bin/echo initrd/bin/yes initrd/bin/cat initrd/bin/sh initrd/bin/clear
|
2011-04-16 06:48:20 +04:00
|
|
|
UTILITIES = util/bin/readelf util/bin/typewriter
|
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-10-28 02:39:40 +04:00
|
|
|
BEG = util/mk-beg
|
|
|
|
END = util/mk-end
|
|
|
|
INFO = util/mk-info
|
|
|
|
ERRORS = 2>>/tmp/.build-errors
|
|
|
|
ERRORSS = >>/tmp/.build-errors
|
|
|
|
|
|
|
|
BEGRM = util/mk-beg-rm
|
|
|
|
ENDRM = util/mk-end-rm
|
2011-01-17 22:58:31 +03:00
|
|
|
|
2011-10-28 01:36:56 +04:00
|
|
|
.PHONY: all system clean clean-hard clean-soft clean-docs clean-bin clean-aux clean-core clean-boot install run docs utils
|
2011-04-11 08:08:34 +04:00
|
|
|
.SECONDARY:
|
2011-01-17 22:58:31 +03:00
|
|
|
|
2011-04-12 00:25:26 +04:00
|
|
|
all: .passed system bootdisk.img docs utils
|
2011-03-18 05:45:26 +03:00
|
|
|
system: toaruos-initrd toaruos-kernel
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2011-05-08 04:21:09 +04:00
|
|
|
install: system
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "CP" "Installing to /boot..."
|
2011-02-13 01:47:20 +03:00
|
|
|
@cp toaruos-kernel /boot/toaruos-kernel
|
|
|
|
@cp toaruos-initrd /boot/toaruos-initrd
|
2011-10-28 02:39:40 +04:00
|
|
|
@${END} "CP" "Installed to /boot"
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2011-05-08 04:21:09 +04:00
|
|
|
run: system
|
2011-03-29 01:29:59 +04:00
|
|
|
${EMU} -kernel toaruos-kernel -initrd toaruos-initrd -append vid=qemu -serial stdio -vga std
|
2011-01-29 23:52:44 +03:00
|
|
|
|
2011-05-08 04:21:09 +04:00
|
|
|
kvm: system
|
|
|
|
${EMU} -kernel toaruos-kernel -initrd toaruos-initrd -append vid=qemu -serial stdio -vga std -enable-kvm
|
|
|
|
|
2011-04-07 01:54:57 +04:00
|
|
|
utils: ${UTILITIES}
|
|
|
|
|
2011-04-12 00:25:26 +04:00
|
|
|
.passed:
|
2011-04-12 00:13:34 +04:00
|
|
|
@util/check-reqs > /dev/null
|
2011-04-12 00:25:26 +04:00
|
|
|
@touch .passed
|
2011-04-12 00:13:34 +04: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
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "docs" "Generating documentation..."
|
|
|
|
@pdflatex -draftmode -halt-on-error -output-directory docs/ docs/core.tex > /dev/null ${ERRORS}
|
|
|
|
@makeindex -q docs/*.idx ${ERRORS}
|
|
|
|
@pdflatex -halt-on-error -output-directory docs/ docs/core.tex > /dev/null ${ERRORS}
|
|
|
|
@${END} "docs" "Generated documentation"
|
2011-03-18 05:45:26 +03:00
|
|
|
|
2011-02-19 07:22:25 +03:00
|
|
|
################
|
|
|
|
# Kernel #
|
|
|
|
################
|
2011-03-26 06:29:54 +03:00
|
|
|
toaruos-kernel: kernel/start.o kernel/link.ld kernel/main.o ${MODULES} ${FILESYSTEMS} ${VIDEODRIVERS}
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "LD""$<"
|
|
|
|
@${LD} -T kernel/link.ld -o toaruos-kernel kernel/*.o kernel/core/*.o kernel/core/fs/*.o kernel/core/video/*.o ${ERRORS}
|
|
|
|
@${END} "LD" "$<"
|
|
|
|
@${INFO} "--" "Kernel is ready!"
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2011-02-28 06:08:55 +03:00
|
|
|
kernel/start.o: kernel/start.s
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "yasm" "$<"
|
|
|
|
@${YASM} -f elf -o kernel/start.o kernel/start.s ${ERRORS}
|
|
|
|
@${END} "yasm" "$<"
|
2011-02-05 22:27:04 +03:00
|
|
|
|
2011-01-16 04:01:19 +03:00
|
|
|
%.o: %.c
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "CC" "$<"
|
|
|
|
@${CC} ${CFLAGS} -I./kernel/include -c -o $@ $< ${ERRORS}
|
|
|
|
@${END} "CC" "$<"
|
2011-01-17 22:58:31 +03:00
|
|
|
|
2011-02-19 07:22:25 +03:00
|
|
|
################
|
|
|
|
# Ram disk #
|
|
|
|
################
|
2011-04-07 01:50:37 +04:00
|
|
|
toaruos-initrd: initrd/boot/kernel initrd/boot/stage2 initrd/bs.bmp ${BINARIES}
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "initrd" "Generating initial RAM disk"
|
2011-03-22 08:14:54 +03:00
|
|
|
@# Get rid of the old one
|
2011-02-13 01:47:20 +03:00
|
|
|
@-rm -f toaruos-initrd
|
2011-10-28 02:39:40 +04:00
|
|
|
@${GENEXT} -d initrd -q -b 4096 toaruos-initrd ${ERRORS}
|
|
|
|
@${END} "initrd" "Generated initial RAM disk"
|
|
|
|
@${INFO} "--" "HDD image is ready!"
|
2011-02-21 05:15:39 +03:00
|
|
|
|
|
|
|
### Ram Disk installers...
|
|
|
|
|
2011-03-22 08:14:54 +03:00
|
|
|
# Second stage bootloader
|
|
|
|
initrd/boot/stage2: bootloader/stage2.bin
|
|
|
|
@mkdir -p initrd/boot
|
2011-03-22 08:48:07 +03:00
|
|
|
@cp bootloader/stage2.bin initrd/boot/stage2
|
2011-03-22 08:14:54 +03:00
|
|
|
|
2011-02-21 05:15:39 +03:00
|
|
|
# Kernel
|
2011-03-22 08:14:54 +03:00
|
|
|
initrd/boot/kernel: toaruos-kernel
|
|
|
|
@mkdir -p initrd/boot
|
|
|
|
@cp toaruos-kernel initrd/boot/kernel
|
2011-02-21 05:15:39 +03:00
|
|
|
|
2011-03-22 07:50:50 +03:00
|
|
|
################
|
|
|
|
# Utilities #
|
|
|
|
################
|
|
|
|
|
2011-04-16 06:48:20 +04:00
|
|
|
util/bin/%: util/%.c
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "CC" "$<"
|
|
|
|
@${CC} ${NATIVEFLAGS} -o $@ $< ${ERRORS}
|
|
|
|
@${END} "CC" "$<"
|
2011-04-07 01:50:37 +04:00
|
|
|
|
|
|
|
################
|
|
|
|
# Userspace #
|
|
|
|
################
|
|
|
|
loader/crtbegin.o: loader/crtbegin.s
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "yasm" "$<"
|
|
|
|
@${YASM} -f elf32 -o $@ $< ${ERRORS}
|
|
|
|
@${END} "yasm" "$<"
|
2011-04-07 01:50:37 +04:00
|
|
|
|
2011-04-12 01:51:31 +04:00
|
|
|
initrd/bin/%: loader/%.o loader/crtbegin.o loader/syscall.o
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "LD" "$<"
|
|
|
|
@${LD} -T loader/link.ld -o $@ $< ${ERRORS}
|
|
|
|
@${END} "LD" "$<"
|
2011-04-07 01:50:37 +04:00
|
|
|
|
|
|
|
loader/%.o: loader/%.c
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "CC" "$<"
|
|
|
|
@${CC} ${CFLAGS} -c -o $@ $< ${ERRORS}
|
|
|
|
@${END} "CC" "$<"
|
2011-04-07 01:50:37 +04:00
|
|
|
|
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
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "CC" "$<"
|
|
|
|
@${GCC} ${CFLAGS} -c -o $@ $< ${ERRORS}
|
|
|
|
@${END} "CC" "$<"
|
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-10-28 02:39:40 +04:00
|
|
|
@${BEG} "yasm" "$<"
|
|
|
|
@${YASM} -f elf32 -p gas -o $@ $< ${ERRORS}
|
|
|
|
@${END} "yasm" "$<"
|
2011-02-21 05:15:39 +03:00
|
|
|
|
2011-02-21 12:11:30 +03:00
|
|
|
bootloader/stage1.bin: bootloader/stage1/main.o bootloader/stage1/start.o bootloader/stage1/link.ld
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "LD" "$<"
|
|
|
|
@${LD} -o bootloader/stage1.bin -T bootloader/stage1/link.ld bootloader/stage1/start.o bootloader/stage1/main.o ${ERRORS}
|
|
|
|
@${END} "LD" "$<"
|
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
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "CC" "$<"
|
|
|
|
@${GCC} ${CFLAGS} -I./kernel/include -c -o $@ $< ${ERRORS}
|
|
|
|
@${END} "CC" "$<"
|
2011-02-21 22:29:09 +03:00
|
|
|
|
2011-02-22 04:36:18 +03:00
|
|
|
bootloader/stage2/start.o: bootloader/stage2/start.s
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "yasm" "$<"
|
|
|
|
@${YASM} -f elf32 -p gas -o $@ $< ${ERRORS}
|
|
|
|
@${END} "yasm" "$<"
|
2011-02-21 22:29:09 +03:00
|
|
|
|
2011-02-22 04:36:18 +03:00
|
|
|
bootloader/stage2.bin: bootloader/stage2/main.o bootloader/stage2/start.o bootloader/stage2/link.ld
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "LD" "$<"
|
|
|
|
@${LD} -o bootloader/stage2.bin -T bootloader/stage2/link.ld bootloader/stage2/start.o bootloader/stage2/main.o ${ERRORS}
|
|
|
|
@${END} "LD" "$<"
|
2011-02-21 22:29:09 +03:00
|
|
|
|
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
|
|
|
@cat bootloader/stage1.bin bootloader/stage2.bin > bootdisk.img
|
2011-10-28 02:39:40 +04:00
|
|
|
@${INFO} "--" "Bootdisk is ready!"
|
2011-02-22 04:36:18 +03:00
|
|
|
|
2011-02-21 22:29:09 +03:00
|
|
|
###############
|
|
|
|
# clean #
|
|
|
|
###############
|
2011-10-27 03:39:36 +04:00
|
|
|
|
|
|
|
clean-soft:
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEGRM} "RM" "Cleaning modules..."
|
2011-02-13 01:47:20 +03:00
|
|
|
@-rm -f kernel/*.o
|
|
|
|
@-rm -f kernel/core/*.o
|
|
|
|
@-rm -f kernel/core/fs/*.o
|
2011-03-26 06:29:54 +03:00
|
|
|
@-rm -f kernel/core/video/*.o
|
2011-10-28 02:39:40 +04:00
|
|
|
@${ENDRM} "RM" "Cleaned modules."
|
2011-10-27 03:39:36 +04:00
|
|
|
|
|
|
|
clean-docs:
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEGRM} "RM" "Cleaning documentation..."
|
2011-10-27 03:39:36 +04:00
|
|
|
@-rm -f docs/*.pdf docs/*.aux docs/*.log docs/*.out
|
|
|
|
@-rm -f docs/*.idx docs/*.ind docs/*.toc docs/*.ilg
|
2011-10-28 02:39:40 +04:00
|
|
|
@${ENDRM} "RM" "Cleaned documentation"
|
2011-10-27 03:39:36 +04:00
|
|
|
|
|
|
|
clean-boot:
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEGRM} "RM" "Cleaning bootloader..."
|
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
|
2011-03-22 08:59:17 +03:00
|
|
|
@-rm -f -r initrd/boot
|
2011-02-22 08:51:59 +03:00
|
|
|
@-rm -f bootdisk.img
|
2011-10-28 02:39:40 +04:00
|
|
|
@${ENDRM} "RM" "Cleaned bootloader"
|
2011-10-27 03:39:36 +04:00
|
|
|
|
|
|
|
clean-bin:
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEGRM} "RM" "Cleaning native binaries..."
|
2011-10-27 03:39:36 +04:00
|
|
|
@-rm -f initrd/bin/*
|
2011-10-28 02:39:40 +04:00
|
|
|
@${ENDRM} "RM" "Cleaned native binaries"
|
2011-10-27 03:39:36 +04:00
|
|
|
|
|
|
|
clean-aux:
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEGRM} "RM" "Cleaning auxillary files..."
|
2011-10-27 03:39:36 +04:00
|
|
|
@-rm -f loader/*.o
|
2011-03-22 07:50:50 +03:00
|
|
|
@-rm -f util/bin/*
|
2011-10-28 02:39:40 +04:00
|
|
|
@${ENDRM} "RM" "Cleaned auxillary files"
|
2011-10-27 03:39:36 +04:00
|
|
|
|
|
|
|
clean-core:
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEGRM} "RM" "Cleaning final output..."
|
2011-10-27 03:39:36 +04:00
|
|
|
@-rm -f toaruos-kernel
|
|
|
|
@-rm -f toaruos-initrd
|
2011-10-28 01:36:56 +04:00
|
|
|
@-rm -f .passed
|
2011-10-28 02:39:40 +04:00
|
|
|
@${ENDRM} "RM" "Cleaned final output"
|
2011-10-27 03:39:36 +04:00
|
|
|
|
2011-10-28 01:36:56 +04:00
|
|
|
clean: clean-soft clean-boot clean-core
|
2011-10-28 02:39:40 +04:00
|
|
|
@${INFO} "--" "Finished soft cleaning"
|
2011-10-28 01:36:56 +04:00
|
|
|
|
|
|
|
clean-hard: clean clean-bin clean-aux clean-docs
|
2011-10-28 02:39:40 +04:00
|
|
|
@${INFO} "--" "Finished hard cleaning"
|
2011-04-18 02:44:29 +04:00
|
|
|
|
|
|
|
|
|
|
|
# vim:noexpandtab
|
|
|
|
# vim:tabstop=4
|
|
|
|
# vim:shiftwidth=4
|