Gilles Peskine | f3d1ae1 | 2023-12-22 11:40:58 +0100 | [diff] [blame] | 1 | # To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS |
| 2 | |
| 3 | CFLAGS ?= -O2 |
| 4 | WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral |
| 5 | WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral |
| 6 | LDFLAGS ?= |
| 7 | |
| 8 | LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../tests/include -I../include -D_FILE_OFFSET_BITS=64 |
| 9 | LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I../include -I../tests/include -D_FILE_OFFSET_BITS=64 |
| 10 | LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \ |
| 11 | -L../library \ |
| 12 | -lmbedtls$(SHARED_SUFFIX) \ |
| 13 | -lmbedx509$(SHARED_SUFFIX) \ |
| 14 | -lmbedcrypto$(SHARED_SUFFIX) |
Gilles Peskine | 076fd25 | 2023-12-22 11:45:53 +0100 | [diff] [blame] | 15 | |
| 16 | include ../3rdparty/Makefile.inc |
| 17 | LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES) |
| 18 | |
| 19 | ifndef SHARED |
| 20 | MBEDLIBS=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a |
| 21 | else |
| 22 | MBEDLIBS=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT) |
| 23 | endif |
| 24 | |
| 25 | ifdef DEBUG |
| 26 | LOCAL_CFLAGS += -g3 |
| 27 | endif |
| 28 | |
| 29 | # if we're running on Windows, build for Windows |
| 30 | ifdef WINDOWS |
| 31 | WINDOWS_BUILD=1 |
| 32 | endif |
| 33 | |
Gilles Peskine | f3316f1 | 2023-12-22 18:30:37 +0100 | [diff] [blame] | 34 | ## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT) |
| 35 | ## Remove the preprocessor symbols that are set in the current configuration |
Gilles Peskine | 21570cf | 2023-12-22 11:49:50 +0100 | [diff] [blame] | 36 | ## from PREPROCESSOR_INPUT. Also normalize whitespace. |
| 37 | ## Example: |
Gilles Peskine | f3316f1 | 2023-12-22 18:30:37 +0100 | [diff] [blame] | 38 | ## $(call remove_set_options,MBEDTLS_FOO MBEDTLS_BAR) |
Gilles Peskine | 21570cf | 2023-12-22 11:49:50 +0100 | [diff] [blame] | 39 | ## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both |
Gilles Peskine | f3316f1 | 2023-12-22 18:30:37 +0100 | [diff] [blame] | 40 | ## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is |
Gilles Peskine | 21570cf | 2023-12-22 11:49:50 +0100 | [diff] [blame] | 41 | ## disabled, etc. |
| 42 | ## |
| 43 | ## This only works with a Unix-like shell environment (Bourne/POSIX-style shell |
| 44 | ## and standard commands) and a Unix-like compiler (supporting -E). In |
| 45 | ## other environments, the output is likely to be empty. |
Gilles Peskine | f3316f1 | 2023-12-22 18:30:37 +0100 | [diff] [blame] | 46 | define remove_enabled_options |
Gilles Peskine | 21570cf | 2023-12-22 11:49:50 +0100 | [diff] [blame] | 47 | $(strip $(shell |
| 48 | exec 2>/dev/null; |
| 49 | { echo '#include <mbedtls/build_info.h>'; echo $(1); } | |
| 50 | $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - | |
| 51 | tail -n 1 |
| 52 | )) |
| 53 | endef |
| 54 | |
Gilles Peskine | 076fd25 | 2023-12-22 11:45:53 +0100 | [diff] [blame] | 55 | ifdef WINDOWS_BUILD |
| 56 | DLEXT=dll |
| 57 | EXEXT=.exe |
| 58 | LOCAL_LDFLAGS += -lws2_32 -lbcrypt |
| 59 | ifdef SHARED |
| 60 | SHARED_SUFFIX=.$(DLEXT) |
| 61 | endif |
| 62 | |
| 63 | else # Not building for Windows |
| 64 | DLEXT ?= so |
| 65 | EXEXT= |
| 66 | SHARED_SUFFIX= |
Gilles Peskine | 21570cf | 2023-12-22 11:49:50 +0100 | [diff] [blame] | 67 | ifndef THREADING |
| 68 | # Auto-detect configurations with pthread. |
Gilles Peskine | f3316f1 | 2023-12-22 18:30:37 +0100 | [diff] [blame] | 69 | # If the call to remove_enabled_options returns "control", the symbols |
Gilles Peskine | 2337a3b | 2023-12-22 13:25:18 +0100 | [diff] [blame] | 70 | # are confirmed set and we link with pthread. |
| 71 | # If the auto-detection fails, the result of the call is empty and |
| 72 | # we keep THREADING undefined. |
Gilles Peskine | f3316f1 | 2023-12-22 18:30:37 +0100 | [diff] [blame] | 73 | ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD)) |
Gilles Peskine | 21570cf | 2023-12-22 11:49:50 +0100 | [diff] [blame] | 74 | THREADING := pthread |
| 75 | endif |
| 76 | endif |
Gilles Peskine | 076fd25 | 2023-12-22 11:45:53 +0100 | [diff] [blame] | 77 | |
| 78 | ifeq ($(THREADING),pthread) |
| 79 | LOCAL_LDFLAGS += -lpthread |
| 80 | endif |
| 81 | endif |
| 82 | |
| 83 | ifdef WINDOWS |
| 84 | PYTHON ?= python |
| 85 | else |
| 86 | PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi) |
| 87 | endif |
| 88 | |
| 89 | # See root Makefile |
| 90 | GEN_FILES ?= yes |
| 91 | ifdef GEN_FILES |
| 92 | gen_file_dep = |
| 93 | else |
| 94 | gen_file_dep = | |
| 95 | endif |
Gilles Peskine | 4392fc1 | 2023-12-22 11:49:35 +0100 | [diff] [blame] | 96 | |
| 97 | default: all |
| 98 | |
| 99 | $(MBEDLIBS): |
| 100 | $(MAKE) -C ../library |
| 101 | |
| 102 | neat: clean |
| 103 | ifndef WINDOWS |
| 104 | rm -f $(GENERATED_FILES) |
| 105 | else |
| 106 | for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f |
| 107 | endif |