Advertisement
lfed255-dev

makefile

May 11th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. cat makefile
  2.  
  3. ifeq ($(OS),Windows_NT)
  4. BUILDOS ?= win
  5. else
  6. BUILDOS ?= nix
  7. endif
  8. ARCH?=x86
  9. DEBUG?=on
  10. OSVER?=1.0
  11. OSNAME?=DepthOS
  12. CC=gcc
  13. LD=ld
  14. ASM=nasm -f elf32
  15. CSTD=11
  16. CEMU=-m32
  17. CCFLAGS= -Iinclude -ffreestanding -nostdlib -nostdinc -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pic
  18. CCFLAGS += -W -Wall -Wno-unused-parameter -Wno-type-limits -Werror -Wno-parentheses -Wno-unused-variable -Wno-maybe-uninitialized
  19. ASFLAGS = -m32
  20. ifeq ($(BUILDOS),win)
  21. LDEMU=-mi386pe
  22. else
  23. LDEMU=-melf_i386
  24. endif
  25. LDFILE=link.ld
  26.  
  27. OUTBIN=$(OSNAME)-$(OSVER)
  28. # CSOURCES ?=
  29. # ASMSOURCES ?=
  30. # NASMSOURCES ?=
  31. CSOURCES +=kmain.c
  32. NASMSOURCES +=loader.asm
  33. #CSOURCES += $(shell find . -name "*.c" -type f -print )
  34. #ASMSOURCES += $(shell find . -name "*.s" -type f -print )
  35. #NASMSOURCES += $(shell find . -name "*.asm" -type f -print )
  36. CSOURCES +=$(wildcard */*.c)
  37. ASMSOURCES +=$(wildcard */*.S)
  38. ASMSOURCES +=$(wildcard */*.s)
  39. NASMSOURCES +=$(wildcard */*.asm)
  40. # OBJS=build/*.o
  41. # .PHONY: all clean
  42.  
  43. CSOURCES+=$(wildcard */$(ARCH)/*.c)
  44. ASMSOURCES+=$(wildcard */$(ARCH)/*.S)
  45. ASMSOURCES+=$(wildcard */$(ARCH)/*.s)
  46. NASMSOURCES+=$(wildcard */$(ARCH)/*.asm)
  47.  
  48. all: os_info clean build test
  49.  
  50.  
  51. os_info:
  52. @echo ---------- build $(OSNAME) ----------
  53. @echo -------- os version is $(OSVER) --------
  54. @echo ---------- build for $(BUILDOS) ----------
  55. @echo
  56.  
  57. clean:
  58. @rm -f build/*.o
  59. @rm -f build/*.bin
  60. @rm -f $(OSNAME)-*
  61.  
  62.  
  63. build: kernel img iso
  64.  
  65.  
  66. kernel: $(CSOURCES) $(ASMSOURCES) $(NASMSOURCES) $(LDFILE)
  67. @echo ---------- build kernel -----------
  68. ifeq ($(DEBUG),on)
  69. $(CC) $(CEMU) -std=c$(CSTD) -g -c -DOSVER=\"$(OSVER)\" $(CSOURCES) $(CCFLAGS)
  70. ifeq ($(DEBUG),true)
  71. $(CC) $(CEMU) -std=c$(CSTD) -g -c -DOSVER=\"$(OSVER)\" $(CSOURCES) $(CCFLAGS)
  72. endif
  73. else
  74. $(CC) $(CEMU) -std=c$(CSTD) -c -DOSVER=\"$(OSVER)\" $(CSOURCES) $(CCFLAGS)
  75. endif
  76. @mkdir -p build
  77. @mv *.o build/
  78. $(ASM) $(NASMSOURCES)
  79. gcc -m32 -c $(ASMSOURCES)
  80. @mv *.o build/
  81. $(LD) $(LDEMU) -T$(LDFILE) -Wl,--build-id=none -o build/$(OUTBIN).bin build/*.o
  82. ifeq ($(BUILDOS),win)
  83. objcopy -O elf32-i386 build/$(OUTBIN).bin $(OUTBIN)
  84. else
  85. cp build/$(OUTBIN).bin $(OUTBIN)
  86. endif
  87.  
  88. img:
  89.  
  90. iso:
  91.  
  92. hex_info:
  93. @echo ---------- HEX INFO ----------
  94. @echo loader hex info
  95. hexdump -x build/loader.o
  96. @echo kernel hex info
  97. hexdump -x $(OUTBIN)
  98. #dis_asm:
  99. # @echo ---------- DIS ASM ----------
  100. # @echo loader disasm
  101. # ndisasm -b 32 build/loader.o
  102. # @echo kernel disasm
  103. # ndisasm -b 32 $(OUTBIN)
  104. obj_info:
  105. @echo ---------- OBJ INFO ----------
  106. @echo loader obj info
  107. objdump -f -h build/loader.o
  108. @echo kernel obj info
  109. objdump -f -h $(OUTBIN)
  110. info: hex_info obj_info # dis_asm
  111.  
  112. test:
  113. @echo
  114. @echo ----------- testing os ------------
  115. @echo
  116. qemu-system-i386 -M pc-i440fx-2.8 -kernel $(OUTBIN) # -d cpu -D qemu_log.log # -d int,pcall,cpu,fpu # -nographic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement