shared-info.pl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #! /usr/bin/env perl
  2. # -*- mode: perl; -*-
  3. # Copyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License 2.0 (the "License"). You may not use
  6. # this file except in compliance with the License. You can obtain a copy
  7. # in the file LICENSE in the source distribution or at
  8. # https://www.openssl.org/source/license.html
  9. # This is a collection of extra attributes to be used as input for creating
  10. # shared libraries, currently on any Unix variant, including Unix like
  11. # environments on Windows.
  12. sub detect_gnu_ld {
  13. my @lines =
  14. `$config{CROSS_COMPILE}$config{CC} -Wl,-V /dev/null 2>&1`;
  15. return grep /^GNU ld/, @lines;
  16. }
  17. sub detect_gnu_cc {
  18. my @lines =
  19. `$config{CROSS_COMPILE}$config{CC} -v 2>&1`;
  20. return grep /gcc/, @lines;
  21. }
  22. my %shared_info;
  23. %shared_info = (
  24. 'gnu-shared' => {
  25. shared_ldflag => '-shared -Wl,-Bsymbolic',
  26. shared_sonameflag => '-Wl,-soname=',
  27. },
  28. 'linux-shared' => sub {
  29. return {
  30. %{$shared_info{'gnu-shared'}},
  31. shared_defflag => '-Wl,--version-script=',
  32. dso_ldflags =>
  33. (grep /(?:^|\s)-fsanitize/,
  34. @{$config{CFLAGS}}, @{$config{cflags}})
  35. ? ''
  36. : '-Wl,-z,defs',
  37. };
  38. },
  39. 'bsd-gcc-shared' => sub { return $shared_info{'linux-shared'}; },
  40. 'bsd-gcc-nodef-shared' => sub {
  41. return {
  42. %{$shared_info{'gnu-shared'}},
  43. shared_defflags => '-Wl,--version-script=',
  44. };
  45. },
  46. 'darwin-shared' => {
  47. module_ldflags => '-bundle',
  48. shared_ldflag => '-dynamiclib -current_version $(SHLIB_VERSION_NUMBER) -compatibility_version $(SHLIB_VERSION_NUMBER)',
  49. shared_sonameflag => '-install_name $(libdir)/',
  50. },
  51. 'cygwin-shared' => {
  52. shared_ldflag => '-shared -Wl,--enable-auto-image-base',
  53. shared_impflag => '-Wl,--out-implib=',
  54. },
  55. 'mingw-shared' => sub {
  56. return {
  57. %{$shared_info{'cygwin-shared'}},
  58. # def_flag made to empty string so it still generates
  59. # something
  60. shared_defflag => '',
  61. shared_argfileflag => '@',
  62. };
  63. },
  64. 'alpha-osf1-shared' => sub {
  65. return $shared_info{'gnu-shared'} if detect_gnu_ld();
  66. return {
  67. module_ldflags => '-shared -Wl,-Bsymbolic',
  68. shared_ldflag => '-shared -Wl,-Bsymbolic -set_version $(SHLIB_VERSION_NUMBER)',
  69. };
  70. },
  71. 'svr3-shared' => sub {
  72. return $shared_info{'gnu-shared'} if detect_gnu_ld();
  73. return {
  74. shared_ldflag => '-G',
  75. shared_sonameflag => '-h ',
  76. };
  77. },
  78. 'svr5-shared' => sub {
  79. return $shared_info{'gnu-shared'} if detect_gnu_ld();
  80. return {
  81. shared_ldflag => detect_gnu_cc() ? '-shared' : '-G',
  82. shared_sonameflag => '-h ',
  83. };
  84. },
  85. 'solaris-gcc-shared' => sub {
  86. return $shared_info{'linux-shared'} if detect_gnu_ld();
  87. return {
  88. # Note: we should also have -shared here, but because some
  89. # config targets define it with an added -static-libgcc
  90. # following it, we don't want to change the order. This
  91. # forces all solaris gcc config targets to define shared_ldflag
  92. shared_ldflag => '-Wl,-Bsymbolic',
  93. shared_defflag => "-Wl,-M,",
  94. shared_sonameflag => "-Wl,-h,",
  95. };
  96. },
  97. );