Makefile 864 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ARCH = x86_64
  2. CROSS =
  3. AS = $(CROSS)as
  4. LD = $(CROSS)ld
  5. OBJCOPY = $(CROSS)objcopy
  6. # For arm and arm64 ld cannot produce flat binaries directly.
  7. # See binutils/ld/emultempl/armelf.em around the definition
  8. # of arm_elf_create_output_section_statements()
  9. NEEDSCOPY = arm arm64 mips mipsel mips64 mips64el
  10. USEOBJCOPY = $(if $(filter $(NEEDSCOPY),$(ARCH)),yes,no)
  11. hello: hello_$(ARCH)
  12. ifeq ($(USEOBJCOPY),yes)
  13. .INTERMEDIATE: hello_$(ARCH).elf
  14. hello_$(ARCH).elf: elf_$(ARCH).o hello_$(ARCH).o tiny.ld
  15. $(LD) -T tiny.ld -o $@ $(filter %.o, $^)
  16. hello_$(ARCH): hello_$(ARCH).elf
  17. $(OBJCOPY) -O binary $< $@
  18. else
  19. hello_$(ARCH): elf_$(ARCH).o hello_$(ARCH).o tiny.ld
  20. $(LD) --oformat binary -T tiny.ld -o $@ $(filter %.o, $^)
  21. endif
  22. %.o: %.s
  23. $(AS) -o $@ $<
  24. # Build *el (little-endian variant) from the same source.
  25. %el.o: %.s
  26. $(AS) -o $@ $<
  27. clean:
  28. rm -f *.o *.elf