1
0

Makefile.common 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/kdf.c
  85. SRC_C += ../../wolfcrypt/src/random.c
  86. SRC_C += ../../wolfcrypt/src/rsa.c
  87. SRC_C += ../../wolfcrypt/src/sha.c
  88. SRC_C += ../../wolfcrypt/src/sha256.c
  89. SRC_C += ../../wolfcrypt/src/sha512.c
  90. SRC_C += ../../wolfcrypt/src/sha3.c
  91. ifeq "$(FIPS)" "1"
  92. SRC_C += ../../wolfcrypt/src/fips.c
  93. SRC_C += ../../wolfcrypt/src/fips_test.c
  94. SRC_C += ../../wolfcrypt/src/wolfcrypt_last.c
  95. endif
  96. # wolfCrypt Additional
  97. SRC_C += ../../wolfcrypt/src/asm.c
  98. SRC_C += ../../wolfcrypt/src/asn.c
  99. SRC_C += ../../wolfcrypt/src/blake2s.c
  100. SRC_C += ../../wolfcrypt/src/chacha.c
  101. SRC_C += ../../wolfcrypt/src/chacha20_poly1305.c
  102. SRC_C += ../../wolfcrypt/src/coding.c
  103. SRC_C += ../../wolfcrypt/src/compress.c
  104. SRC_C += ../../wolfcrypt/src/cpuid.c
  105. SRC_C += ../../wolfcrypt/src/cryptocb.c
  106. SRC_C += ../../wolfcrypt/src/curve25519.c
  107. SRC_C += ../../wolfcrypt/src/curve448.c
  108. SRC_C += ../../wolfcrypt/src/ecc_fp.c
  109. SRC_C += ../../wolfcrypt/src/eccsi.c
  110. SRC_C += ../../wolfcrypt/src/ed25519.c
  111. SRC_C += ../../wolfcrypt/src/ed448.c
  112. SRC_C += ../../wolfcrypt/src/error.c
  113. SRC_C += ../../wolfcrypt/src/evp.c
  114. SRC_C += ../../wolfcrypt/src/fe_448.c
  115. SRC_C += ../../wolfcrypt/src/fe_low_mem.c
  116. SRC_C += ../../wolfcrypt/src/fe_operations.c
  117. SRC_C += ../../wolfcrypt/src/ge_448.c
  118. SRC_C += ../../wolfcrypt/src/ge_low_mem.c
  119. SRC_C += ../../wolfcrypt/src/ge_operations.c
  120. SRC_C += ../../wolfcrypt/src/hash.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/md2.c
  162. SRC_C += ../../wolfcrypt/src/md4.c
  163. SRC_C += ../../wolfcrypt/src/ripemd.c
  164. FILENAMES_C = $(notdir $(SRC_C))
  165. FILENAMES_C := $(filter-out evp.c, $(FILENAMES_C))
  166. OBJS_C = $(addprefix $(BUILD_DIR)/, $(FILENAMES_C:.c=.o))
  167. vpath %.c $(dir $(SRC_C))
  168. build_hex: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).hex
  169. @echo ""
  170. $(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(BIN).elf
  171. build_static: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).a
  172. @echo ""
  173. $(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(BIN).a
  174. $(BUILD_DIR):
  175. $(CMD_ECHO) mkdir -p $(BUILD_DIR)
  176. $(BUILD_DIR)/$(BIN).hex: $(BUILD_DIR)/$(BIN).elf
  177. @echo "Generating HEX binary: $(notdir $@)"
  178. $(CMD_ECHO) $(OBJCOPY) -O ihex $< $@
  179. $(BUILD_DIR)/%.o: %.s
  180. @echo "Compiling ASM file: $(notdir $<)"
  181. $(CMD_ECHO) $(AS) $(ASFLAGS) $(DEF) $(INC) -c -o $@ $<
  182. $(BUILD_DIR)/%.o: %.c
  183. @echo "Compiling C file: $(notdir $<)"
  184. $(CMD_ECHO) $(CC) $(CFLAGS) $(DEF) $(INC) -c -o $@ $<
  185. $(BUILD_DIR)/$(BIN).elf: $(OBJS_ASM) $(OBJS_C)
  186. @echo "Linking ELF binary: $(notdir $@)"
  187. $(CMD_ECHO) $(LD) $(LDFLAGS) $(SRC_LD) -o $@ $^ $(LIBS)
  188. @echo "Generating name list: $(BIN).sym"
  189. $(CMD_ECHO) $(NM) -n $@ > $(BUILD_DIR)/$(BIN).sym
  190. @echo "Showing final size:"
  191. $(CMD_ECHO) ls -la $@
  192. @echo "Generating disassembly: $(BIN).disasm"
  193. $(CMD_ECHO) $(OBJDUMP) -S $@ > $(BUILD_DIR)/$(BIN).disasm
  194. $(BUILD_DIR)/$(BIN).a: $(OBJS_ASM) $(OBJS_C)
  195. @echo "Building static library: $(notdir $@)"
  196. $(CMD_ECHO) $(AR) -r $@ $^
  197. @echo "Generating name list: $(BIN).sym"
  198. $(CMD_ECHO) $(NM) -n $@ > $(BUILD_DIR)/$(BIN).sym
  199. @echo "Showing final size:"
  200. $(CMD_ECHO) ls -la $@
  201. @echo "Generating disassembly: $(BIN).disasm"
  202. $(CMD_ECHO) $(OBJDUMP) -S $@ > $(BUILD_DIR)/$(BIN).disasm
  203. clean:
  204. rm -f $(BUILD_DIR)/*.elf $(BUILD_DIR)/*.hex $(BUILD_DIR)/*.map
  205. rm -f $(BUILD_DIR)/*.o $(BUILD_DIR)/*.a $(BUILD_DIR)/*.sym $(BUILD_DIR)/*.disasm