2018-03-15 14:01:28 +03:00
|
|
|
APPS=init hello sh ls terminal uname compositor drawlines background session kdebug cat yutani-test sysinfo hostname yutani-query env mount date echo nyancat kill ps pstree bim terminal-vga cursor-off font-server migrate free uptime
|
2018-02-25 08:13:54 +03:00
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
KERNEL_TARGET=i686-pc-toaru
|
2018-03-15 04:19:18 +03:00
|
|
|
KCC = $(KERNEL_TARGET)-gcc
|
|
|
|
KAS = $(KERNEL_TARGET)-as
|
|
|
|
KLD = $(KERNEL_TARGET)-ld
|
2018-03-16 15:56:19 +03:00
|
|
|
KNM = $(KERNEL_TARGET)-nm
|
2018-03-15 04:19:18 +03:00
|
|
|
|
2018-02-25 08:13:54 +03:00
|
|
|
CC=i686-pc-toaru-gcc
|
|
|
|
AR=i686-pc-toaru-ar
|
2018-03-16 16:40:23 +03:00
|
|
|
CFLAGS= -O3 -m32 -Wa,--32 -g -std=c99 -I. -Iapps
|
|
|
|
LIBS=
|
2018-02-25 08:13:54 +03:00
|
|
|
|
|
|
|
LIBC_OBJS=$(patsubst %.c,%.o,$(wildcard libc/*.c))
|
2018-03-19 07:36:02 +03:00
|
|
|
LC=base/lib/libc.so
|
2018-02-25 08:13:54 +03:00
|
|
|
|
|
|
|
APPS_X=$(foreach app,$(APPS),base/bin/$(app))
|
|
|
|
|
|
|
|
all: image.iso
|
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# Kernel
|
|
|
|
|
|
|
|
KCFLAGS = -O2 -std=c99
|
|
|
|
KCFLAGS += -finline-functions -ffreestanding
|
|
|
|
KCFLAGS += -Wall -Wextra -Wno-unused-function -Wno-unused-parameter -Wno-format
|
|
|
|
KCFLAGS += -pedantic -fno-omit-frame-pointer
|
|
|
|
KCFLAGS += -D_KERNEL_
|
|
|
|
KCFLAGS += -DKERNEL_GIT_TAG=$(shell util/make-version)
|
|
|
|
KASFLAGS = --32
|
|
|
|
|
|
|
|
KERNEL_OBJS = $(patsubst %.c,%.o,$(wildcard kernel/*.c))
|
|
|
|
KERNEL_OBJS += $(patsubst %.c,%.o,$(wildcard kernel/*/*.c))
|
|
|
|
KERNEL_OBJS += $(patsubst %.c,%.o,$(wildcard kernel/*/*/*.c))
|
|
|
|
|
|
|
|
KERNEL_ASMOBJS = $(filter-out kernel/symbols.o,$(patsubst %.S,%.o,$(wildcard kernel/*.S)))
|
|
|
|
|
|
|
|
cdrom/kernel: ${KERNEL_ASMOBJS} ${KERNEL_OBJS} kernel/symbols.o
|
|
|
|
${KCC} -T kernel/link.ld ${KCFLAGS} -nostdlib -o $@ ${KERNEL_ASMOBJS} ${KERNEL_OBJS} kernel/symbols.o -lgcc
|
|
|
|
|
|
|
|
kernel/symbols.o: ${KERNEL_ASMOBJS} ${KERNEL_OBJS} util/generate_symbols.py
|
|
|
|
-rm -f kernel/symbols.o
|
|
|
|
${KCC} -T kernel/link.ld ${KCFLAGS} -nostdlib -o .toaruos-kernel ${KERNEL_ASMOBJS} ${KERNEL_OBJS} -lgcc
|
|
|
|
${KNM} .toaruos-kernel -g | util/generate_symbols.py > kernel/symbols.S
|
|
|
|
${KAS} ${KASFLAGS} kernel/symbols.S -o $@
|
|
|
|
-rm -f .toaruos-kernel
|
|
|
|
|
|
|
|
kernel/sys/version.o: kernel/*/*.c kernel/*.c
|
|
|
|
|
|
|
|
cdrom/mod:
|
|
|
|
@mkdir -p $@
|
|
|
|
|
|
|
|
MODULES = $(patsubst modules/%.c,cdrom/mod/%.ko,$(wildcard modules/*.c))
|
|
|
|
|
2018-03-19 05:38:11 +03:00
|
|
|
HEADERS = $(shell find base/usr/include/kernel -type f -name '*.h')
|
2018-03-16 15:56:19 +03:00
|
|
|
|
|
|
|
cdrom/mod/%.ko: modules/%.c ${HEADERS} | cdrom/mod
|
2018-03-19 05:38:11 +03:00
|
|
|
${KCC} -T modules/link.ld -nostdlib ${KCFLAGS} -c -o $@ $<
|
2018-03-16 15:56:19 +03:00
|
|
|
|
|
|
|
modules: ${MODULES}
|
|
|
|
|
|
|
|
kernel/%.o: kernel/%.S
|
|
|
|
${KAS} ${ASFLAGS} $< -o $@
|
|
|
|
|
|
|
|
kernel/%.o: kernel/%.c ${HEADERS}
|
2018-03-19 05:38:11 +03:00
|
|
|
${KCC} ${KCFLAGS} -nostdlib -g -c -o $@ $<
|
2018-03-16 15:56:19 +03:00
|
|
|
|
|
|
|
# Root Filesystem
|
|
|
|
|
2018-02-25 08:13:54 +03:00
|
|
|
base/dev:
|
|
|
|
mkdir -p base/dev
|
|
|
|
base/tmp:
|
|
|
|
mkdir -p base/tmp
|
|
|
|
base/proc:
|
|
|
|
mkdir -p base/proc
|
|
|
|
base/bin:
|
|
|
|
mkdir -p base/bin
|
|
|
|
base/lib:
|
|
|
|
mkdir -p base/lib
|
2018-03-15 04:19:18 +03:00
|
|
|
cdrom/boot:
|
|
|
|
mkdir -p cdrom/boot
|
|
|
|
dirs: base/dev base/tmp base/proc base/bin base/lib cdrom/boot
|
2018-02-25 08:13:54 +03:00
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# C Library
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
crts: base/lib/crt0.o base/lib/crti.o base/lib/crtn.o | dirs
|
|
|
|
|
|
|
|
base/lib/crt%.o: libc/crt%.s
|
|
|
|
yasm -f elf -o $@ $<
|
|
|
|
|
2018-02-25 08:13:54 +03:00
|
|
|
libc/%.o: libc/%.c
|
2018-03-16 16:40:23 +03:00
|
|
|
$(CC) -fPIC -c -m32 -Wa,--32 -O3 -o $@ $<
|
2018-02-25 08:13:54 +03:00
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/lib/libc.a: ${LIBC_OBJS} | dirs crts
|
2018-02-25 08:13:54 +03:00
|
|
|
$(AR) cr $@ $^
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/lib/libc.so: ${LIBC_OBJS} | dirs crts
|
|
|
|
$(CC) -nodefaultlibs -o $@ $(CFLAGS) -shared -fPIC $^ -lgcc
|
2018-02-25 08:13:54 +03:00
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# Userspace Linker/Loader
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/lib/ld.so: linker/linker.c base/lib/libc.a | dirs
|
2018-03-16 15:56:19 +03:00
|
|
|
$(CC) -static -Wl,-static $(CFLAGS) -o $@ -Os -T linker/link.ld $< $(LIBS)
|
|
|
|
|
|
|
|
# Shared Libraries
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_graphics.so: lib/graphics.c base/usr/include/toaru/graphics.h ${LC}
|
2018-02-25 08:13:54 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $<
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_list.so: lib/list.c base/usr/include/toaru/list.h ${LC}
|
2018-02-25 08:13:54 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $<
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_tree.so: lib/tree.c base/usr/include/toaru/tree.h base/lib/libtoaru_list.so ${LC}
|
2018-02-25 12:25:05 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_list
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_hashmap.so: lib/hashmap.c base/usr/include/toaru/hashmap.h base/lib/libtoaru_list.so ${LC}
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_list
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_kbd.so: lib/kbd.c base/usr/include/toaru/kbd.h ${LC}
|
2018-02-25 08:13:54 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $<
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_pthread.so: lib/pthread.c base/usr/include/toaru/pthread.h ${LC}
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $<
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_pex.so: lib/pex.c base/usr/include/toaru/pex.h ${LC}
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $<
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_dlfcn.so: lib/dlfcn.c ${LC}
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $<
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_yutani.so: lib/yutani.c base/usr/include/toaru/yutani.h base/lib/libtoaru_graphics.so ${LC}
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_graphics
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_rline.so: lib/rline.c base/usr/include/toaru/rline.h base/lib/libtoaru_kbd.so ${LC}
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_kbd
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_termemu.so: lib/termemu.c base/usr/include/toaru/termemu.h base/lib/libtoaru_graphics.so ${LC}
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_graphics
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_drawstring.so: lib/drawstring.c base/usr/include/toaru/drawstring.h base/lib/libtoaru_graphics.so ${LC}
|
2018-03-01 09:10:57 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_graphics
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru_decorations.so: lib/decorations.c base/usr/include/toaru/decorations.h base/lib/libtoaru_graphics.so ${LC}
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_graphics
|
2018-02-25 08:13:54 +03:00
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# Decoration Themes
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/lib/libtoaru-decor-fancy.so: decors/decor-fancy.c base/usr/include/toaru/decorations.h base/lib/libtoaru_graphics.so base/lib/libtoaru_decorations.so base/lib/libtoaru_drawstring.so ${LC}
|
2018-03-01 09:10:57 +03:00
|
|
|
$(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_decorations -ltoaru_drawstring -ltoaru_graphics
|
2018-02-25 15:54:39 +03:00
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# Init
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/init: apps/init.c base/lib/libc.a | dirs
|
2018-02-25 08:13:54 +03:00
|
|
|
$(CC) -static -Wl,-static $(CFLAGS) -o $@ $< $(LIBS)
|
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# Userspace
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/sh: apps/sh.c base/lib/libc.so base/lib/libtoaru_list.so base/lib/libtoaru_rline.so
|
2018-02-25 08:13:54 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_rline -ltoaru_list -ltoaru_kbd $(LIBS)
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/migrate: apps/migrate.c base/lib/libc.so base/lib/libtoaru_list.so base/lib/libtoaru_hashmap.so
|
2018-03-15 13:30:04 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_hashmap -ltoaru_list $(LIBS)
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/sysinfo: apps/sysinfo.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_termemu.so
|
2018-02-25 17:06:07 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_graphics -ltoaru_termemu $(LIBS)
|
2018-02-25 08:13:54 +03:00
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/terminal: apps/terminal.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_decorations.so base/lib/libtoaru_dlfcn.so base/lib/libtoaru_list.so base/lib/libtoaru_kbd.so base/lib/libtoaru_termemu.so base/lib/libtoaru_pex.so base/lib/libtoaru_hashmap.so
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_termemu -ltoaru_decorations -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_hashmap -ltoaru_dlfcn -ltoaru_kbd -ltoaru_list $(LIBS)
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/terminal-vga: apps/terminal-vga.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_kbd.so base/lib/libtoaru_termemu.so
|
2018-03-04 16:50:53 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_termemu -ltoaru_graphics -ltoaru_kbd $(LIBS)
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/background: apps/background.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so base/lib/libtoaru_drawstring.so
|
2018-03-01 09:10:57 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_drawstring -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
|
2018-02-25 11:14:43 +03:00
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/drawlines: apps/drawlines.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
|
2018-02-25 12:29:31 +03:00
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/yutani-query: apps/yutani-query.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
|
2018-02-25 17:06:07 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/yutani-test: apps/yutani-test.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
|
2018-02-25 12:29:31 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
|
2018-02-25 11:14:43 +03:00
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/compositor: apps/compositor.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_list.so base/lib/libtoaru_kbd.so base/lib/libtoaru_pthread.so base/lib/libtoaru_pex.so base/lib/libtoaru_yutani.so base/lib/libtoaru_hashmap.so
|
2018-02-25 11:14:43 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_pthread -ltoaru_pex -ltoaru_graphics -ltoaru_kbd -ltoaru_hashmap -ltoaru_list $(LIBS)
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/ls: apps/ls.c base/lib/libc.so base/lib/libtoaru_list.so
|
2018-02-25 08:13:54 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_list $(LIBS)
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/bin/nyancat: apps/nyancat/nyancat.c ${LC}
|
2018-03-02 15:25:32 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/ps: apps/ps.c base/lib/libc.so base/lib/libtoaru_list.so
|
2018-03-03 14:23:13 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_list $(LIBS)
|
|
|
|
|
2018-03-16 16:40:23 +03:00
|
|
|
base/bin/pstree: apps/pstree.c base/lib/libc.so base/lib/libtoaru_tree.so base/lib/libtoaru_list.so
|
2018-03-03 14:23:13 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< -ltoaru_tree -ltoaru_list $(LIBS)
|
|
|
|
|
2018-03-19 07:36:02 +03:00
|
|
|
base/bin/%: apps/%.c base/lib/libc.so ${LC} | dirs
|
2018-02-25 08:13:54 +03:00
|
|
|
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# Ramdisk
|
|
|
|
|
2018-03-15 04:19:18 +03:00
|
|
|
cdrom/ramdisk.img: ${APPS_X} base/lib/ld.so base/lib/libtoaru-decor-fancy.so Makefile | dirs
|
|
|
|
genext2fs -B 4096 -d base -U -b 4096 -N 2048 cdrom/ramdisk.img
|
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# CD image
|
|
|
|
|
|
|
|
image.iso: cdrom/ramdisk.img cdrom/boot/boot.sys cdrom/kernel ${MODULES}
|
2018-03-15 04:19:18 +03:00
|
|
|
xorriso -as mkisofs -R -J -c boot/bootcat -b boot/boot.sys -no-emul-boot -boot-load-size 20 -o image.iso cdrom
|
|
|
|
|
2018-03-16 15:56:19 +03:00
|
|
|
# Boot loader
|
|
|
|
|
2018-03-15 04:19:18 +03:00
|
|
|
cdrom/boot/boot.sys: boot/boot.o boot/cstuff.o boot/link.ld | cdrom/boot
|
|
|
|
${KLD} -T boot/link.ld -o $@ boot/boot.o boot/cstuff.o
|
|
|
|
|
|
|
|
boot/cstuff.o: boot/cstuff.c boot/ata.h boot/atapi_imp.h boot/elf.h boot/iso9660.h boot/multiboot.h boot/text.h boot/types.h boot/util.h
|
|
|
|
${KCC} -c -Os -o $@ $<
|
2018-02-25 08:13:54 +03:00
|
|
|
|
2018-03-15 04:19:18 +03:00
|
|
|
boot/boot.o: boot/boot.s
|
|
|
|
yasm -f elf -o $@ $<
|
2018-02-25 08:13:54 +03:00
|
|
|
|
2018-02-25 11:43:31 +03:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm -f base/lib/*.so
|
2018-03-16 16:40:23 +03:00
|
|
|
rm -f base/lib/libc.a
|
2018-03-01 06:55:28 +03:00
|
|
|
rm -f ${APPS_X}
|
2018-02-25 11:43:31 +03:00
|
|
|
rm -f libc/*.o
|
|
|
|
rm -f image.iso
|
2018-03-15 04:33:02 +03:00
|
|
|
rm -f cdrom/ramdisk.img
|
|
|
|
rm -f cdrom/boot/boot.sys
|
|
|
|
rm -f boot/*.o
|
2018-03-16 15:56:19 +03:00
|
|
|
rm -f cdrom/kernel
|
2018-03-19 09:33:07 +03:00
|
|
|
rm -f ${KERNEL_OBJS} ${KERNEL_ASMOBJS} kernel/symbols.o kernel/symbols.S
|
2018-03-19 05:47:16 +03:00
|
|
|
rm -f base/lib/crt*.o
|
2018-03-16 15:56:19 +03:00
|
|
|
rm -f ${MODULES}
|
|
|
|
|