Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. # ToAruOS Primary Build Script
  2. # We always build with our targetted cross-compiler
  3. CC = i686-pc-toaru-gcc
  4. NM = i686-pc-toaru-nm
  5. # Build flags
  6. CFLAGS = -O2 -std=c99
  7. CFLAGS += -finline-functions -ffreestanding
  8. CFLAGS += -Wall -Wextra -Wno-unused-function -Wno-unused-parameter
  9. CFLAGS += -Wstrict-prototypes -pedantic -fno-omit-frame-pointer
  10. CFLAGS += -D_KERNEL_
  11. # Kernel autoversioning with git sha
  12. CFLAGS += -DKERNEL_GIT_TAG=`util/make-version`
  13. # We have some pieces of assembly sitting around as well...
  14. YASM = yasm
  15. # All of the core parts of the kernel are built directly.
  16. KERNEL_OBJS = $(patsubst %.c,%.o,$(wildcard kernel/*/*.c))
  17. KERNEL_OBJS += $(patsubst %.c,%.o,$(wildcard kernel/*/*/*.c))
  18. # Loadable modules
  19. MODULES = $(patsubst modules/%.c,hdd/mod/%.ko,$(wildcard modules/*.c))
  20. # We also want to rebuild when a header changes.
  21. # This is a naive approach, but it works...
  22. HEADERS = $(shell find kernel/include/ -type f -name '*.h')
  23. # We'll call out to our userspace build script if we
  24. # see changes to any of the userspace sources as well.
  25. USERSPACE = $(shell find userspace/ -type f -name '*.c')
  26. USERSPACE += $(shell find userspace/ -type f -name '*.cpp')
  27. USERSPACE += $(shell find userspace/ -type f -name '*.h')
  28. # Pretty output utilities.
  29. BEG = util/mk-beg
  30. END = util/mk-end
  31. INFO = util/mk-info
  32. ERRORS = 2>>/tmp/.`whoami`-build-errors || util/mk-error
  33. ERRORSS = >>/tmp/.`whoami`-build-errors || util/mk-error
  34. BEGRM = util/mk-beg-rm
  35. ENDRM = util/mk-end-rm
  36. # Hard disk image generation
  37. GENEXT = genext2fs
  38. DISK_SIZE = `util/disk_size.sh`
  39. DD = dd conv=notrunc
  40. # Specify which modules should be included on startup.
  41. # There are a few modules that are kinda required for a working system
  42. # such as all of the dependencies needed to mount the root partition.
  43. # We can also include things like the debug shell...
  44. # Note that ordering matters - list dependencies first.
  45. BOOT_MODULES := zero random serial
  46. BOOT_MODULES += procfs tmpfs ata
  47. #BOOT_MODULES += dospart
  48. BOOT_MODULES += ext2
  49. BOOT_MODULES += debug_shell
  50. BOOT_MODULES += ps2mouse ps2kbd
  51. BOOT_MODULES += lfbvideo
  52. BOOT_MODULES += packetfs
  53. # This is kinda silly. We're going to form an -initrd argument..
  54. # which is basically -initrd "hdd/mod/%.ko,hdd/mod/%.ko..."
  55. # for each of the modules listed above in BOOT_MODULES
  56. COMMA := ,
  57. EMPTY :=
  58. SPACE := $(EMPTY) $(EMPTY)
  59. BOOT_MODULES_X = -initrd "$(subst $(SPACE),$(COMMA),$(foreach mod,$(BOOT_MODULES),hdd/mod/$(mod).ko))"
  60. # Emulator settings
  61. EMU = qemu-system-i386
  62. EMUARGS = -sdl -kernel toaruos-kernel -m 1024
  63. EMUARGS += -serial stdio -vga std
  64. EMUARGS += -hda toaruos-disk.img -k en-us -no-frame
  65. EMUARGS += -rtc base=localtime -net nic,model=rtl8139 -net user -soundhw pcspk
  66. EMUARGS += $(BOOT_MODULES_X)
  67. EMUKVM = -enable-kvm
  68. DISK_ROOT = root=/dev/hda
  69. VID_QEMU = vid=qemu,,1280,,720
  70. START_VGA = start=--vga
  71. START_SINGLE = start=--single
  72. WITH_LOGS = logtoserial=1
  73. .PHONY: all system install test toolchain
  74. .PHONY: clean clean-soft clean-hard clean-bin clean-mods clean-core clean-disk clean-once
  75. .PHONY: run vga term headless
  76. .PHONY: kvm vga-kvm term-kvm headless-kvm
  77. # Prevents Make from removing intermediary files on failure
  78. .SECONDARY:
  79. # Disable built-in rules
  80. .SUFFIXES:
  81. all: .passed system tags
  82. system: .passed toaruos-disk.img toaruos-kernel ${MODULES}
  83. install: system
  84. @${BEG} "CP" "Installing to /boot..."
  85. @cp toaruos-kernel /boot/toaruos-kernel
  86. @${END} "CP" "Installed to /boot"
  87. # Various different quick options
  88. run: system
  89. ${EMU} ${EMUARGS} -append "$(VID_QEMU) $(DISK_ROOT)"
  90. kvm: system
  91. ${EMU} ${EMUARGS} ${EMUKVM} -append "$(VID_QEMU) $(DISK_ROOT)"
  92. vga: system
  93. ${EMU} ${EMUARGS} -append "$(START_VGA) $(DISK_ROOT)"
  94. vga-kvm: system
  95. ${EMU} ${EMUARGS} ${EMUKVM} -append "$(START_VGA) $(DISK_ROOT)"
  96. term: system
  97. ${EMU} ${EMUARGS} -append "$(VID_QEMU) $(START_SINGLE) $(DISK_ROOT)"
  98. term-kvm: system
  99. ${EMU} ${EMUARGS} ${EMUKVM} -append "$(VID_QEMU) $(START_SINGLE) $(DISK_ROOT)"
  100. headless: system
  101. ${EMU} ${EMUARGS} -display none -append "$(START_VGA) $(DISK_ROOT)"
  102. headless-kvm: system
  103. ${EMU} ${EMUARGS} ${EMUKVM} -display none -append "$(START_VGA) $(DISK_ROOT)"
  104. test: system
  105. python2 util/run-tests.py 2>/dev/null
  106. toolchain:
  107. @cd toolchain; ./toolchain-build.sh
  108. .passed:
  109. @util/check-reqs > /dev/null
  110. @touch .passed
  111. ################
  112. # Kernel #
  113. ################
  114. toaruos-kernel: kernel/start.o kernel/link.ld kernel/main.o kernel/symbols.o ${KERNEL_OBJS} .passed
  115. @${BEG} "CC" "$<"
  116. @${CC} -T kernel/link.ld -nostdlib -o toaruos-kernel kernel/*.o ${KERNEL_OBJS} -lgcc ${ERRORS}
  117. @${END} "CC" "$<"
  118. @${INFO} "--" "Kernel is ready!"
  119. kernel/symbols.o: ${KERNEL_OBJS} util/generate_symbols.py
  120. @-rm -f kernel/symbols.o
  121. @${BEG} "nm" "Generating symbol list..."
  122. @${CC} -T kernel/link.ld -nostdlib -o toaruos-kernel kernel/*.o ${KERNEL_OBJS} -lgcc ${ERRORS}
  123. @${NM} toaruos-kernel -g | python2 util/generate_symbols.py > kernel/symbols.s
  124. @${END} "nm" "Generated symbol list."
  125. @${BEG} "yasm" "kernel/symbols.s"
  126. @${YASM} -f elf -o $@ kernel/symbols.s ${ERRORS}
  127. @${END} "yasm" "kernel/symbols.s"
  128. kernel/start.o: kernel/start.s
  129. @${BEG} "yasm" "$<"
  130. @${YASM} -f elf -o $@ $< ${ERRORS}
  131. @${END} "yasm" "$<"
  132. kernel/sys/version.o: kernel/*/*.c kernel/*.c
  133. hdd/mod/%.ko: modules/%.c ${HEADERS}
  134. @${BEG} "CC" "$< [module]"
  135. @${CC} -T modules/link.ld -I./kernel/include -nostdlib ${CFLAGS} -c -o $@ $< ${ERRORS}
  136. @${END} "CC" "$< [module]"
  137. %.o: %.c ${HEADERS}
  138. @${BEG} "CC" "$<"
  139. @${CC} ${CFLAGS} -g -I./kernel/include -c -o $@ $< ${ERRORS}
  140. @${END} "CC" "$<"
  141. ####################
  142. # Hard Disk Images #
  143. ####################
  144. .userspace-check: ${USERSPACE}
  145. @cd userspace && python2 build.py
  146. @touch .userspace-check
  147. toaruos-disk.img: .userspace-check ${MODULES}
  148. @${BEG} "hdd" "Generating a Hard Disk image..."
  149. @-rm -f toaruos-disk.img
  150. @${GENEXT} -B 4096 -d hdd -U -b ${DISK_SIZE} -N 4096 toaruos-disk.img ${ERRORS}
  151. @${END} "hdd" "Generated Hard Disk image"
  152. @${INFO} "--" "Hard disk image is ready!"
  153. ##############
  154. # ctags #
  155. ##############
  156. tags: kernel/*/*.c kernel/*.c .userspace-check
  157. @${BEG} "ctag" "Generating CTags..."
  158. @ctags -R --c++-kinds=+p --fields=+iaS --extra=+q kernel userspace modules util
  159. @${END} "ctag" "Generated CTags."
  160. ###############
  161. # clean #
  162. ###############
  163. clean-soft:
  164. @${BEGRM} "RM" "Cleaning modules..."
  165. @-rm -f kernel/*.o
  166. @-rm -f kernel/*/*.o
  167. @-rm -f ${KERNEL_OBJS}
  168. @${ENDRM} "RM" "Cleaned modules."
  169. clean-bin:
  170. @${BEGRM} "RM" "Cleaning native binaries..."
  171. @-rm -f hdd/bin/*
  172. @${ENDRM} "RM" "Cleaned native binaries"
  173. clean-mods:
  174. @${BEGRM} "RM" "Cleaning kernel modules..."
  175. @-rm -f hdd/mod/*
  176. @${ENDRM} "RM" "Cleaned kernel modules"
  177. clean-core:
  178. @${BEGRM} "RM" "Cleaning final output..."
  179. @-rm -f toaruos-kernel
  180. @${ENDRM} "RM" "Cleaned final output"
  181. clean-disk:
  182. @${BEGRM} "RM" "Deleting hard disk image..."
  183. @-rm -f toaruos-disk.img
  184. @${ENDRM} "RM" "Deleted hard disk image"
  185. clean-once:
  186. @${BEGRM} "RM" "Cleaning one-time files..."
  187. @-rm -f .passed
  188. @${ENDRM} "RM" "Cleaned one-time files"
  189. clean: clean-soft clean-core
  190. @${INFO} "--" "Finished soft cleaning"
  191. clean-hard: clean clean-bin clean-mods
  192. @${INFO} "--" "Finished hard cleaning"
  193. # vim:noexpandtab
  194. # vim:tabstop=4
  195. # vim:shiftwidth=4