Rules.mk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #
  2. # Rules.mk
  3. #
  4. # Circle - A C++ bare metal environment for Raspberry Pi
  5. # Copyright (C) 2014-2018 R. Stange <rsta2@o2online.de>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ifeq ($(strip $(CIRCLEHOME)),)
  21. CIRCLEHOME = ..
  22. endif
  23. -include $(CIRCLEHOME)/Config.mk
  24. RASPPI ?= 1
  25. PREFIX ?= arm-none-eabi-
  26. # see: doc/stdlib-support.txt
  27. STDLIB_SUPPORT ?= 1
  28. # set this to "softfp" if you want to link specific libraries
  29. FLOAT_ABI ?= hard
  30. CC = $(PREFIX)gcc
  31. CPP = $(PREFIX)g++
  32. AS = $(CC)
  33. LD = $(PREFIX)ld
  34. AR = $(PREFIX)ar
  35. ifeq ($(strip $(RASPPI)),1)
  36. ARCH ?= -march=armv6k -mtune=arm1176jzf-s -marm -mfpu=vfp -mfloat-abi=$(FLOAT_ABI)
  37. TARGET ?= kernel
  38. else ifeq ($(strip $(RASPPI)),2)
  39. ARCH ?= -march=armv7-a -marm -mfpu=neon-vfpv4 -mfloat-abi=$(FLOAT_ABI)
  40. TARGET ?= kernel7
  41. else
  42. ARCH ?= -march=armv8-a -mtune=cortex-a53 -marm -mfpu=neon-fp-armv8 -mfloat-abi=$(FLOAT_ABI)
  43. TARGET ?= kernel8-32
  44. endif
  45. MAKE_VERSION_MAJOR := $(firstword $(subst ., ,$(MAKE_VERSION)))
  46. ifneq ($(filter 0 1 2 3,$(MAKE_VERSION_MAJOR)),)
  47. $(error Requires GNU make 4.0 or newer)
  48. endif
  49. ifeq ($(strip $(STDLIB_SUPPORT)),3)
  50. LIBSTDCPP != $(CPP) $(ARCH) -print-file-name=libstdc++.a
  51. EXTRALIBS += $(LIBSTDCPP)
  52. LIBGCC_EH != $(CPP) $(ARCH) -print-file-name=libgcc_eh.a
  53. ifneq ($(strip $(LIBGCC_EH)),libgcc_eh.a)
  54. EXTRALIBS += $(LIBGCC_EH)
  55. endif
  56. else
  57. CPPFLAGS += -fno-exceptions -fno-rtti -nostdinc++
  58. endif
  59. ifeq ($(strip $(STDLIB_SUPPORT)),0)
  60. CFLAGS += -nostdinc
  61. else
  62. LIBGCC != $(CPP) $(ARCH) -print-file-name=libgcc.a
  63. EXTRALIBS += $(LIBGCC)
  64. endif
  65. OPTIMIZE ?= -O2
  66. INCLUDE += -I $(CIRCLEHOME)/include -I $(CIRCLEHOME)/addon -I $(CIRCLEHOME)/app/lib
  67. AFLAGS += $(ARCH) -DRASPPI=$(RASPPI) -DSTDLIB_SUPPORT=$(STDLIB_SUPPORT) $(INCLUDE)
  68. CFLAGS += $(ARCH) -Wall -fsigned-char -ffreestanding \
  69. -D__circle__ -DRASPPI=$(RASPPI) -DSTDLIB_SUPPORT=$(STDLIB_SUPPORT) \
  70. $(INCLUDE) $(OPTIMIZE) -g #-DNDEBUG
  71. CPPFLAGS+= $(CFLAGS) -std=c++14
  72. %.o: %.S
  73. $(AS) $(AFLAGS) -c -o $@ $<
  74. %.o: %.c
  75. $(CC) $(CFLAGS) -c -o $@ $<
  76. %.o: %.cpp
  77. $(CPP) $(CPPFLAGS) -c -o $@ $<
  78. $(TARGET).img: $(OBJS) $(LIBS) $(CIRCLEHOME)/lib/startup.o $(CIRCLEHOME)/circle.ld
  79. $(LD) -o $(TARGET).elf -Map $(TARGET).map -T $(CIRCLEHOME)/circle.ld $(CIRCLEHOME)/lib/startup.o $(OBJS) $(EXTRALIBS) $(LIBS) $(EXTRALIBS)
  80. $(PREFIX)objdump -d $(TARGET).elf | $(PREFIX)c++filt > $(TARGET).lst
  81. $(PREFIX)objcopy $(TARGET).elf -O binary $(TARGET).img
  82. wc -c $(TARGET).img
  83. clean:
  84. rm -f *.o *.a *.elf *.lst *.img *.hex *.cir *.map *~ $(EXTRACLEAN)