Advertisement
MichaelPetch

Makefile

Oct 23rd, 2022
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. # NOTES
  2. #
  3. # bin/disk.img is the flat hard disk that the emulator will see
  4. #
  5. #
  6. # what the bin/kernel.bin target recipe is doing:
  7. # -the first command links together all our object files into another large intermediary relocatable object file (build/kernelfull.o)
  8. # -the second command tells gcc to use our linker script and ld to turn our intermediary relocatable object file (build/kernelfull.o) into a binary at bin/kernel.bin
  9. # using gcc since in the future we will be compiling c files in with this command. When an object file is passed to gcc, gcc
  10. # skips compilation and instead directly invokes the linker (i686-elf-ld)
  11. #
  12. # SPECIAL VARIABLES REFERENCE
  13. # $^ = name of all the dependencies with space as the delimiter
  14. # $@ = full target name of the current target
  15. # $< = name of the first dependency
  16. # $? = returns the dependencies that are newer than the current target
  17. # $* = returns the text that corresponds to % in the target
  18.  
  19. SHELL = /bin/sh
  20. INCLUDES = ./src
  21. MODULES = build/kernel.asm.o build/kernel.o \
  22. build/print.o build/idt/idt.asm.o \
  23. build/idt/idt.o build/memory/memory.o \
  24. build/io/io.asm.o build/memory/heap/heap.o \
  25. build/memory/heap/kernel_heap.o build/memory/paging/paging.o \
  26. build/memory/paging/paging.asm.o build/disk/disk.o \
  27. build/string/string.o build/fs/pparser.o \
  28. build/disk/disk_stream.o build/fs/file.o \
  29. build/fs/fat/fat16.o \
  30. build/gdt/gdt.o build/gdt/gdt.asm.o
  31.  
  32. FLAGS = -g -ffreestanding -falign-jumps -falign-functions -falign-labels \
  33. -falign-loops -fstrength-reduce -fomit-frame-pointer \
  34. -finline-functions -Wno-unused-function -fno-builtin \
  35. -Werror -Wno-unused-label -Wno-cpp -Wno-unused-parameter \
  36. -nostdlib -nostartfiles -nodefaultlibs -Wall -O0 -Iinc
  37.  
  38. all: bin/disk.img
  39.  
  40. bin/disk.img: bin/os.bin
  41. cp bin/os.bin bin/disk.img
  42. # Mount and unmount the the disk image as a file system
  43. # This will allow us to copy over files onto the disk image
  44. sudo mount -t vfat bin/disk.img /mnt/d
  45. echo "Hello World" > ./hello.txt
  46. sudo cp ./hello.txt /mnt/d
  47. sudo umount /mnt/d
  48.  
  49. bin/os.bin: bin/boot.bin bin/kernel.bin
  50. dd if=bin/boot.bin > bin/os.bin
  51. dd if=bin/kernel.bin >> bin/os.bin
  52. dd if=/dev/zero bs=1048576 count=16 >> bin/os.bin # Fills up rest of disk with 16, 1 MB sized blocks of zeros (this will be used by Linux to store our file data)
  53.  
  54. bin/kernel.bin: $(MODULES)
  55. i686-elf-ld -g -relocatable $(MODULES) -o build/kernelfull.o
  56. i686-elf-gcc $(FLAGS) -T src/linker.ld -o bin/kernel.elf -ffreestanding -O0 -nostdlib build/kernelfull.o
  57. i686-elf-objcopy -O binary bin/kernel.elf bin/kernel.bin
  58.  
  59. bin/boot.bin: src/boot/boot.asm
  60. nasm -f bin $^ -o $@
  61.  
  62. build/kernel.asm.o: src/kernel.asm
  63. nasm -f elf -g $^ -o $@
  64.  
  65. build/kernel.o: src/kernel.c
  66. i686-elf-gcc -I $(INCLUDES) $(FLAGS) -c $^ -o $@
  67.  
  68. build/print.o: src/print/print.c
  69. i686-elf-gcc -I $(INCLUDES) src/print $(FLAGS) -c $^ -o $@
  70.  
  71. build/idt/idt.asm.o: src/idt/idt.asm
  72. nasm -f elf -g $^ -o $@
  73.  
  74. build/idt/idt.o: src/idt/idt.c
  75. i686-elf-gcc -I $(INCLUDES) src/idt $(FLAGS) -c $^ -o $@
  76.  
  77. build/gdt/gdt.asm.o: src/gdt/gdt.asm
  78. nasm -f elf -g $^ -o $@
  79.  
  80. build/gdt/gdt.o: src/gdt/gdt.c
  81. i686-elf-gcc -I $(INCLUDES) src/gdt $(FLAGS) -c $^ -o $@
  82.  
  83. build/memory/memory.o: src/memory/memory.c
  84. i686-elf-gcc -I $(INCLUDES) src/memory $(FLAGS) -c $^ -o $@
  85.  
  86. build/io/io.asm.o: src/io/io.asm
  87. nasm -f elf -g $^ -o $@
  88.  
  89. build/memory/heap/heap.o: src/memory/heap/heap.c
  90. i686-elf-gcc -I $(INCLUDES) src/memory/heap $(FLAGS) -c $^ -o $@
  91.  
  92. build/memory/heap/kernel_heap.o: src/memory/heap/kernel_heap.c
  93. i686-elf-gcc -I $(INCLUDES) src/memory/heap $(FLAGS) -c $^ -o $@
  94.  
  95. build/memory/paging/paging.o: src/memory/paging/paging.c
  96. i686-elf-gcc -I $(INCLUDES) src/memory/paging $(FLAGS) -c $^ -o $@
  97.  
  98. build/memory/paging/paging.asm.o: src/memory/paging/paging.asm
  99. nasm -f elf -g $^ -o $@
  100.  
  101. build/disk/disk.o: src/disk/disk.c
  102. i686-elf-gcc -I $(INCLUDES) src/disk $(FLAGS) -c $^ -o $@
  103.  
  104. build/string/string.o: src/string/string.c
  105. i686-elf-gcc -I $(INCLUDES) src/string $(FLAGS) -c $^ -o $@
  106.  
  107. build/fs/pparser.o: src/fs/pparser.c
  108. i686-elf-gcc -I $(INCLUDES) src/fs $(FLAGS) -c $^ -o $@
  109.  
  110. build/fs/file.o: src/fs/file.c
  111. i686-elf-gcc -I $(INCLUDES) src/fs $(FLAGS) -c $^ -o $@
  112.  
  113. build/fs/fat/fat16.o: src/fs/fat/fat16.c
  114. i686-elf-gcc -I $(INCLUDES) src/fs/fat $(FLAGS) -c $^ -o $@
  115.  
  116. build/disk/disk_stream.o: src/disk/disk_stream.c
  117. i686-elf-gcc -I $(INCLUDES) src/disk $(FLAGS) -c $^ -o $@
  118.  
  119. run:
  120. qemu-system-i386 -drive file=bin/disk.img,index=0,media=disk,format=raw
  121.  
  122. clean:
  123. rm -rf bin/boot.bin
  124. rm -rf bin/kernel.bin
  125. rm -rf bin/os.bin
  126. rm -rf build/kernelfull.o
  127. rm -rf ${MODULES}
  128. rm -rf bin/disk.img
  129. rm -rf ./hello.txt
  130.  
  131.  
  132.  
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement