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