Tom Rini | 3f7c22a | 2024-10-08 13:56:50 -0600 | [diff] [blame] | 1 | DESTDIR=/usr/local |
| 2 | PREFIX=mbedtls_ |
| 3 | PERL ?= perl |
| 4 | |
| 5 | ifneq (,$(filter-out lib library/%,$(or $(MAKECMDGOALS),all))) |
| 6 | ifeq (,$(wildcard framework/exported.make)) |
| 7 | # Use the define keyword to get a multi-line message. |
| 8 | # GNU make appends ". Stop.", so tweak the ending of our message accordingly. |
| 9 | define error_message |
| 10 | $(MBEDTLS_PATH)/framework/exported.make not found. |
| 11 | Run `git submodule update --init` to fetch the submodule contents. |
| 12 | This is a fatal error |
| 13 | endef |
| 14 | $(error $(error_message)) |
| 15 | endif |
| 16 | include framework/exported.make |
| 17 | endif |
| 18 | |
| 19 | .SILENT: |
| 20 | |
| 21 | .PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean |
| 22 | |
| 23 | all: programs tests |
| 24 | $(MAKE) post_build |
| 25 | |
| 26 | no_test: programs |
| 27 | |
| 28 | programs: lib mbedtls_test |
| 29 | $(MAKE) -C programs |
| 30 | |
| 31 | lib: |
| 32 | $(MAKE) -C library |
| 33 | |
| 34 | tests: lib mbedtls_test |
| 35 | $(MAKE) -C tests |
| 36 | |
| 37 | mbedtls_test: |
| 38 | $(MAKE) -C tests mbedtls_test |
| 39 | |
| 40 | library/%: |
| 41 | $(MAKE) -C library $* |
| 42 | programs/%: |
| 43 | $(MAKE) -C programs $* |
| 44 | tests/%: |
| 45 | $(MAKE) -C tests $* |
| 46 | |
| 47 | .PHONY: generated_files |
| 48 | generated_files: library/generated_files |
| 49 | generated_files: programs/generated_files |
| 50 | generated_files: tests/generated_files |
| 51 | generated_files: visualc_files |
| 52 | |
| 53 | # Set GEN_FILES to the empty string to disable dependencies on generated |
| 54 | # source files. Then `make generated_files` will only build files that |
| 55 | # are missing, it will not rebuilt files that are present but out of date. |
| 56 | # This is useful, for example, if you have a source tree where |
| 57 | # `make generated_files` has already run and file timestamps reflect the |
| 58 | # time the files were copied or extracted, and you are now in an environment |
| 59 | # that lacks some of the necessary tools to re-generate the files. |
| 60 | # If $(GEN_FILES) is non-empty, the generated source files' dependencies |
| 61 | # are treated ordinarily, based on file timestamps. |
| 62 | GEN_FILES ?= |
| 63 | |
| 64 | # In dependencies where the target is a configuration-independent generated |
| 65 | # file, use `TARGET: $(gen_file_dep) DEPENDENCY1 DEPENDENCY2 ...` |
| 66 | # rather than directly `TARGET: DEPENDENCY1 DEPENDENCY2 ...`. This |
| 67 | # enables the re-generation to be turned off when GEN_FILES is disabled. |
| 68 | ifdef GEN_FILES |
| 69 | gen_file_dep = |
| 70 | else |
| 71 | # Order-only dependency: generate the target if it's absent, but don't |
| 72 | # re-generate it if it's present but older than its dependencies. |
| 73 | gen_file_dep = | |
| 74 | endif |
| 75 | |
| 76 | .PHONY: visualc_files |
| 77 | VISUALC_FILES = visualc/VS2017/mbedTLS.sln visualc/VS2017/mbedTLS.vcxproj |
| 78 | # TODO: $(app).vcxproj for each $(app) in programs/ |
| 79 | visualc_files: $(VISUALC_FILES) |
| 80 | |
| 81 | # Ensure that the .c files that generate_visualc_files.pl enumerates are |
| 82 | # present before it runs. It doesn't matter if the files aren't up-to-date, |
| 83 | # they just need to be present. |
| 84 | $(VISUALC_FILES): | library/generated_files |
| 85 | $(VISUALC_FILES): $(gen_file_dep) scripts/generate_visualc_files.pl |
| 86 | $(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-app-template.vcxproj |
| 87 | $(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-main-template.vcxproj |
| 88 | $(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-sln-template.sln |
| 89 | # TODO: also the list of .c and .h source files, but not their content |
| 90 | $(VISUALC_FILES): |
| 91 | echo " Gen $@ ..." |
| 92 | $(PERL) scripts/generate_visualc_files.pl |
| 93 | |
| 94 | ifndef WINDOWS |
| 95 | install: no_test |
| 96 | mkdir -p $(DESTDIR)/include/mbedtls |
| 97 | cp -rp include/mbedtls $(DESTDIR)/include |
| 98 | mkdir -p $(DESTDIR)/include/psa |
| 99 | cp -rp include/psa $(DESTDIR)/include |
| 100 | |
| 101 | mkdir -p $(DESTDIR)/lib |
| 102 | cp -RP library/libmbedtls.* $(DESTDIR)/lib |
| 103 | cp -RP library/libmbedx509.* $(DESTDIR)/lib |
| 104 | cp -RP library/libmbedcrypto.* $(DESTDIR)/lib |
| 105 | |
| 106 | mkdir -p $(DESTDIR)/bin |
| 107 | for p in programs/*/* ; do \ |
| 108 | if [ -x $$p ] && [ ! -d $$p ] ; \ |
| 109 | then \ |
| 110 | f=$(PREFIX)`basename $$p` ; \ |
| 111 | cp $$p $(DESTDIR)/bin/$$f ; \ |
| 112 | fi \ |
| 113 | done |
| 114 | |
| 115 | uninstall: |
| 116 | rm -rf $(DESTDIR)/include/mbedtls |
| 117 | rm -rf $(DESTDIR)/include/psa |
| 118 | rm -f $(DESTDIR)/lib/libmbedtls.* |
| 119 | rm -f $(DESTDIR)/lib/libmbedx509.* |
| 120 | rm -f $(DESTDIR)/lib/libmbedcrypto.* |
| 121 | |
| 122 | for p in programs/*/* ; do \ |
| 123 | if [ -x $$p ] && [ ! -d $$p ] ; \ |
| 124 | then \ |
| 125 | f=$(PREFIX)`basename $$p` ; \ |
| 126 | rm -f $(DESTDIR)/bin/$$f ; \ |
| 127 | fi \ |
| 128 | done |
| 129 | endif |
| 130 | |
| 131 | |
| 132 | WARNING_BORDER_LONG =**********************************************************************************\n |
| 133 | CTR_DRBG_128_BIT_KEY_WARN_L1=**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined! ****\n |
| 134 | CTR_DRBG_128_BIT_KEY_WARN_L2=**** Using 128-bit keys for CTR_DRBG limits the security of generated ****\n |
| 135 | CTR_DRBG_128_BIT_KEY_WARN_L3=**** keys and operations that use random values generated to 128-bit security ****\n |
| 136 | |
| 137 | CTR_DRBG_128_BIT_KEY_WARNING=\n$(WARNING_BORDER_LONG)$(CTR_DRBG_128_BIT_KEY_WARN_L1)$(CTR_DRBG_128_BIT_KEY_WARN_L2)$(CTR_DRBG_128_BIT_KEY_WARN_L3)$(WARNING_BORDER_LONG) |
| 138 | |
| 139 | # Post build steps |
| 140 | post_build: |
| 141 | ifndef WINDOWS |
| 142 | |
| 143 | # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning |
| 144 | -scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \ |
| 145 | echo '$(CTR_DRBG_128_BIT_KEY_WARNING)' |
| 146 | |
| 147 | endif |
| 148 | |
| 149 | clean: clean_more_on_top |
| 150 | $(MAKE) -C library clean |
| 151 | $(MAKE) -C programs clean |
| 152 | $(MAKE) -C tests clean |
| 153 | |
| 154 | clean_more_on_top: |
| 155 | ifndef WINDOWS |
| 156 | find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} + |
| 157 | endif |
| 158 | |
| 159 | neat: clean_more_on_top |
| 160 | $(MAKE) -C library neat |
| 161 | $(MAKE) -C programs neat |
| 162 | $(MAKE) -C tests neat |
| 163 | ifndef WINDOWS |
| 164 | rm -f visualc/VS2017/*.vcxproj visualc/VS2017/mbedTLS.sln |
| 165 | else |
| 166 | if exist visualc\VS2017\*.vcxproj del /Q /F visualc\VS2017\*.vcxproj |
| 167 | if exist visualc\VS2017\mbedTLS.sln del /Q /F visualc\VS2017\mbedTLS.sln |
| 168 | endif |
| 169 | |
| 170 | check: lib tests |
| 171 | $(MAKE) -C tests check |
| 172 | |
| 173 | test: check |
| 174 | |
| 175 | ifndef WINDOWS |
| 176 | # For coverage testing: |
| 177 | # 1. Build with: |
| 178 | # make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage' |
| 179 | # 2. Run the relevant tests for the part of the code you're interested in. |
| 180 | # For the reference coverage measurement, see |
| 181 | # tests/scripts/basic-build-test.sh |
| 182 | # 3. Run scripts/lcov.sh to generate an HTML report. |
| 183 | lcov: |
| 184 | scripts/lcov.sh |
| 185 | |
| 186 | apidoc: |
| 187 | mkdir -p apidoc |
| 188 | cd doxygen && doxygen mbedtls.doxyfile |
| 189 | |
| 190 | apidoc_clean: |
| 191 | rm -rf apidoc |
| 192 | endif |
| 193 | |
| 194 | ## Editor navigation files |
| 195 | C_SOURCE_FILES = $(wildcard \ |
| 196 | 3rdparty/*/include/*/*.h 3rdparty/*/include/*/*/*.h 3rdparty/*/include/*/*/*/*.h \ |
| 197 | 3rdparty/*/*.c 3rdparty/*/*/*.c 3rdparty/*/*/*/*.c 3rdparty/*/*/*/*/*.c \ |
| 198 | include/*/*.h \ |
| 199 | library/*.[hc] \ |
| 200 | programs/*/*.[hc] \ |
| 201 | tests/include/*/*.h tests/include/*/*/*.h \ |
| 202 | tests/src/*.c tests/src/*/*.c \ |
| 203 | tests/suites/*.function \ |
| 204 | ) |
| 205 | # Exuberant-ctags invocation. Other ctags implementations may require different options. |
| 206 | CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o |
| 207 | tags: $(C_SOURCE_FILES) |
| 208 | $(CTAGS) $@ $(C_SOURCE_FILES) |
| 209 | TAGS: $(C_SOURCE_FILES) |
| 210 | etags --no-line-directive -o $@ $(C_SOURCE_FILES) |
| 211 | global: GPATH GRTAGS GSYMS GTAGS |
| 212 | GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES) |
| 213 | ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc |
| 214 | cscope: cscope.in.out cscope.po.out cscope.out |
| 215 | cscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES) |
| 216 | cscope -bq -u -Iinclude -Ilibrary $(patsubst %,-I%,$(wildcard 3rdparty/*/include)) -Itests/include $(C_SOURCE_FILES) |
| 217 | .PHONY: cscope global |