xref: /freebsd/crypto/openssl/util/mkbuildinf.pl (revision 0d0c8621fd181e507f0fb50ffcca606faf66a8c2)
1#! /usr/bin/env perl
2# Copyright 2014-2025 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
9use strict;
10use warnings;
11
12my $platform = pop @ARGV;
13my $cflags = join(' ', @ARGV);
14$cflags =~ s(\\)(\\\\)g;
15$cflags = "compiler: $cflags";
16
17# Use the value of the envvar SOURCE_DATE_EPOCH, even if it's
18# zero or the empty string.
19my $date = gmtime($ENV{'SOURCE_DATE_EPOCH'} // time()) . " UTC";
20
21print <<"END_OUTPUT";
22/*
23 * WARNING: do not edit!
24 * Generated by util/mkbuildinf.pl
25 *
26 * Copyright 2014-2025 The OpenSSL Project Authors. All Rights Reserved.
27 *
28 * Licensed under the Apache License 2.0 (the "License").  You may not use
29 * this file except in compliance with the License.  You can obtain a copy
30 * in the file LICENSE in the source distribution or at
31 * https://www.openssl.org/source/license.html
32 */
33
34#define PLATFORM "platform: $platform"
35#define DATE "built on: $date"
36
37/*
38 * Generate compiler_flags as an array of individual characters. This is a
39 * workaround for the situation where CFLAGS gets too long for a C90 string
40 * literal
41 */
42static const char compiler_flags[] = {
43END_OUTPUT
44
45my $ctr = 0;
46foreach my $c (split //, $cflags) {
47    $c =~ s|([\\'])|\\$1|;
48    # Max 16 characters per line
49    if  (($ctr++ % 16) == 0) {
50        if ($ctr != 1) {
51            print "\n";
52        }
53        print "    ";
54    }
55    print "'$c',";
56}
57print <<"END_OUTPUT";
58'\\0'
59};
60END_OUTPUT
61