xref: /netbsd-src/crypto/external/bsd/openssl/dist/util/write-man-symlinks (revision b0d1725196a7921d003d2c66a14f186abda4176b)
1*b0d17251Schristos#! /usr/bin/env perl
2*b0d17251Schristos# Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
3*b0d17251Schristos#
4*b0d17251Schristos# Licensed under the Apache License 2.0 (the "License").  You may not use
5*b0d17251Schristos# this file except in compliance with the License.  You can obtain a copy
6*b0d17251Schristos# in the file LICENSE in the source distribution or at
7*b0d17251Schristos# https://www.openssl.org/source/license.html
8*b0d17251Schristos
9*b0d17251Schristos
10*b0d17251Schristosrequire 5.10.0;
11*b0d17251Schristosuse warnings;
12*b0d17251Schristosuse strict;
13*b0d17251Schristos
14*b0d17251Schristosuse FindBin;
15*b0d17251Schristosuse lib "$FindBin::Bin/perl";
16*b0d17251Schristos
17*b0d17251Schristosuse OpenSSL::Util::Pod;
18*b0d17251Schristos
19*b0d17251Schristosif ($#ARGV + 1 != 5 || $ARGV[0] !~ /^(un)?install$/) {
20*b0d17251Schristos    print "Usage: write-man-symlinks [install|uninstall] src-dir build-dir man-page-name target-dir\n";
21*b0d17251Schristos    exit;
22*b0d17251Schristos}
23*b0d17251Schristos
24*b0d17251Schristosmy $action = $ARGV[0];
25*b0d17251Schristosmy $srcdir = $ARGV[1];
26*b0d17251Schristosmy $builddir = $ARGV[2];
27*b0d17251Schristosmy $manname = $ARGV[3];
28*b0d17251Schristosmy $targetdir = $ARGV[4];
29*b0d17251Schristos
30*b0d17251Schristos$manname =~ m|(.+)\.(.+)|;
31*b0d17251Schristosmy $mainf = $1;
32*b0d17251Schristosmy $section = $2;
33*b0d17251Schristosdie "Bad src file" if !defined $mainf;
34*b0d17251Schristosmy $podfile = "$srcdir/$mainf.pod";
35*b0d17251Schristos#Some pod files are generated and are in the build dir
36*b0d17251Schristosunless (-e $podfile) {
37*b0d17251Schristos    $podfile = "$builddir/$mainf.pod";
38*b0d17251Schristos}
39*b0d17251Schristosmy %podinfo = extract_pod_info($podfile);
40*b0d17251Schristos
41*b0d17251Schristosfor my $name (@{$podinfo{names}}) {
42*b0d17251Schristos    next if $name eq $mainf;
43*b0d17251Schristos    if ($action eq "install") {
44*b0d17251Schristos        symlink "$manname", "$targetdir/$name.$section";
45*b0d17251Schristos    } else {
46*b0d17251Schristos        unlink "$targetdir/$name.$section";
47*b0d17251Schristos    }
48*b0d17251Schristos}
49