Advertisement
timofiend

Pi Kernel Makefile

Apr 14th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 2.49 KB | None | 0 0
  1. #-------------------------------------#
  2. #          OS Kernel Makefile         #            
  3. #-------------------------------------#
  4.  
  5. #
  6. # Current functionality:
  7. #
  8. #   Creation of binary images to be
  9. #   loaded by bootloader
  10. #
  11.  
  12. # Toolchain to use
  13. ARMGNU ?= arm-none-eabi
  14.  
  15. # Directory for misc build objects
  16. BUILD = build/
  17.  
  18. # Directory for c build objs
  19. CBUILD = build/c/
  20.  
  21. # Directory for assembly build objs
  22. ASBUILD = build/as/
  23.  
  24. # Directory for src objects
  25. SOURCE = src/
  26.  
  27. # Name of output file
  28. TARGET = harpos.bin
  29.  
  30. # Name of assembler list file to generate
  31. LIST = $(BUILD)harpos.list
  32.  
  33. # Name of map file to generate
  34. MAP = $(BUILD)harpos.map
  35.  
  36. # Name of linker script to use
  37. LINKER = memorymap.ld
  38.  
  39. # Additional libraries
  40. LIBRARIES =
  41. #csud
  42.  
  43. # Additional compiler flags for c files
  44. # General warning flags (wall), midlevel optimisations (02), no standard system startup files or libraries (nostdlib nostartfiles)
  45. # assert freestanding environment where stdlib may not exist and program startup may not be at main (freestanding) treat wchar as 16bit value (short-wchar)
  46. COPTS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding -fshort-wchar
  47.  
  48. # Names of object files to be built
  49. # Uses pattern substitute to find source files and add object names
  50. # Assembly files then c files
  51. OBJS = $(patsubst $(SOURCE)%.s,$(ASBUILD)%.o,$(wildcard $(SOURCE)*.s)) $(patsubst $(SOURCE)%.c,$(CBUILD)%.o,$(wildcard $(SOURCE)*.c))
  52.  
  53. # Rule for all
  54. all: $(TARGET)
  55.  
  56. # Rule to make target image : depends on elf
  57. # Objcopy elf to binary image
  58. $(TARGET) : $(BUILD)harpos.elf
  59.     $(ARMGNU)-objcopy $(BUILD)harpos.elf -O binary $(TARGET)
  60.  
  61. # Rule to make elf : depends on objects and linker script
  62. # Link all objects, link to additional libraries, create map file, output to harpos.elf, replace default linker script with ours
  63. # Objdump elf to list file
  64. # Objcopy elf to hex file
  65. $(BUILD)harpos.elf : $(LINKER) $(OBJS)
  66.     echo $(OBJS)
  67.     $(ARMGNU)-ld $(OBJS) -L. $(patsubst %,-l %,$(LIBRARIES)) -Map $(MAP) -o $(BUILD)harpos.elf -T $(LINKER)
  68.     $(ARMGNU)-objdump -D $(BUILD)harpos.elf > $(LIST)
  69.     $(ARMGNU)-objcopy $(BUILD)harpos.elf -O ihex $(BUILD)harpos.hex
  70.  
  71. # Rule to make the c object files.
  72. $(CBUILD)%.o: $(SOURCE)%.c
  73.     $(ARMGNU)-gcc $(COPTS) -c $< -o $@
  74.  
  75. # Rule to make the assembly object files.
  76. $(ASBUILD)%.o: $(SOURCE)%.s
  77.     $(ARMGNU)-as -I $(SOURCE) $< -o $@
  78.  
  79. # Rule to clean
  80. clean:
  81.     rm -f $(CBUILD)*.o
  82.     rm -f $(ASBUILD)*.o
  83.     rm -f $(BUILD)*.elf
  84.     rm -f $(BUILD)*.hex
  85.     rm -f $(TARGET)
  86.     rm -f $(LIST)
  87.     rm -f $(MAP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement