Makefile 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ###############################################################################
  2. # makefile
  3. # by Alex Chadwick
  4. #
  5. # A makefile script for generation of raspberry pi kernel images.
  6. ###############################################################################
  7. # The toolchain to use. arm-none-eabi works, but there does exist
  8. # arm-bcm2708-linux-gnueabi.
  9. #ARMGNU ?= arm-none-eabi
  10. # The intermediate directory for compiled object files.
  11. BUILD = build/
  12. # The directory in which source files are stored.
  13. SOURCE = source/
  14. # The name of the output file to generate.
  15. TARGET = kernel.img
  16. # The name of the assembler listing file to generate.
  17. LIST = kernel.list
  18. # The name of the map file to generate.
  19. MAP = kernel.map
  20. # The name of the linker script to use.
  21. LINKER = kernel.ld
  22. # The names of libraries to use.
  23. LIBRARIES := csud
  24. #CFLAGS := -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -Werror -fno-omit-frame-pointer -nostdinc -nostdlib -fno-stack-protector
  25. CFLAGS := -fno-pic -static -Wno-packed-bitfield-compat -fno-builtin -fno-strict-aliasing -fshort-wchar -O2 -Wall -MD -ggdb -Werror -fno-omit-frame-pointer -fno-stack-protector -Wa,-march=armv6 -Wa,-mcpu=arm1176jzf-s -I include
  26. CC := gcc
  27. # The names of all object files that must be generated. Deduced from the
  28. # assembly code files in source.
  29. OBJECTS := $(patsubst $(SOURCE)%.s,$(BUILD)%.o,$(wildcard $(SOURCE)*.s))
  30. C_OBJS := $(patsubst $(SOURCE)%.c,$(BUILD)%.o,$(wildcard $(SOURCE)*.c))
  31. # Rule to make everything.
  32. all: $(TARGET) $(LIST)
  33. # Rule to remake everything. Does not include clean.
  34. #rebuild: all
  35. # Rule to make the listing file.
  36. $(LIST) : $(BUILD)output.elf
  37. $(ARMGNU)-objdump -d $(BUILD)output.elf > $(LIST)
  38. # Rule to make the image file.
  39. $(TARGET) : $(BUILD)output.elf
  40. $(ARMGNU)-objcopy $(BUILD)output.elf -O binary $(TARGET)
  41. # Rule to make the elf file.
  42. $(BUILD)output.elf : $(OBJECTS) $(C_OBJS) $(LINKER)
  43. $(ARMGNU)-ld --no-undefined $(OBJECTS) $(C_OBJS) -L. $(patsubst %,-l %,$(LIBRARIES)) -Map $(MAP) -o $(BUILD)output.elf -T $(LINKER)
  44. # Rule to make the object files.
  45. $(BUILD)%.o: $(SOURCE)%.s $(BUILD)
  46. $(ARMGNU)-as -I $(SOURCE) $< -o $@
  47. $(BUILD)%.o: $(SOURCE)%.c $(BUILD)
  48. $(CC) -c $(CFLAGS) $< -o $@
  49. $(BUILD):
  50. mkdir $@
  51. # Rule to clean files.
  52. clean :
  53. -rm -rf $(BUILD)
  54. -rm -f $(TARGET)
  55. -rm -f $(LIST)
  56. -rm -f $(MAP)