2011-10-28 03:19:39 +04:00
|
|
|
# ToAruOS Primary Build Script
|
2014-03-09 10:17:47 +04:00
|
|
|
|
|
|
|
# We always build with our targetted cross-compiler
|
|
|
|
ifneq ($(CCC_ANALYZE),yes)
|
2013-06-07 08:59:20 +04:00
|
|
|
CC = i686-pc-toaru-gcc
|
2012-10-10 08:00:50 +04:00
|
|
|
endif
|
2014-03-09 10:17:47 +04:00
|
|
|
|
2014-03-11 12:43:42 +04:00
|
|
|
NM = i686-pc-toaru-nm
|
|
|
|
|
2014-03-09 10:17:47 +04:00
|
|
|
# Build flags
|
2014-03-17 00:53:19 +04:00
|
|
|
CFLAGS = -O2 -std=c99
|
2014-03-09 10:17:47 +04:00
|
|
|
CFLAGS += -finline-functions -ffreestanding
|
|
|
|
CFLAGS += -Wall -Wextra -Wno-unused-function -Wno-unused-parameter
|
2014-03-11 18:58:12 +04:00
|
|
|
CFLAGS += -Wstrict-prototypes -pedantic -fno-omit-frame-pointer
|
2014-03-09 10:17:47 +04:00
|
|
|
|
|
|
|
# We have some pieces of assembly sitting around as well...
|
2011-02-21 05:15:39 +03:00
|
|
|
YASM = yasm
|
2014-03-09 09:46:43 +04:00
|
|
|
|
|
|
|
# All of the core parts of the kernel are built directly.
|
|
|
|
# TODO: Modules would be fantastic
|
2014-03-10 06:36:28 +04:00
|
|
|
KERNEL_OBJS = $(patsubst %.c,%.o,$(wildcard kernel/*/*.c))
|
|
|
|
KERNEL_OBJS += $(patsubst %.c,%.o,$(wildcard kernel/*/*/*.c))
|
|
|
|
|
|
|
|
# Loadable modules
|
|
|
|
MODULES = $(patsubst modules/%.c,hdd/mod/%.ko,$(wildcard modules/*.c))
|
2013-12-14 08:50:04 +04:00
|
|
|
|
2014-03-09 09:46:43 +04:00
|
|
|
# We also want to rebuild when a header changes.
|
|
|
|
# This is a naive approach, but it works...
|
|
|
|
HEADERS = $(shell find kernel/include/ -type f -name '*.h')
|
2011-12-15 08:15:47 +04:00
|
|
|
|
2014-03-09 09:46:43 +04:00
|
|
|
# We'll call out to our userspace build script if we
|
|
|
|
# see changes to any of the userspace sources as well.
|
|
|
|
USERSPACE = $(shell find userspace/ -type f -name '*.c')
|
|
|
|
USERSPACE += $(shell find userspace/ -type f -name '*.cpp')
|
|
|
|
USERSPACE += $(shell find userspace/ -type f -name '*.h')
|
|
|
|
|
|
|
|
# Pretty output utilities.
|
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
|
|
|
|
2014-03-09 09:46:43 +04:00
|
|
|
# Hard disk image generation
|
|
|
|
GENEXT = genext2fs
|
|
|
|
DISK_SIZE = `util/disk_size.sh`
|
|
|
|
DD = dd conv=notrunc
|
|
|
|
|
2014-03-16 04:51:33 +04:00
|
|
|
# Specify which modules should be included on startup.
|
|
|
|
# There are a few modules that are kinda required for a working system
|
|
|
|
# such as all of the dependencies needed to mount the root partition.
|
|
|
|
# We can also include things like the debug shell...
|
2014-03-17 05:39:03 +04:00
|
|
|
BOOT_MODULES := zero random serial
|
2014-03-16 07:05:07 +04:00
|
|
|
BOOT_MODULES += procfs tmpfs ata
|
2014-03-17 05:39:03 +04:00
|
|
|
#BOOT_MODULES += dospart
|
|
|
|
BOOT_MODULES += ext2
|
|
|
|
BOOT_MODULES += debug_shell
|
2014-03-17 02:13:27 +04:00
|
|
|
BOOT_MODULES += ps2mouse ps2kbd
|
2014-03-16 04:51:33 +04:00
|
|
|
|
|
|
|
# This is kinda silly. We're going to form an -initrd argument..
|
|
|
|
# which is basically -initrd "hdd/mod/%.ko,hdd/mod/%.ko..."
|
|
|
|
# for each of the modules listed above in BOOT_MODULES
|
|
|
|
COMMA := ,
|
|
|
|
EMPTY :=
|
|
|
|
SPACE := $(EMPTY) $(EMPTY)
|
|
|
|
BOOT_MODULES_X = -initrd "$(subst $(SPACE),$(COMMA),$(foreach mod,$(BOOT_MODULES),hdd/mod/$(mod).ko))"
|
|
|
|
|
2014-03-09 09:46:43 +04:00
|
|
|
# Emulator settings
|
|
|
|
EMU = qemu-system-i386
|
|
|
|
EMUARGS = -sdl -kernel toaruos-kernel -m 1024
|
|
|
|
EMUARGS += -serial stdio -vga std
|
|
|
|
EMUARGS += -hda toaruos-disk.img -k en-us -no-frame
|
|
|
|
EMUARGS += -rtc base=localtime -net nic,model=rtl8139 -net user
|
2014-03-16 04:51:33 +04:00
|
|
|
EMUARGS += $(BOOT_MODULES_X)
|
2014-03-09 09:46:43 +04:00
|
|
|
EMUKVM = -enable-kvm
|
2011-10-28 04:37:01 +04:00
|
|
|
|
2014-03-16 12:33:01 +04:00
|
|
|
DISK_ROOT = root=/dev/hda
|
|
|
|
|
2014-03-11 12:55:51 +04:00
|
|
|
.PHONY: all system install test
|
|
|
|
.PHONY: clean clean-soft clean-hard clean-bin clean-mods clean-core clean-disk clean-once
|
2014-03-16 06:48:51 +04:00
|
|
|
.PHONY: run vga term headless run-config
|
|
|
|
.PHONY: kvm vga-kvm term-kvm
|
2014-03-09 09:46:43 +04:00
|
|
|
|
|
|
|
# Prevents Make from removing intermediary files on failure
|
2011-04-11 08:08:34 +04:00
|
|
|
.SECONDARY:
|
2011-01-17 22:58:31 +03:00
|
|
|
|
2014-03-09 09:46:43 +04:00
|
|
|
# Disable built-in rules
|
|
|
|
.SUFFIXES:
|
|
|
|
|
2012-09-11 09:53:39 +04:00
|
|
|
all: .passed system tags
|
2014-03-10 06:36:28 +04:00
|
|
|
system: .passed toaruos-disk.img toaruos-kernel ${MODULES}
|
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
|
2011-10-28 02:39:40 +04:00
|
|
|
@${END} "CP" "Installed to /boot"
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2012-04-20 04:59:59 +04:00
|
|
|
# Various different quick options
|
2011-05-08 04:21:09 +04:00
|
|
|
run: system
|
2014-03-16 12:33:01 +04:00
|
|
|
${EMU} ${EMUARGS} -append "vid=qemu $(DISK_ROOT)"
|
2011-05-08 04:21:09 +04:00
|
|
|
kvm: system
|
2014-03-16 12:33:01 +04:00
|
|
|
${EMU} ${EMUARGS} ${EMUKVM} -append "vid=qemu $(DISK_ROOT)"
|
2012-04-13 08:21:38 +04:00
|
|
|
vga: system
|
2014-03-17 02:22:00 +04:00
|
|
|
${EMU} ${EMUARGS} -append "vgaterm $(DISK_ROOT)"
|
2012-04-20 04:59:59 +04:00
|
|
|
vga-kvm: system
|
2014-03-16 12:33:01 +04:00
|
|
|
${EMU} ${EMUARGS} ${EMUKVM} -append "vgaterm $(DISK_ROOT)"
|
2012-04-20 04:59:59 +04:00
|
|
|
term: system
|
2014-03-16 12:33:01 +04:00
|
|
|
${EMU} ${EMUARGS} -append "vid=qemu single $(DISK_ROOT)"
|
2012-04-20 04:59:59 +04:00
|
|
|
term-kvm: system
|
2014-03-16 12:33:01 +04:00
|
|
|
${EMU} ${EMUARGS} ${EMUKVM} -append "vid=qemu single $(DISK_ROOT)"
|
2013-11-28 07:15:28 +04:00
|
|
|
headless: system
|
2014-03-16 12:33:01 +04:00
|
|
|
${EMU} ${EMUARGS} -display none -append "vgaterm $(DISK_ROOT)"
|
2012-08-21 09:26:22 +04:00
|
|
|
run-config: system
|
2013-11-29 03:58:57 +04:00
|
|
|
util/config-parser ${EMU}
|
2012-04-13 08:21:38 +04:00
|
|
|
|
2012-09-02 13:24:25 +04:00
|
|
|
test: system
|
2014-02-13 01:33:19 +04:00
|
|
|
python2 util/run-tests.py 2>/dev/null
|
2012-09-02 13:24:25 +04:00
|
|
|
|
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-02-19 07:22:25 +03:00
|
|
|
################
|
|
|
|
# Kernel #
|
|
|
|
################
|
2014-03-10 06:36:28 +04:00
|
|
|
toaruos-kernel: kernel/start.o kernel/link.ld kernel/main.o kernel/symbols.o ${KERNEL_OBJS} .passed
|
2014-03-09 10:17:47 +04:00
|
|
|
@${BEG} "CC" "$<"
|
2014-03-10 06:36:28 +04:00
|
|
|
@${CC} -T kernel/link.ld -nostdlib -o toaruos-kernel kernel/*.o ${KERNEL_OBJS} -lgcc ${ERRORS}
|
2014-03-09 10:17:47 +04:00
|
|
|
@${END} "CC" "$<"
|
2011-10-28 02:39:40 +04:00
|
|
|
@${INFO} "--" "Kernel is ready!"
|
2011-01-16 04:01:19 +03:00
|
|
|
|
2014-03-10 06:36:28 +04:00
|
|
|
kernel/symbols.o: ${KERNEL_OBJS} util/generate_symbols.py
|
|
|
|
@-rm -f kernel/symbols.o
|
2014-03-11 12:43:42 +04:00
|
|
|
@${BEG} "nm" "Generating symbol list..."
|
2014-03-10 06:36:28 +04:00
|
|
|
@${CC} -T kernel/link.ld -nostdlib -o toaruos-kernel kernel/*.o ${KERNEL_OBJS} -lgcc ${ERRORS}
|
2014-03-11 12:43:42 +04:00
|
|
|
@${NM} toaruos-kernel -g | python2 util/generate_symbols.py > kernel/symbols.s
|
|
|
|
@${END} "nm" "Generated symbol list."
|
2014-03-10 06:36:28 +04:00
|
|
|
@${BEG} "yasm" "kernel/symbols.s"
|
|
|
|
@${YASM} -f elf -o $@ kernel/symbols.s ${ERRORS}
|
|
|
|
@${END} "yasm" "kernel/symbols.s"
|
|
|
|
|
2011-02-28 06:08:55 +03:00
|
|
|
kernel/start.o: kernel/start.s
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "yasm" "$<"
|
2014-03-10 06:36:28 +04:00
|
|
|
@${YASM} -f elf -o $@ $< ${ERRORS}
|
2011-10-28 02:39:40 +04:00
|
|
|
@${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
|
|
|
|
|
2014-03-10 10:31:13 +04:00
|
|
|
hdd/mod/%.ko: modules/%.c ${HEADERS}
|
2014-03-10 06:36:28 +04:00
|
|
|
@${BEG} "CC" "$< [module]"
|
2014-03-10 10:01:30 +04:00
|
|
|
@${CC} -T modules/link.ld -I./kernel/include -nostdlib ${CFLAGS} -c -o $@ $< ${ERRORS}
|
2014-03-10 06:36:28 +04:00
|
|
|
@${END} "CC" "$< [module]"
|
|
|
|
|
2014-03-09 09:46:43 +04:00
|
|
|
%.o: %.c ${HEADERS}
|
2011-10-28 02:39:40 +04:00
|
|
|
@${BEG} "CC" "$<"
|
2014-03-17 00:53:19 +04:00
|
|
|
@${CC} ${CFLAGS} -g -I./kernel/include -c -o $@ $< ${ERRORS}
|
2011-10-28 02:39:40 +04:00
|
|
|
@${END} "CC" "$<"
|
2011-01-17 22:58:31 +03:00
|
|
|
|
2011-10-28 04:37:01 +04:00
|
|
|
####################
|
|
|
|
# Hard Disk Images #
|
|
|
|
####################
|
|
|
|
|
2013-02-10 13:36:15 +04:00
|
|
|
.userspace-check: ${USERSPACE}
|
2014-02-13 01:33:19 +04:00
|
|
|
@cd userspace && python2 build.py
|
2012-12-10 07:56:56 +04:00
|
|
|
@touch .userspace-check
|
|
|
|
|
2014-03-11 11:18:51 +04:00
|
|
|
toaruos-disk.img: .userspace-check ${MODULES}
|
2011-10-28 04:37:01 +04:00
|
|
|
@${BEG} "hdd" "Generating a Hard Disk image..."
|
|
|
|
@-rm -f toaruos-disk.img
|
2013-08-04 11:04:22 +04:00
|
|
|
@${GENEXT} -B 4096 -d hdd -U -b ${DISK_SIZE} -N 4096 toaruos-disk.img ${ERRORS}
|
2011-10-28 04:37:01 +04:00
|
|
|
@${END} "hdd" "Generated Hard Disk image"
|
|
|
|
@${INFO} "--" "Hard disk image is ready!"
|
|
|
|
|
2012-01-27 11:38:08 +04:00
|
|
|
##############
|
|
|
|
# ctags #
|
|
|
|
##############
|
2013-02-20 09:10:05 +04:00
|
|
|
tags: kernel/*/*.c kernel/*.c .userspace-check
|
2012-01-27 11:38:08 +04:00
|
|
|
@${BEG} "ctag" "Generating CTags..."
|
2014-03-11 11:18:51 +04:00
|
|
|
@ctags -R --c++-kinds=+p --fields=+iaS --extra=+q kernel userspace modules util
|
2012-01-27 11:38:08 +04:00
|
|
|
@${END} "ctag" "Generated CTags."
|
|
|
|
|
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
|
2014-03-17 00:30:25 +04:00
|
|
|
@-rm -f kernel/*/*.o
|
2014-03-10 06:36:28 +04:00
|
|
|
@-rm -f ${KERNEL_OBJS}
|
2011-10-28 02:39:40 +04:00
|
|
|
@${ENDRM} "RM" "Cleaned modules."
|
2011-10-27 03:39:36 +04:00
|
|
|
|
|
|
|
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"
|
2011-10-27 03:39:36 +04:00
|
|
|
|
2014-03-11 12:55:51 +04:00
|
|
|
clean-mods:
|
|
|
|
@${BEGRM} "RM" "Cleaning kernel modules..."
|
|
|
|
@-rm -f hdd/mod/*
|
|
|
|
@${ENDRM} "RM" "Cleaned kernel modules"
|
|
|
|
|
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
|
2011-10-28 02:39:40 +04:00
|
|
|
@${ENDRM} "RM" "Cleaned final output"
|
2011-10-27 03:39:36 +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"
|
|
|
|
|
2011-10-28 04:37:01 +04:00
|
|
|
clean-once:
|
|
|
|
@${BEGRM} "RM" "Cleaning one-time files..."
|
|
|
|
@-rm -f .passed
|
|
|
|
@${ENDRM} "RM" "Cleaned one-time files"
|
|
|
|
|
2014-03-11 12:55:51 +04:00
|
|
|
clean: clean-soft clean-core
|
|
|
|
@${INFO} "--" "Finished soft cleaning"
|
|
|
|
|
|
|
|
clean-hard: clean clean-bin clean-mods
|
|
|
|
@${INFO} "--" "Finished hard cleaning"
|
|
|
|
|
|
|
|
|
2011-04-18 02:44:29 +04:00
|
|
|
# vim:noexpandtab
|
|
|
|
# vim:tabstop=4
|
|
|
|
# vim:shiftwidth=4
|