/
makemake
executable file
·193 lines (172 loc) · 4.92 KB
/
makemake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/perl
# **** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "MPL"); you may not use this file
# except in compliance with the MPL. You may obtain a copy of
# the MPL at http://www.mozilla.org/MPL/
#
# Software distributed under the MPL is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the MPL for the specific language governing
# rights and limitations under the MPL.
#
# The Original Code is ipccode.
#
# The Initial Developer of the Original Code is Patrick Brunschwig.
# Portions created by Patrick Brunschwig <patrick@mozilla-enigmail.org> are
# Copyright (C) 2011 Patrick Brunschwig. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
# ***** END LICENSE BLOCK *****
# makemake: script to generate Makefile from Makefile.in
# -r: process recursively all subdirectories
# -o DIR: use DIR as MOZ_OBJDIR
# Usage: makemake [-o @TOPSRCDIR@/somedir] [-r]
my $makelist="./Makefile.in";
my $mozObjDir=".";
my $makefile;
my $cwd=`pwd`;
chomp($cwd);
my $topdir=$cwd;
my $depth="";
open(MAKEFILE, $makelist) || die ("Could not open '$makelist'\n");
while (my $l = <MAKEFILE>) {
chomp($l);
if ($l =~ /^\s*DEPTH\s*=/) {
$l =~ s/(^\s*DEPTH\s*=\s*)(.*)$/$2/;
$depth = $l;
}
}
close(MAKEFILE);
if ($depth eq "") {
while ( (length($topdir)>0) && ( basename($topdir) ne "mozilla" )) {
$topdir=dirname($topdir);
}
}
else {
chdir($depth) || die "Directory '$depth' not found\n";
chdir("..");
$topdir=`pwd`;
chomp($topdir);
chdir($cwd);
}
print "INFO: found toplevel source directory $topdir\n";
if (open(MOZCONFIG, "$topdir/.mozconfig")) {
while (my $l = <MOZCONFIG>) {
chomp($l);
if ($l =~ /^\s*mk_add_options\s+MOZ_OBJDIR\s*=/) {
$l =~ s/(^\s*mk_add_options\s+MOZ_OBJDIR\s*=\s*)(.*)$/$2/;
$mozObjDir = $l;
}
}
close(MOZCONFIG);
}
else {
print "INFO: no .mozconfig file found\n";
}
while ( $#ARGV >= 0 ) {
if ($ARGV[0] eq "-o") {
$mozObjDir=$ARGV[1];
shift @ARGV;
}
if ($ARGV[0] eq "-r") {
$makelist=`find . -name Makefile.in -print`;
break;
}
shift @ARGV;
}
$mozObjDir =~ s/\@TOPSRCDIR\@/$topdir/;
if ($mozObjDir eq ".") {
print "INFO: no MOZ_OBJDIR used\n";
}
else {
print "INFO: using MOZ_OBJDIR=$mozObjDir\n\n";
}
foreach $makefile (split(/[ \n\r]+/, $makelist)) {
$makefile =~ s/^\.\///;
my $dir=dirname("$cwd/$makefile");
my $wd=$dir;
print "Processing: $wd\n";
my $top_srcdir="";
my $newMakefile = $makefile;
$newMakefile =~ s/.in$//;
if ($mozObjDir eq ".") {
# no OBJDIR specified
if ($depth eq "") {
while ( (length($wd)>0) && (basename($wd) ne "mozilla") ) {
if (length($top_srcdir) == 0) {
$top_srcdir="..";
}
else {
$top_srcdir="../$top_srcdir";
}
$wd=dirname($wd);
}
}
else {
$top_srcdir=$topdir;
}
$srcdir=".";
}
else {
# using OBJDIR
if ($depth eq "") {
# while ( (length($wd)>0) && (basename($wd) ne "mozilla") ) {
while ( length($wd)>0 ) {
$wd=dirname($wd);
}
$top_srcdir="$wd";
}
else {
$top_srcdir="$topdir";
}
$srcdir=$dir;
my $targetDir=$srcdir;
$targetDir =~ s/$top_srcdir/$mozObjDir/x;
system("mkdir -p '$targetDir'");
$newMakefile=sprintf("%s/%s", $targetDir, basename($newMakefile));
}
# print "Creating file $newMakefile\n";
open(INFILE, $makefile) || die ("cannot open input file '$makefile'\n");
open(OUTFILE, ">$newMakefile") || die ("cannot open output file '$newMakefile'\n");
my $line;
while ($line = <INFILE>) {
$line =~ s/\@srcdir\@/$srcdir/g;
$line =~ s/\@top_srcdir\@/$top_srcdir\/mozilla/g;
print OUTFILE $line;
}
close(INFILE);
close(OUTFILE);
}
if ($mozObjDir eq ".") {
print "Done\n\n";
}
else {
my $newWd=$cwd;
$newWd =~ s/$topdir/$mozObjDir/x;
print "Done. The code can now be compiled from $newWd\n\n";
}
sub basename {
my $fn=$_[0];
$fn =~ s/^(.*)\/(.*)$/$2/;
return $fn;
}
sub dirname {
my $dn=$_[0];
$dn =~ s/^(.*)\/(.*)$/$1/;
return $dn;
}