Makefile 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. 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
  2. ifeq ($(TOOLCHAIN),)
  3. ifeq ($(shell util/check.sh),y)
  4. export PATH := $(shell util/activate.sh)
  5. else
  6. FOO := $(shell util/prompt.sh)
  7. ifeq ($(shell util/check.sh),y)
  8. export PATH := $(shell util/activate.sh)
  9. else
  10. $(error "No toolchain, and you did not ask to build it.")
  11. endif
  12. endif
  13. endif
  14. KERNEL_TARGET=i686-pc-toaru
  15. KCC = $(KERNEL_TARGET)-gcc
  16. KAS = $(KERNEL_TARGET)-as
  17. KLD = $(KERNEL_TARGET)-ld
  18. KNM = $(KERNEL_TARGET)-nm
  19. CC=i686-pc-toaru-gcc
  20. AR=i686-pc-toaru-ar
  21. CFLAGS= -O3 -m32 -Wa,--32 -g -std=c99 -I. -Iapps
  22. LIBS=
  23. LIBC_OBJS=$(patsubst %.c,%.o,$(wildcard libc/*.c))
  24. LC=base/lib/libc.so
  25. APPS_X=$(foreach app,$(APPS),base/bin/$(app))
  26. all: image.iso
  27. # Kernel
  28. KCFLAGS = -O2 -std=c99
  29. KCFLAGS += -finline-functions -ffreestanding
  30. KCFLAGS += -Wall -Wextra -Wno-unused-function -Wno-unused-parameter -Wno-format
  31. KCFLAGS += -pedantic -fno-omit-frame-pointer
  32. KCFLAGS += -D_KERNEL_
  33. KCFLAGS += -DKERNEL_GIT_TAG=$(shell util/make-version)
  34. KASFLAGS = --32
  35. KERNEL_OBJS = $(patsubst %.c,%.o,$(wildcard kernel/*.c))
  36. KERNEL_OBJS += $(patsubst %.c,%.o,$(wildcard kernel/*/*.c))
  37. KERNEL_OBJS += $(patsubst %.c,%.o,$(wildcard kernel/*/*/*.c))
  38. KERNEL_ASMOBJS = $(filter-out kernel/symbols.o,$(patsubst %.S,%.o,$(wildcard kernel/*.S)))
  39. cdrom/kernel: ${KERNEL_ASMOBJS} ${KERNEL_OBJS} kernel/symbols.o
  40. ${KCC} -T kernel/link.ld ${KCFLAGS} -nostdlib -o $@ ${KERNEL_ASMOBJS} ${KERNEL_OBJS} kernel/symbols.o -lgcc
  41. kernel/symbols.o: ${KERNEL_ASMOBJS} ${KERNEL_OBJS} util/generate_symbols.py
  42. -rm -f kernel/symbols.o
  43. ${KCC} -T kernel/link.ld ${KCFLAGS} -nostdlib -o .toaruos-kernel ${KERNEL_ASMOBJS} ${KERNEL_OBJS} -lgcc
  44. ${KNM} .toaruos-kernel -g | util/generate_symbols.py > kernel/symbols.S
  45. ${KAS} ${KASFLAGS} kernel/symbols.S -o $@
  46. -rm -f .toaruos-kernel
  47. kernel/sys/version.o: kernel/*/*.c kernel/*.c
  48. cdrom/mod:
  49. @mkdir -p $@
  50. MODULES = $(patsubst modules/%.c,cdrom/mod/%.ko,$(wildcard modules/*.c))
  51. HEADERS = $(shell find base/usr/include/kernel -type f -name '*.h')
  52. cdrom/mod/%.ko: modules/%.c ${HEADERS} | cdrom/mod
  53. ${KCC} -T modules/link.ld -nostdlib ${KCFLAGS} -c -o $@ $<
  54. modules: ${MODULES}
  55. kernel/%.o: kernel/%.S
  56. ${KAS} ${ASFLAGS} $< -o $@
  57. kernel/%.o: kernel/%.c ${HEADERS}
  58. ${KCC} ${KCFLAGS} -nostdlib -g -c -o $@ $<
  59. # Root Filesystem
  60. base/dev:
  61. mkdir -p base/dev
  62. base/tmp:
  63. mkdir -p base/tmp
  64. base/proc:
  65. mkdir -p base/proc
  66. base/bin:
  67. mkdir -p base/bin
  68. base/lib:
  69. mkdir -p base/lib
  70. cdrom/boot:
  71. mkdir -p cdrom/boot
  72. dirs: base/dev base/tmp base/proc base/bin base/lib cdrom/boot
  73. # C Library
  74. crts: base/lib/crt0.o base/lib/crti.o base/lib/crtn.o | dirs
  75. base/lib/crt%.o: libc/crt%.s
  76. yasm -f elf -o $@ $<
  77. libc/%.o: libc/%.c
  78. $(CC) -fPIC -c -m32 -Wa,--32 -O3 -o $@ $<
  79. base/lib/libc.a: ${LIBC_OBJS} | dirs crts
  80. $(AR) cr $@ $^
  81. base/lib/libc.so: ${LIBC_OBJS} | dirs crts
  82. $(CC) -nodefaultlibs -o $@ $(CFLAGS) -shared -fPIC $^ -lgcc
  83. # Userspace Linker/Loader
  84. base/lib/ld.so: linker/linker.c base/lib/libc.a | dirs
  85. $(CC) -static -Wl,-static $(CFLAGS) -o $@ -Os -T linker/link.ld $< $(LIBS)
  86. # Shared Libraries
  87. base/lib/libtoaru_graphics.so: lib/graphics.c base/usr/include/toaru/graphics.h ${LC}
  88. $(CC) -o $@ $(CFLAGS) -shared -fPIC $<
  89. base/lib/libtoaru_list.so: lib/list.c base/usr/include/toaru/list.h ${LC}
  90. $(CC) -o $@ $(CFLAGS) -shared -fPIC $<
  91. base/lib/libtoaru_tree.so: lib/tree.c base/usr/include/toaru/tree.h base/lib/libtoaru_list.so ${LC}
  92. $(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_list
  93. base/lib/libtoaru_hashmap.so: lib/hashmap.c base/usr/include/toaru/hashmap.h base/lib/libtoaru_list.so ${LC}
  94. $(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_list
  95. base/lib/libtoaru_kbd.so: lib/kbd.c base/usr/include/toaru/kbd.h ${LC}
  96. $(CC) -o $@ $(CFLAGS) -shared -fPIC $<
  97. base/lib/libtoaru_pthread.so: lib/pthread.c base/usr/include/toaru/pthread.h ${LC}
  98. $(CC) -o $@ $(CFLAGS) -shared -fPIC $<
  99. base/lib/libtoaru_pex.so: lib/pex.c base/usr/include/toaru/pex.h ${LC}
  100. $(CC) -o $@ $(CFLAGS) -shared -fPIC $<
  101. base/lib/libtoaru_dlfcn.so: lib/dlfcn.c ${LC}
  102. $(CC) -o $@ $(CFLAGS) -shared -fPIC $<
  103. base/lib/libtoaru_yutani.so: lib/yutani.c base/usr/include/toaru/yutani.h base/lib/libtoaru_graphics.so ${LC}
  104. $(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_graphics
  105. base/lib/libtoaru_rline.so: lib/rline.c base/usr/include/toaru/rline.h base/lib/libtoaru_kbd.so ${LC}
  106. $(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_kbd
  107. base/lib/libtoaru_termemu.so: lib/termemu.c base/usr/include/toaru/termemu.h base/lib/libtoaru_graphics.so ${LC}
  108. $(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_graphics
  109. base/lib/libtoaru_drawstring.so: lib/drawstring.c base/usr/include/toaru/drawstring.h base/lib/libtoaru_graphics.so ${LC}
  110. $(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_graphics
  111. base/lib/libtoaru_decorations.so: lib/decorations.c base/usr/include/toaru/decorations.h base/lib/libtoaru_graphics.so ${LC}
  112. $(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_graphics
  113. # Decoration Themes
  114. 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}
  115. $(CC) -o $@ $(CFLAGS) -shared -fPIC $< -ltoaru_decorations -ltoaru_drawstring -ltoaru_graphics
  116. # Init
  117. base/bin/init: apps/init.c base/lib/libc.a | dirs
  118. $(CC) -static -Wl,-static $(CFLAGS) -o $@ $< $(LIBS)
  119. # Userspace
  120. base/bin/sh: apps/sh.c base/lib/libc.so base/lib/libtoaru_list.so base/lib/libtoaru_rline.so
  121. $(CC) $(CFLAGS) -o $@ $< -ltoaru_rline -ltoaru_list -ltoaru_kbd $(LIBS)
  122. base/bin/migrate: apps/migrate.c base/lib/libc.so base/lib/libtoaru_list.so base/lib/libtoaru_hashmap.so
  123. $(CC) $(CFLAGS) -o $@ $< -ltoaru_hashmap -ltoaru_list $(LIBS)
  124. base/bin/sysinfo: apps/sysinfo.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_termemu.so
  125. $(CC) $(CFLAGS) -o $@ $< -ltoaru_graphics -ltoaru_termemu $(LIBS)
  126. 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
  127. $(CC) $(CFLAGS) -o $@ $< -ltoaru_termemu -ltoaru_decorations -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_hashmap -ltoaru_dlfcn -ltoaru_kbd -ltoaru_list $(LIBS)
  128. 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
  129. $(CC) $(CFLAGS) -o $@ $< -ltoaru_termemu -ltoaru_graphics -ltoaru_kbd $(LIBS)
  130. 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
  131. $(CC) $(CFLAGS) -o $@ $< -ltoaru_drawstring -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
  132. 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
  133. $(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
  134. 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
  135. $(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
  136. 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
  137. $(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
  138. 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
  139. $(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_pthread -ltoaru_pex -ltoaru_graphics -ltoaru_kbd -ltoaru_hashmap -ltoaru_list $(LIBS)
  140. base/bin/ls: apps/ls.c base/lib/libc.so base/lib/libtoaru_list.so
  141. $(CC) $(CFLAGS) -o $@ $< -ltoaru_list $(LIBS)
  142. base/bin/nyancat: apps/nyancat/nyancat.c ${LC}
  143. $(CC) $(CFLAGS) -o $@ $< $(LIBS)
  144. base/bin/ps: apps/ps.c base/lib/libc.so base/lib/libtoaru_list.so
  145. $(CC) $(CFLAGS) -o $@ $< -ltoaru_list $(LIBS)
  146. base/bin/pstree: apps/pstree.c base/lib/libc.so base/lib/libtoaru_tree.so base/lib/libtoaru_list.so
  147. $(CC) $(CFLAGS) -o $@ $< -ltoaru_tree -ltoaru_list $(LIBS)
  148. base/bin/%: apps/%.c base/lib/libc.so ${LC} | dirs
  149. $(CC) $(CFLAGS) -o $@ $< $(LIBS)
  150. # Ramdisk
  151. cdrom/ramdisk.img: ${APPS_X} base/lib/ld.so base/lib/libtoaru-decor-fancy.so Makefile | dirs
  152. genext2fs -B 4096 -d base -U -b 4096 -N 2048 cdrom/ramdisk.img
  153. # CD image
  154. image.iso: cdrom/ramdisk.img cdrom/boot/boot.sys cdrom/kernel ${MODULES}
  155. xorriso -as mkisofs -R -J -c boot/bootcat -b boot/boot.sys -no-emul-boot -boot-load-size 20 -o image.iso cdrom
  156. # Boot loader
  157. cdrom/boot/boot.sys: boot/boot.o boot/cstuff.o boot/link.ld | cdrom/boot
  158. ${KLD} -T boot/link.ld -o $@ boot/boot.o boot/cstuff.o
  159. 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
  160. ${KCC} -c -Os -o $@ $<
  161. boot/boot.o: boot/boot.s
  162. yasm -f elf -o $@ $<
  163. .PHONY: clean
  164. clean:
  165. rm -f base/lib/*.so
  166. rm -f base/lib/libc.a
  167. rm -f ${APPS_X}
  168. rm -f libc/*.o
  169. rm -f image.iso
  170. rm -f cdrom/ramdisk.img
  171. rm -f cdrom/boot/boot.sys
  172. rm -f boot/*.o
  173. rm -f cdrom/kernel
  174. rm -f ${KERNEL_OBJS} ${KERNEL_ASMOBJS} kernel/symbols.o kernel/symbols.S
  175. rm -f base/lib/crt*.o
  176. rm -f ${MODULES}