mkinstallvars.pl 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #! /usr/bin/env perl
  2. # Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. # All variables are supposed to come from Makefile, in environment variable
  9. # form, or passed as variable assignments on the command line.
  10. # The result is a Perl module creating the package OpenSSL::safe::installdata.
  11. use File::Spec;
  12. # These are expected to be set up as absolute directories
  13. my @absolutes = qw(PREFIX);
  14. # These may be absolute directories, and if not, they are expected to be set up
  15. # as subdirectories to PREFIX
  16. my @subdirs = qw(BINDIR LIBDIR INCLUDEDIR APPLINKDIR ENGINESDIR MODULESDIR
  17. PKGCONFIGDIR CMAKECONFIGDIR);
  18. my %keys = ();
  19. foreach (@ARGV) {
  20. (my $k, my $v) = m|^([^=]*)=(.*)$|;
  21. $keys{$k} = 1;
  22. $ENV{$k} = $v;
  23. }
  24. foreach my $k (sort keys %keys) {
  25. my $v = $ENV{$k};
  26. $v = File::Spec->rel2abs($v) if $v && grep { $k eq $_ } @absolutes;
  27. $ENV{$k} = $v;
  28. }
  29. foreach my $k (sort keys %keys) {
  30. my $v = $ENV{$k} || '.';
  31. # Absolute paths for the subdir variables are computed. This provides
  32. # the usual form of values for names that have become norm, known as GNU
  33. # installation paths.
  34. # For the benefit of those that need it, the subdirectories are preserved
  35. # as they are, using the same variable names, suffixed with '_REL', if they
  36. # are indeed subdirectories.
  37. if (grep { $k eq $_ } @subdirs) {
  38. if (File::Spec->file_name_is_absolute($v)) {
  39. $ENV{"${k}_REL"} = File::Spec->abs2rel($v, $ENV{PREFIX});
  40. } else {
  41. $ENV{"${k}_REL"} = $v;
  42. $v = File::Spec->rel2abs($v, $ENV{PREFIX});
  43. }
  44. }
  45. $ENV{$k} = $v;
  46. }
  47. print <<_____;
  48. package OpenSSL::safe::installdata;
  49. use strict;
  50. use warnings;
  51. use Exporter;
  52. our \@ISA = qw(Exporter);
  53. our \@EXPORT = qw(\$PREFIX
  54. \$BINDIR \$BINDIR_REL
  55. \$LIBDIR \$LIBDIR_REL
  56. \$INCLUDEDIR \$INCLUDEDIR_REL
  57. \$APPLINKDIR \$APPLINKDIR_REL
  58. \$ENGINESDIR \$ENGINESDIR_REL
  59. \$MODULESDIR \$MODULESDIR_REL
  60. \$PKGCONFIGDIR \$PKGCONFIGDIR_REL
  61. \$CMAKECONFIGDIR \$CMAKECONFIGDIR_REL
  62. \$VERSION \@LDLIBS);
  63. our \$PREFIX = '$ENV{PREFIX}';
  64. our \$BINDIR = '$ENV{BINDIR}';
  65. our \$BINDIR_REL = '$ENV{BINDIR_REL}';
  66. our \$LIBDIR = '$ENV{LIBDIR}';
  67. our \$LIBDIR_REL = '$ENV{LIBDIR_REL}';
  68. our \$INCLUDEDIR = '$ENV{INCLUDEDIR}';
  69. our \$INCLUDEDIR_REL = '$ENV{INCLUDEDIR_REL}';
  70. our \$APPLINKDIR = '$ENV{APPLINKDIR}';
  71. our \$APPLINKDIR_REL = '$ENV{APPLINKDIR_REL}';
  72. our \$ENGINESDIR = '$ENV{ENGINESDIR}';
  73. our \$ENGINESDIR_REL = '$ENV{ENGINESDIR_REL}';
  74. our \$MODULESDIR = '$ENV{MODULESDIR}';
  75. our \$MODULESDIR_REL = '$ENV{MODULESDIR_REL}';
  76. our \$PKGCONFIGDIR = '$ENV{PKGCONFIGDIR}';
  77. our \$PKGCONFIGDIR_REL = '$ENV{PKGCONFIGDIR_REL}';
  78. our \$CMAKECONFIGDIR = '$ENV{CMAKECONFIGDIR}';
  79. our \$CMAKECONFIGDIR_REL = '$ENV{CMAKECONFIGDIR_REL}';
  80. our \$VERSION = '$ENV{VERSION}';
  81. our \@LDLIBS =
  82. # Unix and Windows use space separation, VMS uses comma separation
  83. split(/ +| *, */, '$ENV{LDLIBS}');
  84. 1;
  85. _____