xref: /AOO41X/main/zlib/make_patched_header.pl (revision 83aea518c7f3c808307ad79888307cd0d661615c)
1cdf0e10cSrcweir:
2cdf0e10cSrcweireval 'exec perl -S $0 ${1+"$@"}'
3cdf0e10cSrcweir    if 0;
4*7e90fac2SAndrew Rist#**************************************************************
5cdf0e10cSrcweir#
6*7e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
7*7e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
8*7e90fac2SAndrew Rist#  distributed with this work for additional information
9*7e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
10*7e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
11*7e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
12*7e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
13cdf0e10cSrcweir#
14*7e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
15cdf0e10cSrcweir#
16*7e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
17*7e90fac2SAndrew Rist#  software distributed under the License is distributed on an
18*7e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*7e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
20*7e90fac2SAndrew Rist#  specific language governing permissions and limitations
21*7e90fac2SAndrew Rist#  under the License.
22cdf0e10cSrcweir#
23*7e90fac2SAndrew Rist#**************************************************************
24*7e90fac2SAndrew Rist
25cdf0e10cSrcweir#
26cdf0e10cSrcweir# make_patched_header - make patched header
27cdf0e10cSrcweir#
28cdf0e10cSrcweir
29cdf0e10cSrcweiruse strict;
30cdf0e10cSrcweiruse File::Basename;
31cdf0e10cSrcweiruse File::Path;
32cdf0e10cSrcweiruse Carp;
33cdf0e10cSrcweir
34cdf0e10cSrcweirmy $patched_file = shift @ARGV;
35cdf0e10cSrcweir$patched_file =~ s/\\/\//g;
36cdf0e10cSrcweirmy $module = shift @ARGV;
37cdf0e10cSrcweirmy $patch_dir = dirname($patched_file);
38cdf0e10cSrcweirmy $orig_file = $patched_file;
39cdf0e10cSrcweir$orig_file =~ s/\/patched\//\//;
40cdf0e10cSrcweir
41cdf0e10cSrcweirif (!-f $orig_file) { carp("Cannot find file $orig_file\n"); };
42cdf0e10cSrcweirif (!-d $patch_dir) {
43cdf0e10cSrcweir    mkpath($patch_dir, 0, 0775);
44cdf0e10cSrcweir    if (!-d $patch_dir) {("mkdir: could not create directory $patch_dir\n"); };
45cdf0e10cSrcweir};
46cdf0e10cSrcweir
47cdf0e10cSrcweiropen(PATCHED_FILE, ">$patched_file") or carp("Cannot open file $patched_file\n");
48cdf0e10cSrcweiropen(ORIG_FILE, "<$orig_file") or carp("Cannot open file $orig_file\n");
49cdf0e10cSrcweirforeach (<ORIG_FILE>) {
50cdf0e10cSrcweir    if (/#include\s*"(\w+\.h\w*)"/) {
51cdf0e10cSrcweir        my $include = $1;
52cdf0e10cSrcweir        s/#include "$include"/#include <$module\/$include>/g;
53cdf0e10cSrcweir    };
54cdf0e10cSrcweir    print PATCHED_FILE $_;
55cdf0e10cSrcweir};
56cdf0e10cSrcweirclose PATCHED_FILE;
57cdf0e10cSrcweirclose ORIG_FILE;
58cdf0e10cSrcweir
59cdf0e10cSrcweirexit(0);
60cdf0e10cSrcweir
61