Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # libwolfssl Linux kernel module Makefile (wraps Kbuild-native makefile)
  2. #
  3. # Copyright (C) 2006-2021 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. #/
  21. SHELL=/bin/bash
  22. all: libwolfssl.ko libwolfssl.ko.signed
  23. .PHONY: libwolfssl.ko
  24. ifndef MODULE_TOP
  25. MODULE_TOP=$(CURDIR)
  26. endif
  27. ifndef SRC_TOP
  28. SRC_TOP=$(shell dirname $(MODULE_TOP))
  29. endif
  30. 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)\""
  31. ifdef KERNEL_EXTRA_CFLAGS
  32. WOLFSSL_CFLAGS += $(KERNEL_EXTRA_CFLAGS)
  33. endif
  34. WOLFSSL_ASFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CCASFLAGS) $(CCASFLAGS)
  35. 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)))))
  36. ifeq "$(ENABLED_CRYPT_TESTS)" "yes"
  37. WOLFSSL_OBJ_FILES+=wolfcrypt/test/test.o
  38. else
  39. WOLFSSL_CFLAGS+=-DNO_CRYPT_TEST
  40. endif
  41. ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
  42. WOLFCRYPT_PIE_FILES := linuxkm/pie_first.o $(filter wolfcrypt/src/%,$(WOLFSSL_OBJ_FILES)) linuxkm/pie_redirect_table.o linuxkm/pie_last.o
  43. WOLFSSL_OBJ_FILES := $(WOLFCRYPT_PIE_FILES) $(filter-out $(WOLFCRYPT_PIE_FILES),$(WOLFSSL_OBJ_FILES))
  44. endif
  45. export WOLFSSL_CFLAGS WOLFSSL_ASFLAGS WOLFSSL_OBJ_FILES WOLFCRYPT_PIE_FILES
  46. libwolfssl.ko:
  47. @if test -z "$(KERNEL_ROOT)"; then echo '$$KERNEL_ROOT is unset' >&2; exit 1; fi
  48. @if test -z "$(AM_CFLAGS)$(CFLAGS)"; then echo '$$AM_CFLAGS and $$CFLAGS are both unset.' >&2; exit 1; fi
  49. @if test -z "$(src_libwolfssl_la_OBJECTS)"; then echo '$$src_libwolfssl_la_OBJECTS is unset.' >&2; exit 1; fi
  50. @mkdir -p linuxkm src wolfcrypt/src wolfcrypt/test
  51. @if test ! -h $(SRC_TOP)/Kbuild; then ln -s $(MODULE_TOP)/Kbuild $(SRC_TOP)/Kbuild; fi
  52. ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
  53. +$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(SRC_TOP) CC_FLAGS_FTRACE=
  54. else
  55. +$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(SRC_TOP)
  56. endif
  57. libwolfssl.ko.signed: libwolfssl.ko
  58. @cd '$(KERNEL_ROOT)' || exit $$?; \
  59. while read configline; do \
  60. case "$$configline" in \
  61. CONFIG_MODULE_SIG*=*) \
  62. declare "$${configline%=*}"="$${configline#*=}" \
  63. ;; \
  64. esac; \
  65. done < .config || exit $$?; \
  66. if [[ "$${CONFIG_MODULE_SIG}" = "y" && -n "$${CONFIG_MODULE_SIG_KEY}" && \
  67. -n "$${CONFIG_MODULE_SIG_HASH}" && ( ! -f '$(MODULE_TOP)/$@' || \
  68. '$(MODULE_TOP)/$<' -nt '$(MODULE_TOP)/$@' ) ]]; then \
  69. CONFIG_MODULE_SIG_KEY="$${CONFIG_MODULE_SIG_KEY#\"}"; \
  70. CONFIG_MODULE_SIG_KEY="$${CONFIG_MODULE_SIG_KEY%\"}"; \
  71. CONFIG_MODULE_SIG_HASH="$${CONFIG_MODULE_SIG_HASH#\"}"; \
  72. CONFIG_MODULE_SIG_HASH="$${CONFIG_MODULE_SIG_HASH%\"}"; \
  73. cp -p '$(MODULE_TOP)/$<' '$(MODULE_TOP)/$@' || exit $$?; \
  74. ./scripts/sign-file "$${CONFIG_MODULE_SIG_HASH}" \
  75. "$${CONFIG_MODULE_SIG_KEY}" \
  76. "$${CONFIG_MODULE_SIG_KEY/%.pem/.x509}" \
  77. '$(MODULE_TOP)/$@'; \
  78. sign_file_exitval=$$?; \
  79. if [[ $$sign_file_exitval != 0 ]]; then \
  80. $(RM) -f '$(MODULE_TOP)/$@'; \
  81. exit $$sign_file_exitval; \
  82. fi; \
  83. if [[ "$(quiet)" != "silent_" ]]; then \
  84. echo " Module $@ signed by $${CONFIG_MODULE_SIG_KEY}."; \
  85. fi \
  86. fi
  87. .PHONY: install modules_install
  88. install modules_install:
  89. +$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(SRC_TOP) INSTALL_MOD_DIR=wolfssl modules_install
  90. .PHONY: clean
  91. # note, must supply $(MODULE_TOP) as the src value for clean so that Kbuild is included, else
  92. # the top Makefile (which is not for the kernel build) would be included here.
  93. clean:
  94. +$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(MODULE_TOP) clean
  95. .PHONY: check
  96. check:
  97. .PHONY: distclean
  98. distclean: clean
  99. .PHONY: dist
  100. dist:
  101. .PHONY: distdir
  102. distdir: