Makefile.common 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. # Set to @ if you want to suppress command echo
  2. CMD_ECHO =
  3. # Important directories
  4. BUILD_DIR = ./Build
  5. # Toolchain location and prefix
  6. #TOOLCHAIN =
  7. TOOLCHAIN ?= /opt/gcc-arm-none-eabi/bin/arm-none-eabi-
  8. # Tools selection
  9. CC = $(TOOLCHAIN)gcc
  10. AS = $(CC)
  11. LD = $(CC)
  12. AR = $(TOOLCHAIN)ar
  13. NM = $(TOOLCHAIN)nm
  14. OBJCOPY ?= $(TOOLCHAIN)objcopy
  15. OBJDUMP ?= $(TOOLCHAIN)objdump
  16. SIZE ?= $(TOOLCHAIN)size
  17. # Includes
  18. USER_SETTINGS_DIR ?= ./Header
  19. INC = -I$(USER_SETTINGS_DIR) \
  20. -I../..
  21. # Defines
  22. DEF = -DWOLFSSL_USER_SETTINGS
  23. # Architecture
  24. ARCHFLAGS ?= -mcpu=cortex-m4 -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP
  25. #ARCHFLAGS = -mcpu=cortex-m0 -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP
  26. #ARCHFLAGS = -mcpu=cortex-r5 -mthumb -mabi=aapcs
  27. #ARCHFLAGS = -mcpu=cortex-a53 -mthumb -mabi=aapcs
  28. # Compiler and linker flags
  29. ASFLAGS ?= $(ARCHFLAGS)
  30. CFLAGS_EXTRA ?= -Wno-cpp
  31. CFLAGS ?= $(ARCHFLAGS) -std=gnu99 -Wall $(CFLAGS_EXTRA)
  32. LDFLAGS ?= $(ARCHFLAGS)
  33. FIPS?=1
  34. # LD: Link with nosys
  35. LDFLAGS += --specs=nosys.specs
  36. # LD: Link with nano or rdimon implementation for standard library
  37. LDFLAGS += --specs=nano.specs
  38. #LDFLAGS += --specs=rdimon.specs
  39. # LD: generate map
  40. LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(BIN).map
  41. # LD: Entry point
  42. LDFLAGS += -Wl,-ereset_handler
  43. # Math lib (for DH)
  44. LIBS = -lm
  45. # Memory Map
  46. SRC_LD = -T./linker.ld
  47. # Optimization level and place functions / data into separate sections to allow dead code removal
  48. CFLAGS += -Os -ffunction-sections -fdata-sections -fno-builtin
  49. # Remove unused sections and link time optimizations
  50. LDFLAGS += -Wl,--gc-sections -flto
  51. # Debugging
  52. #DBGFLAGS = -ggdb -g3
  53. CFLAGS += $(DBGFLAGS)
  54. LDFLAGS += $(DBGFLAGS)
  55. # FILES
  56. # Port and Test/Benchmark
  57. ifndef NO_EXAMPLES
  58. SRC_C += ./Source/wolf_main.c
  59. SRC_C += ./Source/armtarget.c
  60. SRC_C += ../../wolfcrypt/test/test.c
  61. SRC_C += ../../wolfcrypt/benchmark/benchmark.c
  62. endif
  63. # WOLFSSL TLS FILES
  64. SRC_C += ../../src/bio.c
  65. SRC_C += ../../src/crl.c
  66. SRC_C += ../../src/internal.c
  67. SRC_C += ../../src/keys.c
  68. SRC_C += ../../src/ocsp.c
  69. SRC_C += ../../src/sniffer.c
  70. SRC_C += ../../src/ssl.c
  71. SRC_C += ../../src/tls.c
  72. SRC_C += ../../src/tls13.c
  73. SRC_C += ../../src/wolfio.c
  74. # wolfCrypt Core (FIPS)
  75. ifeq "$(FIPS)" "1"
  76. SRC_C += ../../wolfcrypt/src/wolfcrypt_first.c
  77. endif
  78. SRC_C += ../../wolfcrypt/src/aes.c
  79. SRC_C += ../../wolfcrypt/src/cmac.c
  80. SRC_C += ../../wolfcrypt/src/des3.c
  81. SRC_C += ../../wolfcrypt/src/dh.c
  82. SRC_C += ../../wolfcrypt/src/ecc.c
  83. SRC_C += ../../wolfcrypt/src/hmac.c
  84. SRC_C += ../../wolfcrypt/src/random.c
  85. SRC_C += ../../wolfcrypt/src/rsa.c
  86. SRC_C += ../../wolfcrypt/src/sha.c
  87. SRC_C += ../../wolfcrypt/src/sha256.c
  88. SRC_C += ../../wolfcrypt/src/sha512.c
  89. SRC_C += ../../wolfcrypt/src/sha3.c
  90. ifeq "$(FIPS)" "1"
  91. SRC_C += ../../wolfcrypt/src/fips.c
  92. SRC_C += ../../wolfcrypt/src/fips_test.c
  93. SRC_C += ../../wolfcrypt/src/wolfcrypt_last.c
  94. endif
  95. # wolfCrypt Additional
  96. SRC_C += ../../wolfcrypt/src/asm.c
  97. SRC_C += ../../wolfcrypt/src/asn.c
  98. SRC_C += ../../wolfcrypt/src/blake2s.c
  99. SRC_C += ../../wolfcrypt/src/chacha.c
  100. SRC_C += ../../wolfcrypt/src/chacha20_poly1305.c
  101. SRC_C += ../../wolfcrypt/src/coding.c
  102. SRC_C += ../../wolfcrypt/src/compress.c
  103. SRC_C += ../../wolfcrypt/src/cpuid.c
  104. SRC_C += ../../wolfcrypt/src/cryptocb.c
  105. SRC_C += ../../wolfcrypt/src/curve25519.c
  106. SRC_C += ../../wolfcrypt/src/curve448.c
  107. SRC_C += ../../wolfcrypt/src/ecc_fp.c
  108. SRC_C += ../../wolfcrypt/src/eccsi.c
  109. SRC_C += ../../wolfcrypt/src/ed25519.c
  110. SRC_C += ../../wolfcrypt/src/ed448.c
  111. SRC_C += ../../wolfcrypt/src/error.c
  112. SRC_C += ../../wolfcrypt/src/evp.c
  113. SRC_C += ../../wolfcrypt/src/fe_448.c
  114. SRC_C += ../../wolfcrypt/src/fe_low_mem.c
  115. SRC_C += ../../wolfcrypt/src/fe_operations.c
  116. SRC_C += ../../wolfcrypt/src/ge_448.c
  117. SRC_C += ../../wolfcrypt/src/ge_low_mem.c
  118. SRC_C += ../../wolfcrypt/src/ge_operations.c
  119. SRC_C += ../../wolfcrypt/src/hash.c
  120. SRC_C += ../../wolfcrypt/src/kdf.c
  121. SRC_C += ../../wolfcrypt/src/integer.c
  122. SRC_C += ../../wolfcrypt/src/logging.c
  123. SRC_C += ../../wolfcrypt/src/md5.c
  124. SRC_C += ../../wolfcrypt/src/memory.c
  125. SRC_C += ../../wolfcrypt/src/misc.c
  126. SRC_C += ../../wolfcrypt/src/pkcs12.c
  127. SRC_C += ../../wolfcrypt/src/pkcs7.c
  128. SRC_C += ../../wolfcrypt/src/poly1305.c
  129. SRC_C += ../../wolfcrypt/src/pwdbased.c
  130. SRC_C += ../../wolfcrypt/src/rc2.c
  131. SRC_C += ../../wolfcrypt/src/sakke.c
  132. SRC_C += ../../wolfcrypt/src/signature.c
  133. SRC_C += ../../wolfcrypt/src/srp.c
  134. SRC_C += ../../wolfcrypt/src/sp_arm32.c
  135. SRC_C += ../../wolfcrypt/src/sp_arm64.c
  136. SRC_C += ../../wolfcrypt/src/sp_armthumb.c
  137. SRC_C += ../../wolfcrypt/src/sp_c32.c
  138. SRC_C += ../../wolfcrypt/src/sp_c64.c
  139. SRC_C += ../../wolfcrypt/src/sp_cortexm.c
  140. SRC_C += ../../wolfcrypt/src/sp_dsp32.c
  141. SRC_C += ../../wolfcrypt/src/sp_int.c
  142. SRC_C += ../../wolfcrypt/src/sp_x86_64.c
  143. SRC_C += ../../wolfcrypt/src/tfm.c
  144. SRC_C += ../../wolfcrypt/src/wc_dsp.c
  145. SRC_C += ../../wolfcrypt/src/wc_encrypt.c
  146. SRC_C += ../../wolfcrypt/src/wc_pkcs11.c
  147. SRC_C += ../../wolfcrypt/src/wc_port.c
  148. SRC_C += ../../wolfcrypt/src/wolfevent.c
  149. SRC_C += ../../wolfcrypt/src/wolfmath.c
  150. ifeq "$(ASYNC)" "1"
  151. SRC_C += ../../wolfcrypt/src/async.c
  152. endif
  153. ifeq "$(SELFTEST)" "1"
  154. SRC_C += ../../wolfcrypt/src/selftest.c
  155. endif
  156. # wolfCrypt non-standard algorithms (disabled by default)
  157. SRC_C += ../../wolfcrypt/src/arc4.c
  158. SRC_C += ../../wolfcrypt/src/blake2b.c
  159. SRC_C += ../../wolfcrypt/src/camellia.c
  160. SRC_C += ../../wolfcrypt/src/dsa.c
  161. SRC_C += ../../wolfcrypt/src/hc128.c
  162. SRC_C += ../../wolfcrypt/src/idea.c
  163. SRC_C += ../../wolfcrypt/src/md2.c
  164. SRC_C += ../../wolfcrypt/src/md4.c
  165. SRC_C += ../../wolfcrypt/src/rabbit.c
  166. SRC_C += ../../wolfcrypt/src/ripemd.c
  167. FILENAMES_C = $(notdir $(SRC_C))
  168. FILENAMES_C := $(filter-out evp.c, $(FILENAMES_C))
  169. OBJS_C = $(addprefix $(BUILD_DIR)/, $(FILENAMES_C:.c=.o))
  170. vpath %.c $(dir $(SRC_C))
  171. build_hex: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).hex
  172. @echo ""
  173. $(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(BIN).elf
  174. build_static: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).a
  175. @echo ""
  176. $(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(BIN).a
  177. $(BUILD_DIR):
  178. $(CMD_ECHO) mkdir -p $(BUILD_DIR)
  179. $(BUILD_DIR)/$(BIN).hex: $(BUILD_DIR)/$(BIN).elf
  180. @echo "Generating HEX binary: $(notdir $@)"
  181. $(CMD_ECHO) $(OBJCOPY) -O ihex $< $@
  182. $(BUILD_DIR)/%.o: %.s
  183. @echo "Compiling ASM file: $(notdir $<)"
  184. $(CMD_ECHO) $(AS) $(ASFLAGS) $(DEF) $(INC) -c -o $@ $<
  185. $(BUILD_DIR)/%.o: %.c
  186. @echo "Compiling C file: $(notdir $<)"
  187. $(CMD_ECHO) $(CC) $(CFLAGS) $(DEF) $(INC) -c -o $@ $<
  188. $(BUILD_DIR)/$(BIN).elf: $(OBJS_ASM) $(OBJS_C)
  189. @echo "Linking ELF binary: $(notdir $@)"
  190. $(CMD_ECHO) $(LD) $(LDFLAGS) $(SRC_LD) -o $@ $^ $(LIBS)
  191. @echo "Generating name list: $(BIN).sym"
  192. $(CMD_ECHO) $(NM) -n $@ > $(BUILD_DIR)/$(BIN).sym
  193. @echo "Showing final size:"
  194. $(CMD_ECHO) ls -la $@
  195. @echo "Generating disassembly: $(BIN).disasm"
  196. $(CMD_ECHO) $(OBJDUMP) -S $@ > $(BUILD_DIR)/$(BIN).disasm
  197. $(BUILD_DIR)/$(BIN).a: $(OBJS_ASM) $(OBJS_C)
  198. @echo "Building static library: $(notdir $@)"
  199. $(CMD_ECHO) $(AR) -r $@ $^
  200. @echo "Generating name list: $(BIN).sym"
  201. $(CMD_ECHO) $(NM) -n $@ > $(BUILD_DIR)/$(BIN).sym
  202. @echo "Showing final size:"
  203. $(CMD_ECHO) ls -la $@
  204. @echo "Generating disassembly: $(BIN).disasm"
  205. $(CMD_ECHO) $(OBJDUMP) -S $@ > $(BUILD_DIR)/$(BIN).disasm
  206. clean:
  207. rm -f $(BUILD_DIR)/*.elf $(BUILD_DIR)/*.hex $(BUILD_DIR)/*.map
  208. rm -f $(BUILD_DIR)/*.o $(BUILD_DIR)/*.a $(BUILD_DIR)/*.sym $(BUILD_DIR)/*.disasm