toaruos/Makefile

237 lines
6.7 KiB
Makefile
Raw Normal View History

# ToAruOS Primary Build Script
# This script will pull either clang (with -fcolor-diagnostics), gcc (with no extra options), or cc
2012-10-10 08:00:50 +04:00
#
ifeq ($(CCC_ANALYZE),yes)
else
CC = `util/compiler`
2012-10-10 08:00:50 +04:00
endif
# CFLAGS for core components
CFLAGS = -Wall -Wextra -pedantic -m32 -O0 -std=c99 -finline-functions -fno-stack-protector -nostdinc -ffreestanding -Wno-unused-function -Wno-unused-parameter -g
# CFLAGS for native utils
2011-03-22 07:51:30 +03:00
NATIVEFLAGS = -std=c99 -g -pedantic -Wall -Wextra -Wno-unused-parameter
# Linker for core
LD = ld -m elf_i386
YASM = yasm
# Feel free to be specific, but I'd rather you not be.
FILESYSTEMS = $(patsubst %.c,%.o,$(wildcard kernel/fs/*.c))
VIDEODRIVERS = $(patsubst %.c,%.o,$(wildcard kernel/video/*.c))
DEVICES = $(patsubst %.c,%.o,$(wildcard kernel/devices/*.c))
VIRTUALMEM = $(patsubst %.c,%.o,$(wildcard kernel/mem/*.c))
MISCMODS = $(patsubst %.c,%.o,$(wildcard kernel/misc/*.c))
SYSTEM = $(patsubst %.c,%.o,$(wildcard kernel/sys/*.c))
DATASTRUCTS = $(patsubst %.c,%.o,$(wildcard kernel/ds/*.c))
CPUBITS = $(patsubst %.c,%.o,$(wildcard kernel/cpu/*.c))
REALEMU = $(patsubst %.c,%.o,$(wildcard kernel/v8086/*.c))
SUBMODULES = ${MODULES} ${FILESYSTEMS} ${VIDEODRIVERS} ${DEVICES} ${VIRTUALMEM} ${MISCMODS} ${SYSTEM} ${DATASTRUCTS} ${CPUBITS} ${REALEMU}
UTILITIES = util/bin/readelf util/bin/typewriter util/bin/bim
EMU = qemu-system-i386
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
2012-01-19 05:52:11 +04:00
ERRORS = 2>>/tmp/.`whoami`-build-errors || util/mk-error
ERRORSS = >>/tmp/.`whoami`-build-errors || util/mk-error
2011-10-28 02:39:40 +04:00
BEGRM = util/mk-beg-rm
ENDRM = util/mk-end-rm
2011-01-17 22:58:31 +03:00
2012-10-17 07:42:37 +04:00
EMUARGS = -kernel toaruos-kernel -m 1024 -serial stdio -vga std -hda toaruos-disk.img -k en-us -no-frame -rtc base=localtime
EMUKVM = -enable-kvm
2012-02-06 03:40:19 +04:00
.PHONY: all system clean clean-once clean-hard clean-soft clean-docs clean-bin clean-aux clean-core update-version install run docs utils
.SECONDARY:
2011-01-17 22:58:31 +03:00
all: .passed system tags
aux: utils docs
2012-04-11 21:47:39 +04:00
system: .passed toaruos-disk.img toaruos-kernel
2011-01-16 04:01:19 +03:00
install: system
2011-10-28 02:39:40 +04:00
@${BEG} "CP" "Installing to /boot..."
@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
# Various different quick options
run: system
${EMU} ${EMUARGS} -append "vid=qemu hdd"
kvm: system
${EMU} ${EMUARGS} ${EMUKVM} -append "vid=qemu hdd"
vga: system
${EMU} ${EMUARGS} -append "vgaterm hdd"
vga-kvm: system
${EMU} ${EMUARGS} ${EMUKVM} -append "vgaterm hdd"
term: system
${EMU} ${EMUARGS} -append "vid=qemu single hdd"
term-kvm: system
${EMU} ${EMUARGS} ${EMUKVM} -append "vid=qemu single hdd"
2012-12-03 09:43:54 +04:00
debug: system
${EMU} ${EMUARGS} -append "logtoserial=0 vid=qemu hdd"
2012-08-21 09:26:22 +04:00
run-config: system
util/config-parser | xargs ${EMU}
test: system
python util/run-tests.py 2>/dev/null
2011-04-07 01:54:57 +04:00
utils: ${UTILITIES}
.passed:
@util/check-reqs > /dev/null
@touch .passed
#################
# Documentation #
#################
2011-03-19 03:18:08 +03:00
docs: docs/core.pdf
2012-02-06 03:40:19 +04: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-02-19 07:22:25 +03:00
################
# Kernel #
################
2012-02-06 03:43:32 +04:00
toaruos-kernel: kernel/start.o kernel/link.ld kernel/main.o ${SUBMODULES} .passed
2011-10-29 09:33:57 +04:00
@${BEG} "LD" "$<"
@${LD} -T kernel/link.ld -o toaruos-kernel kernel/*.o ${SUBMODULES} ${ERRORS}
2011-10-28 02:39:40 +04:00
@${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
2012-01-29 03:06:07 +04:00
kernel/sys/version.o: kernel/*/*.c kernel/*.c
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
2012-04-11 22:07:16 +04:00
hdd/bin/%:
@cd userspace; make ../$@
2011-02-19 07:22:25 +03:00
################
# Ram disk #
################
toaruos-initrd: .passed
2011-10-28 02:39:40 +04:00
@${BEG} "initrd" "Generating initial RAM disk"
@# Get rid of the old one
@-rm -f toaruos-initrd
@#${GENEXT} -d initrd -q -b 20480 toaruos-initrd ${ERRORS}
@#${GENEXT} -d initrd -q -b 8192 toaruos-initrd ${ERRORS}
@${GENEXT} -d hdd -q -b 81920 toaruos-initrd ${ERRORS}
2011-10-28 02:39:40 +04:00
@${END} "initrd" "Generated initial RAM disk"
@${INFO} "--" "Ramdisk image is ready!"
####################
# Hard Disk Images #
####################
# TODO: Install Grub to one of these by pulling newest grub builds
# from the Grub2 website.
hdd:
@mkdir hdd
toaruos-disk.img: hdd userspace/*.c userspace/*.cpp
@${BEG} "hdd" "Generating a Hard Disk image..."
@-rm -f toaruos-disk.img
2011-11-18 05:01:14 +04:00
@${GENEXT} -d hdd -q -b 131072 -N 4096 toaruos-disk.img ${ERRORS}
@${END} "hdd" "Generated Hard Disk image"
@${INFO} "--" "Hard disk image is ready!"
################
# Utilities #
################
util/bin/bim: userspace/bim.c
@${BEG} "CC" "$<"
2012-12-05 08:09:06 +04:00
@${CC} -std=c99 -posix -m32 -g -o $@ $< userspace/lib/wcwidth.c
@${END} "CC" "$<"
util/bin/%: util/%.c
2011-10-28 02:39:40 +04:00
@${BEG} "CC" "$<"
@${CC} ${NATIVEFLAGS} -o $@ $< ${ERRORS}
@${END} "CC" "$<"
################
# Userspace #
################
loader/crtbegin.o: loader/crtbegin.s
2011-10-28 02:39:40 +04:00
@${BEG} "yasm" "$<"
@${YASM} -f elf32 -o $@ $< ${ERRORS}
@${END} "yasm" "$<"
hdd/bin/%: loader/%.o loader/crtbegin.o loader/syscall.o
2011-10-28 02:39:40 +04:00
@${BEG} "LD" "$<"
@${LD} -T loader/link.ld -s -S -o $@ $< ${ERRORS}
2011-10-28 02:39:40 +04:00
@${END} "LD" "$<"
2012-01-27 11:38:08 +04:00
##############
# ctags #
##############
tags: kernel/*/*.c kernel/*.c userspace/*.c
@${BEG} "ctag" "Generating CTags..."
2012-05-31 13:37:17 +04:00
@ctags -R --c++-kinds=+p --fields=+iaS --extra=+q kernel userspace util
2012-01-27 11:38:08 +04:00
@${END} "ctag" "Generated CTags."
2011-02-21 22:29:09 +03:00
###############
# clean #
###############
clean-soft:
2011-10-28 02:39:40 +04:00
@${BEGRM} "RM" "Cleaning modules..."
@-rm -f kernel/*.o
@-rm -f ${SUBMODULES}
2011-10-28 02:39:40 +04:00
@${ENDRM} "RM" "Cleaned modules."
clean-docs:
2011-10-28 02:39:40 +04:00
@${BEGRM} "RM" "Cleaning documentation..."
@-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"
clean-bin:
2011-10-28 02:39:40 +04:00
@${BEGRM} "RM" "Cleaning native binaries..."
2012-04-11 21:47:39 +04:00
@-rm -f hdd/bin/*
2011-10-28 02:39:40 +04:00
@${ENDRM} "RM" "Cleaned native binaries"
clean-aux:
2011-10-28 02:39:40 +04:00
@${BEGRM} "RM" "Cleaning auxillary files..."
@-rm -f loader/*.o
@-rm -f util/bin/*
2011-10-28 02:39:40 +04:00
@${ENDRM} "RM" "Cleaned auxillary files"
clean-core:
2011-10-28 02:39:40 +04:00
@${BEGRM} "RM" "Cleaning final output..."
@-rm -f toaruos-kernel
@-rm -f toaruos-initrd
2011-10-28 02:39:40 +04:00
@${ENDRM} "RM" "Cleaned final output"
clean: clean-soft clean-core
2011-10-28 02:39:40 +04:00
@${INFO} "--" "Finished soft cleaning"
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
2011-12-27 05:23:58 +04:00
clean-disk:
@${BEGRM} "RM" "Deleting hard disk image..."
@-rm -f toaruos-disk.img
@${ENDRM} "RM" "Deleted hard disk image"
clean-once:
@${BEGRM} "RM" "Cleaning one-time files..."
@-rm -f .passed
@${ENDRM} "RM" "Cleaned one-time files"
2011-04-18 02:44:29 +04:00
# vim:noexpandtab
# vim:tabstop=4
# vim:shiftwidth=4