Makefile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # libwolfssl Linux kernel module Makefile (wraps Kbuild-native makefile)
  2. #
  3. # Copyright (C) 2006-2024 wolfSSL Inc.
  4. #
  5. # This file is part of wolfSSL.
  6. #
  7. # wolfSSL 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 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # wolfSSL 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, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. SHELL=bash
  21. all: libwolfssl.ko libwolfssl.ko.signed
  22. .PHONY: libwolfssl.ko
  23. ifndef MODULE_TOP
  24. MODULE_TOP=$(CURDIR)
  25. endif
  26. ifndef SRC_TOP
  27. SRC_TOP=$(shell dirname $(MODULE_TOP))
  28. endif
  29. WOLFSSL_CFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -Wno-declaration-after-statement -Wno-redundant-decls -DLIBWOLFSSL_GLOBAL_EXTRA_CFLAGS="\" $(KERNEL_EXTRA_CFLAGS)\""
  30. ifdef KERNEL_EXTRA_CFLAGS
  31. WOLFSSL_CFLAGS += $(KERNEL_EXTRA_CFLAGS)
  32. endif
  33. WOLFSSL_ASFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CCASFLAGS) $(CCASFLAGS)
  34. WOLFSSL_OBJ_FILES=$(patsubst %.lo, %.o, $(patsubst src/src_libwolfssl_la-%, src/%, $(patsubst src/libwolfssl_la-%, src/%, $(patsubst wolfcrypt/src/src_libwolfssl_la-%, wolfcrypt/src/%, $(src_libwolfssl_la_OBJECTS)))))
  35. ifeq "$(ENABLED_CRYPT_TESTS)" "yes"
  36. WOLFSSL_OBJ_FILES+=wolfcrypt/test/test.o
  37. else
  38. WOLFSSL_CFLAGS+=-DNO_CRYPT_TEST
  39. endif
  40. ifeq "$(ENABLED_LINUXKM_BENCHMARKS)" "yes"
  41. WOLFSSL_OBJ_FILES+=wolfcrypt/benchmark/benchmark.o
  42. endif
  43. ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
  44. WOLFCRYPT_PIE_FILES := linuxkm/pie_first.o $(filter wolfcrypt/src/%,$(WOLFSSL_OBJ_FILES)) linuxkm/pie_redirect_table.o linuxkm/pie_last.o
  45. WOLFSSL_OBJ_FILES := $(WOLFCRYPT_PIE_FILES) $(filter-out $(WOLFCRYPT_PIE_FILES),$(WOLFSSL_OBJ_FILES))
  46. endif
  47. export WOLFSSL_CFLAGS WOLFSSL_ASFLAGS WOLFSSL_OBJ_FILES WOLFCRYPT_PIE_FILES
  48. ifneq "$(host_triplet)" "$(build_triplet)"
  49. CROSS_COMPILE := 'CROSS_COMPILE=$(host_triplet)-'
  50. endif
  51. OVERRIDE_PATHS :=
  52. ifdef CC
  53. ifneq "$(CC)" "cc"
  54. OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'CC=$(CC)'
  55. endif
  56. endif
  57. ifdef AS
  58. ifneq "$(AS)" "as"
  59. OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'AS=$(AS)'
  60. endif
  61. endif
  62. ifdef LD
  63. ifneq "$(LD)" "ld"
  64. OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'LD=$(LD)'
  65. endif
  66. endif
  67. libwolfssl.ko:
  68. @if test -z '$(KERNEL_ROOT)'; then echo '$$KERNEL_ROOT is unset' >&2; exit 1; fi
  69. @if test -z '$(AM_CFLAGS)$(CFLAGS)'; then echo '$$AM_CFLAGS and $$CFLAGS are both unset.' >&2; exit 1; fi
  70. @if test -z '$(src_libwolfssl_la_OBJECTS)'; then echo '$$src_libwolfssl_la_OBJECTS is unset.' >&2; exit 1; fi
  71. # after commit 9a0ebe5011 (6.10), sources must be in $(obj). work around this by making links to all needed sources:
  72. @mkdir -p '$(MODULE_TOP)/linuxkm'
  73. @test '$(MODULE_TOP)/module_hooks.c' -ef '$(MODULE_TOP)/linuxkm/module_hooks.c' || cp --no-dereference --symbolic-link --no-clobber '$(MODULE_TOP)'/*.[ch] '$(MODULE_TOP)/linuxkm/'
  74. @test '$(SRC_TOP)/wolfcrypt/src/wc_port.c' -ef '$(MODULE_TOP)/wolfcrypt/src/wc_port.c' || cp --no-dereference --symbolic-link --no-clobber --recursive '$(SRC_TOP)/wolfcrypt' '$(MODULE_TOP)/'
  75. @test '$(SRC_TOP)/src/wolfio.c' -ef '$(MODULE_TOP)/src/wolfio.c' || cp --no-dereference --symbolic-link --no-clobber --recursive '$(SRC_TOP)/src' '$(MODULE_TOP)/'
  76. ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
  77. +$(MAKE) ARCH='$(KERNEL_ARCH)' $(OVERRIDE_PATHS) $(CROSS_COMPILE) -C '$(KERNEL_ROOT)' M='$(MODULE_TOP)' $(KBUILD_EXTRA_FLAGS) CC_FLAGS_FTRACE=
  78. else
  79. +$(MAKE) ARCH='$(KERNEL_ARCH)' $(OVERRIDE_PATHS) $(CROSS_COMPILE) -C '$(KERNEL_ROOT)' M='$(MODULE_TOP)' $(KBUILD_EXTRA_FLAGS)
  80. endif
  81. libwolfssl.ko.signed: libwolfssl.ko
  82. @cd '$(KERNEL_ROOT)' || exit $$?; \
  83. while read configline; do \
  84. case "$$configline" in \
  85. CONFIG_MODULE_SIG*=*) \
  86. declare "$${configline%=*}"="$${configline#*=}" \
  87. ;; \
  88. esac; \
  89. done < .config || exit $$?; \
  90. if [[ "$${CONFIG_MODULE_SIG}" = "y" && -n "$${CONFIG_MODULE_SIG_KEY}" && \
  91. -n "$${CONFIG_MODULE_SIG_HASH}" && ( ! -f '$(MODULE_TOP)/$@' || \
  92. '$(MODULE_TOP)/$<' -nt '$(MODULE_TOP)/$@' ) ]]; then \
  93. CONFIG_MODULE_SIG_KEY="$${CONFIG_MODULE_SIG_KEY#\"}"; \
  94. CONFIG_MODULE_SIG_KEY="$${CONFIG_MODULE_SIG_KEY%\"}"; \
  95. CONFIG_MODULE_SIG_HASH="$${CONFIG_MODULE_SIG_HASH#\"}"; \
  96. CONFIG_MODULE_SIG_HASH="$${CONFIG_MODULE_SIG_HASH%\"}"; \
  97. cp -p '$(MODULE_TOP)/$<' '$(MODULE_TOP)/$@' || exit $$?; \
  98. ./scripts/sign-file "$${CONFIG_MODULE_SIG_HASH}" \
  99. "$${CONFIG_MODULE_SIG_KEY}" \
  100. "$${CONFIG_MODULE_SIG_KEY/%.pem/.x509}" \
  101. '$(MODULE_TOP)/$@'; \
  102. sign_file_exitval=$$?; \
  103. if [[ $$sign_file_exitval != 0 ]]; then \
  104. $(RM) -f '$(MODULE_TOP)/$@'; \
  105. exit $$sign_file_exitval; \
  106. fi; \
  107. if [[ "$(quiet)" != "silent_" ]]; then \
  108. echo " Module $@ signed by $${CONFIG_MODULE_SIG_KEY}."; \
  109. fi \
  110. fi
  111. .PHONY: install modules_install
  112. install modules_install:
  113. +$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(SRC_TOP) INSTALL_MOD_DIR=wolfssl modules_install
  114. .PHONY: clean
  115. # note, must supply $(MODULE_TOP) as the src value for clean so that Kbuild is included, else
  116. # the top Makefile (which is not for the kernel build) would be included here.
  117. clean:
  118. $(RM) -rf '$(MODULE_TOP)/linuxkm'
  119. $(RM) -rf '$(MODULE_TOP)/wolfcrypt'
  120. $(RM) -rf '$(MODULE_TOP)/src'
  121. +$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(MODULE_TOP) clean
  122. .PHONY: check
  123. check:
  124. .PHONY: distclean
  125. distclean: clean
  126. .PHONY: dist
  127. dist:
  128. .PHONY: distdir
  129. distdir: