Makefile.dlldeps 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # SPDX-License-Identifier: BSD-2-Clause
  2. #
  3. # Automatically find DLL dependencies, transitively.
  4. #
  5. # Copyright © 2021 David Woodhouse <dwmw2@infradead.org>
  6. #
  7. # Each .d file is auto-generated on demand when make tries to include
  8. # it. It is generated by a pattern rule from the corresponding DLL
  9. # binary, either in the local .libs directory or in the MinGw sys-root
  10. # which ought to be $(bindir).
  11. #
  12. # The Makefile snippet in each generated file adds the full DLL pathname
  13. # to $(DLLS), adds the .d file and the DLL itself to the dependencies of
  14. # file-list.txt, and then includes more .d files for each other DLL that
  15. # this DLL links to.
  16. #
  17. # Because we use -include, we just skip any DLLs we can't find, which
  18. # will mostly be Windows system runtime stuff like kernel32.dll.
  19. #
  20. # The result, after manually -including the top-level .openconnect.exe.d,
  21. # is that we have a full transitive list of required non-system DLLs
  22. # in the $(DLLS) variable. Which will contain duplicates, hence the
  23. # use of $(sort) when writing it out to file-list.txt.
  24. # Defaults for manual invocation.
  25. DLL_EXECUTABLES ?= openconnect.exe wintun.dll $(EXTRA_EXECUTABLES)
  26. MINGW ?= x86_64-w64-mingw32
  27. OBJDUMP ?= $(MINGW)-objdump
  28. bindir ?= /usr/$(MINGW)/sys-root/mingw/bin
  29. V ?= 0
  30. AM_V_LISTDLLS = $(am__v_LISTDLLS_$(V))
  31. am__v_LISTDLLS_ = $(am__v_LISTDLLS_$(AM_DEFAULT_VERBOSITY))
  32. am__v_LISTDLLS_0 = @echo " LISTDLLS" $<;
  33. am__v_LISTDLLS_1 =
  34. LISTDLLS_CMD = $(AM_V_LISTDLLS) \
  35. ( echo "DLLS += $<" ; echo "file-list.txt: $@ $<" ; \
  36. $(OBJDUMP) -p "$<" | sed -n '/DLL Name:/{s%^.*DLL Name: \(Qt.*\)\?\(.*\)\?%-include .\1\L\2.d%;p}' ) > $@
  37. VPATH = $(bindir) $(EXTRA_DLLDIRS)
  38. .%.d: .libs/%
  39. $(LISTDLLS_CMD)
  40. .%.d: %
  41. $(LISTDLLS_CMD)
  42. include $(patsubst %,.%.d,$(DLL_EXECUTABLES))
  43. AM_V_GEN = $(am__v_GEN_$(V))
  44. am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
  45. am__v_GEN_0 = @echo " GEN " $@;
  46. am__v_GEN_1 =
  47. file-list.txt:
  48. $(AM_V_GEN) for dll in $(sort $(DLLS)); do echo "$${dll}"; done > $@