Advertisement
Guest User

Untitled

a guest
May 29th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. ARROW= ==>
  2.  
  3. #U365 Makefile configuration
  4.  
  5. LSCRIPT = link
  6. BUILD_DIR = build
  7. SRC_DIR = src
  8. INC_DIR = include
  9. VFS_DIR = vfs
  10. OS_VER = 0.7
  11.  
  12. #Filenames
  13.  
  14. ARCH = i686
  15. BINFORMAT = elf
  16. BITS = 32
  17. ISODIR = $(BUILD_DIR)/iso/fs
  18. GRUB_BIN = ~/i386-pc
  19. CROSS = ~/opt/cross
  20. CROSSBIN = $(CROSS)/bin/
  21. GAS = $(CROSSBIN)$(ARCH)-$(BINFORMAT)-as #AT&T-syntax assembler
  22. CC = $(CROSSBIN)$(ARCH)-$(BINFORMAT)-gcc
  23. IASM = nasm #Intel-syntax assembler
  24. ISOFILE = u365-$(OS_VER)#Compiled ELF binary and ISO image name.
  25. BINFILE = u365
  26. EMU = qemu-system-i386 -cdrom build/releases/u365-0.7.iso -m 128
  27. EFLAGS = -cdrom $(BUILD_DIR)/releases/$(ISOFILE).iso -m 128
  28. DEFS = -DOSVER="$(OS_VER)"
  29. MKRSCFLAGS = -d $(GRUB_BIN) -o $(BUILD_DIR)/releases/$(ISOFILE).iso $(ISODIR)
  30. CFLAGS = -O3 -ffreestanding -Wall -Wextra -Wmaybe-uninitialized -fno-exceptions -std=gnu11 -Iinclude -c $(DEFS) -Wtype-limits
  31. GASFLAGS =
  32. IASFLAGS = -f $(BINFORMAT)
  33. LDFLAGS = -T $(LSCRIPT).ld -o $(BUILD_DIR)/bin/$(BINFILE).$(BINFORMAT) -O3 -nostdlib -lgcc
  34.  
  35. # Source file names computing
  36. # Multiboot header first
  37. SOURCES := $(SRC_DIR)/arch/$(ARCH)/boot.asm
  38. # Al common sources
  39. SOURCES += $(shell find $(SRC_DIR) -name "*.c" -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
  40. SOURCES += $(shell find $(SRC_DIR) -name "*.s" -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
  41. SOURCES += $(shell find $(SRC_DIR) -name "*.asm" -and -not -path "$(SRC_DIR)/arch/*" -type f -print)
  42. # Architecture-dependent sources
  43. SOURCES += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.c' -type f -print)
  44. SOURCES += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.s' -type f -print)
  45. SOURCES += $(shell find $(SRC_DIR)/arch/$(ARCH) -name '*.asm' -and -not -path "$(SRC_DIR)/arch/$(ARCH)/boot.asm" -type f -print)
  46.  
  47. SRCDIRS := $(shell find $(SRC_DIR) -type d -print)
  48. VFSDIRS := $(shell find $(VFS_DIR) -type d -print)
  49. OBJDIRS := $(patsubst $(SRC_DIR)/%,"$(BUILD_DIR)/obj/%",$(SRCDIRS))
  50. CFSDIRS := $(patsubst $(VFS_DIR)/tree/%,"$(VFS_DIR)/conv/%",$(VFSDIRS))
  51.  
  52. FAKE := $(shell echo $(SOURCES))
  53. # Object file names computing
  54. OBJS := $(patsubst $(SRC_DIR)/%.c,"$(BUILD_DIR)/obj/%.c.o",$(SOURCES))
  55. #OBJS := $(patsubst $(SRC_DIR)/libc/%.c,"$(BUILD_DIR)/obj/libc/%.c.o",$(SOURCES))
  56. OBJS := $(patsubst $(SRC_DIR)/%.s,"$(BUILD_DIR)/obj/%.s.o",$(OBJS))
  57. OBJS := $(patsubst $(SRC_DIR)/%.asm,"$(BUILD_DIR)/obj/%.asm.o",$(OBJS))
  58.  
  59. #End
  60.  
  61. # target _welcome dependencies
  62. all: _welcome clean directories compile link initrd iso run
  63. @echo -n
  64.  
  65. # Welcome user at make call
  66. _welcome:
  67. @echo " Makefile: U365"
  68.  
  69. compile: _welcome clean directories _compile $(SOURCES)
  70. # @echo -e " $(ARROW) Compiling GDT"
  71. # @$(IASM) $(SRC_DIR)/arch/$(ARCH)/gdt.s -o $(BUILD_DIR)/obj/gdt.o $(IASFLAGS)
  72. # @echo -e " $(ARROW) Compiling IDT"
  73. # @$(IASM) $(SRC_DIR)/arch/$(ARCH)/idt.s -o $(BUILD_DIR)/obj/idt.o $(IASFLAGS)
  74. # @echo -e " $(ARROW) Compiling C sources"
  75. # @$(CC) $(SOURCES) $(SRC_DIR)/arch/$(ARCH)/init.c $(IOBJS) $(CFLAGS) $(LDFLAGS)
  76. @echo -n
  77. initrd: _welcome clean directories
  78. @echo " $(ARROW) Generating initrd"
  79. @cd initrd; tar -cf ../build/iso/fs/boot/initrd.tar *
  80.  
  81.  
  82. link: _welcome clean directories compile
  83. @echo " $(ARROW) Linking"
  84. @$(CC) $(OBJS) $(LDFLAGS)
  85.  
  86.  
  87. iso: _welcome directories
  88. @echo " $(ARROW) Generating an ISO image"
  89.  
  90. echo "insmod gfxterm; \
  91. insmod vbe; \
  92. timeout=5; \
  93. set gfxmode=1024x768; \
  94. menuentry \"U365 Basic System 1.0\" \
  95. { \
  96. echo 'Loading kernel...'; \
  97. multiboot /boot/u365.elf; \
  98. echo 'Loading initrd...' ;\
  99. module /boot/initrd.tar initrd; \
  100. boot; \
  101. } \
  102. " > $(BUILD_DIR)/iso/fs/grub.cfg
  103.  
  104. cp $(BUILD_DIR)/iso/fs/grub.cfg $(BUILD_DIR)/iso/fs/boot/grub/grub.cfg
  105. cp $(BUILD_DIR)/bin/$(BINFILE).$(BINFORMAT) $(BUILD_DIR)/iso/fs/boot/
  106. /usr/local/bin/grub-mkrescue $(MKRSCFLAGS)
  107. echo -n
  108. ##########################################################
  109.  
  110. #run: _welcome
  111. #
  112. # qemu-system-i386 -cdrom ~/desktop/Важное/U365/build/releases/u365-0.7.iso -m 128
  113. #
  114.  
  115. ##########################################################
  116.  
  117. clean: _welcome
  118. @echo " $(ARROW) Cleaning"
  119. @rm -rf $(BUILD_DIR) $(VFS_DIR)/conv *.iso initrd.tar
  120. @echo -n
  121.  
  122. directories: _welcome
  123. @echo " $(ARROW) Creating build directories"
  124. @mkdir -p $(OBJDIRS) $(CFSDIRS) $(BUILD_DIR)/bin $(BUILD_DIR)/iso/fs/boot $(BUILD_DIR)/iso/fs/boot/grub $(BUILD_DIR)/iso/fs/fonts $(BUILD_DIR)/releases
  125. @echo -n
  126.  
  127. Makefile:
  128. @echo " Strange make bug prevented"
  129.  
  130. # Compilation notification - do not remove
  131. _compile:
  132. @echo " $(ARROW) Compiling"
  133. # Compilation routines
  134. %.c: _welcome directories _compile
  135. @echo " Building C file: $@"
  136. @$(CC) $@ -o $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/obj/%.c.o,$@) $(CFLAGS)
  137. @echo -n
  138.  
  139. %.s: _welcome directories _compile
  140. @echo " Building GAS file: $@"
  141. @$(GAS) $@ -o $(patsubst $(SRC_DIR)/%.s,$(BUILD_DIR)/obj/%.s.o,$@)
  142. @echo -n
  143.  
  144. %.asm: _welcome directories _compile
  145. @echo " Building IAS file: $@"
  146. @$(IASM) $@ -o $(patsubst $(SRC_DIR)/%.asm,$(BUILD_DIR)/obj/%.asm.o,$@) $(IASFLAGS)
  147. @echo -n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement