Makefile 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Aedrix root Makefile
  2. # Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
  3. # Config options for the code itself (should be separated from the Makefile sometime)
  4. ARCH ?= arm
  5. #ARCH_KCFLAGS defined (if at all) in arch/$(ARCH)/kernel.mk
  6. #CROSS_COMPILE defined (if at all) in arch/$(ARCH)/kernel.mk
  7. # Config options concerning the build process itself
  8. VERBOSE ?= 0 # 1 shows all compiler flags, 0 shows cleaner output
  9. V = $(if $(VERBOSE:1=),@) # Use this to prefix commands that should only be shown when VERBOSE==1
  10. # Define the tools to be used
  11. AS = $(CROSS_COMPILE)as
  12. CC = $(CROSS_COMPILE)gcc
  13. LD = $(CROSS_COMPILE)ld
  14. OBJCOPY = $(CROSS_COMPILE)objcopy
  15. OBJDUMP = $(CROSS_COMPILE)objdump
  16. # Define the flags we'll need for our tools
  17. INCLUDES = -I include -I arch/$(ARCH)/include
  18. KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(ARCH_KCFLAGS) -include config.h $(INCLUDES)
  19. KLDFLAGS = -T arch/$(ARCH)/kernel.ld $(ARCH_KLDFLAGS)
  20. EXTRA_LIBS = $(ARCH_EXTRA_LIBS)
  21. # Include the config file so we don't compile/link unnecessary objects
  22. include config
  23. # Define KOBJS as a 'simply expanded' variable
  24. KOBJS :=
  25. # Initialize sub-directory Makefile inclusion
  26. BASEDIR = $(shell pwd)
  27. SUBDIRS := arch/$(ARCH) kernel drivers
  28. ifneq (,$(SUBDIRS))
  29. include $(patsubst %,%/kernel.mk,$(SUBDIRS))
  30. endif
  31. .PHONY: all tags clean boot boot-gdb
  32. all: aedrix-kernel.img aedrix-kernel.elf
  33. aedrix-kernel.elf: $(KOBJS)
  34. @echo ' LD $@'
  35. $(V)$(LD) $(KLDFLAGS) -o $@ $(KOBJS) $(EXTRA_LIBS)
  36. aedrix-kernel.objdump: aedrix-kernel.elf
  37. @echo 'OBJDUMP $@'
  38. $(V)$(OBJDUMP) -D $< > $@
  39. aedrix-kernel.img: aedrix-kernel.elf
  40. @echo 'OBJCOPY $@'
  41. $(V)$(OBJCOPY) $< -O binary $@
  42. %.o: %.c config.h
  43. @echo ' CC $@'
  44. $(V)$(CC) $(KCFLAGS) -MD -c -o $@ $<
  45. @# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html)
  46. @cp $*.d $(*D)/.$(*F).d; \
  47. sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
  48. -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \
  49. rm -f $*.d
  50. %.o: %.S config.h
  51. @echo ' AS $@'
  52. $(V)$(CC) $(KCFLAGS) -MD -c -o $@ $<
  53. @# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html)
  54. @cp $*.d $(*D)/.$(*F).d; \
  55. sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
  56. -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \
  57. rm -f $*.d
  58. config.h: config
  59. @# Generate config header file from make-style include
  60. @echo ' CONFIG config.h'
  61. @cp config config.h
  62. @sed -i '/^\s*#/d' config.h
  63. @sed -i 's/#.*$$//g' config.h
  64. @sed -i '/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[nN]/d' config.h
  65. @sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[yY]/#define \1/g' config.h
  66. @sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*\([0-9]\+\)/#define \1 \2/g' config.h
  67. tags:
  68. @echo ' CTAGS tags'
  69. $(V)ctags -R $(SUBDIRS)
  70. clean:
  71. @echo ' CLEAN config.h'
  72. $(V)rm -f config.h
  73. @echo ' CLEAN *.o'
  74. $(V)rm -f $(KOBJS)
  75. @echo ' CLEAN .*.d'
  76. $(V)rm -f $(DEPENDENCY_FILES)
  77. @echo ' CLEAN aedrix-kernel.elf'
  78. $(V)rm -f aedrix-kernel.elf
  79. @echo ' CLEAN aedrix-kernel.objdump'
  80. $(V)rm -f aedrix-kernel.objdump
  81. @echo ' CLEAN aedrix-kernel.img'
  82. $(V)rm -f aedrix-kernel.img
  83. @echo ' CLEAN tags'
  84. $(V)rm -f tags
  85. boot-elf: aedrix-kernel.elf
  86. $(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.elf -serial stdio
  87. boot-img: aedrix-kernel.img
  88. $(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.img -serial stdio
  89. boot-hda: aedrix-boot.img
  90. $(V)$(ARCH_QEMU_CMD) -hda aedrix-boot.img -serial stdio
  91. boot-elf-gdb: aedrix-kernel.elf
  92. $(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.elf -serial stdio -S -s
  93. boot-img-gdb: aedrix-kernel.img
  94. $(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.img -serial stdio -S -s
  95. boot-hda-gdb: aedrix-boot.img
  96. $(V)$(ARCH_QEMU_CMD) -hda aedrix-boot.img -serial stdio -S -s
  97. DEPENDENCY_FILES = $(foreach file,$(KOBJS), $(dir $(file)).$(notdir $(basename $(file))).d)
  98. -include $(DEPENDENCY_FILES)