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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# Samba Build System
# - create output for Makefile
#
# Copyright (C) Stefan (metze) Metzmacher 2004
# Copyright (C) Jelmer Vernooij 2005
# Released under the GNU GPL
package smb_build::makefile;
use smb_build::output;
use File::Basename;
use strict;
use Cwd 'abs_path';
sub new($$$)
{
my ($myname, $config, $mkfile) = @_;
my $self = {};
bless($self, $myname);
$self->_set_config($config);
$self->{output} = "";
$self->output("################################################\n");
$self->output("# Autogenerated by source4/build/smb_build/makefile.pm #\n");
$self->output("################################################\n");
$self->output("\n");
$self->output($mkfile);
return $self;
}
sub _set_config($$)
{
my ($self, $config) = @_;
$self->{config} = $config;
if (not defined($self->{config}->{srcdir})) {
$self->{config}->{srcdir} = '.';
}
if (not defined($self->{config}->{builddir})) {
$self->{config}->{builddir} = '.';
}
if ($self->{config}->{prefix} eq "NONE") {
$self->{config}->{prefix} = $self->{config}->{ac_default_prefix};
}
if ($self->{config}->{exec_prefix} eq "NONE") {
$self->{config}->{exec_prefix} = $self->{config}->{prefix};
}
}
sub output($$)
{
my ($self, $text) = @_;
$self->{output} .= $text;
}
sub _prepare_mk_files($)
{
my $self = shift;
my @tmp = ();
foreach (@smb_build::config_mk::parsed_files) {
s/ .*$//g;
push (@tmp, $_);
}
$self->output("MK_FILES = " . array2oneperline(\@tmp) . "\n");
}
sub array2oneperline($)
{
my $array = shift;
my $output = "";
foreach (@$array) {
next unless defined($_);
$output .= " \\\n\t\t$_";
}
return $output;
}
sub _prepare_list($$$)
{
my ($self,$ctx,$var) = @_;
my @tmparr = ();
push(@tmparr, @{$ctx->{$var}}) if defined($ctx->{$var});
my $tmplist = array2oneperline(\@tmparr);
return if ($tmplist eq "");
$self->output("$ctx->{NAME}_$var =$tmplist\n");
}
sub PythonModule($$)
{
my ($self,$ctx) = @_;
$self->_prepare_list($ctx, "FULL_OBJ_LIST");
$self->_prepare_list($ctx, "DEPEND_LIST");
$self->_prepare_list($ctx, "LINK_FLAGS");
$self->output("\$(eval \$(call python_c_module_template,$ctx->{LIBRARY_REALNAME},\$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST), \$($ctx->{NAME}\_FULL_OBJ_LIST) \$($ctx->{NAME}_LINK_FLAGS)))\n");
}
sub SharedModule($$)
{
my ($self,$ctx) = @_;
my $sane_subsystem = lc($ctx->{SUBSYSTEM});
$sane_subsystem =~ s/^lib//;
$self->output("PLUGINS += $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n");
$self->output("\$(eval \$(call shared_module_install_template,$sane_subsystem,$ctx->{LIBRARY_REALNAME}))\n");
$self->_prepare_list($ctx, "FULL_OBJ_LIST");
$self->_prepare_list($ctx, "DEPEND_LIST");
$self->_prepare_list($ctx, "LINK_FLAGS");
if (defined($ctx->{INIT_FUNCTION}) and $ctx->{INIT_FUNCTION_TYPE} =~ /\(\*\)/ and not ($ctx->{INIT_FUNCTION} =~ /\(/)) {
$self->output("\$($ctx->{NAME}_OBJ_FILES): CFLAGS+=-D$ctx->{INIT_FUNCTION}=samba_init_module\n");
}
$self->output("\$(eval \$(call shared_module_template,$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}, \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST), \$($ctx->{NAME}\_FULL_OBJ_LIST) \$($ctx->{NAME}_LINK_FLAGS)))\n");
if (defined($ctx->{ALIASES})) {
$self->output("\$(eval \$(foreach alias,". join(' ', @{$ctx->{ALIASES}}) . ",\$(call shared_module_alias_template,$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME},$sane_subsystem,\$(alias))))\n");
}
}
sub StaticLibraryPrimitives($$)
{
my ($self,$ctx) = @_;
$self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
$self->_prepare_list($ctx, "FULL_OBJ_LIST");
}
sub SharedLibraryPrimitives($$)
{
my ($self,$ctx) = @_;
if (not grep(/STATIC_LIBRARY/, @{$ctx->{OUTPUT_TYPE}})) {
$self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
$self->_prepare_list($ctx, "FULL_OBJ_LIST");
}
}
sub SharedLibrary($$)
{
my ($self,$ctx) = @_;
$self->output("SHARED_LIBS += $ctx->{RESULT_SHARED_LIBRARY}\n");
$self->_prepare_list($ctx, "DEPEND_LIST");
$self->_prepare_list($ctx, "LINK_FLAGS");
$self->output("\$(eval \$(call shared_library_template,$ctx->{RESULT_SHARED_LIBRARY}, \$($ctx->{NAME}_DEPEND_LIST) \$($ctx->{NAME}_FULL_OBJ_LIST), \$($ctx->{NAME}\_FULL_OBJ_LIST) \$($ctx->{NAME}_LINK_FLAGS),$ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME},$ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}))\n");
}
sub MergedObj($$)
{
my ($self, $ctx) = @_;
$self->output("\$(call partial_link_template, $ctx->{OUTPUT}, \$($ctx->{NAME}_OBJ_FILES))\n");
}
sub InitFunctions($$)
{
my ($self, $ctx) = @_;
$self->output("\$($ctx->{NAME}_OBJ_FILES): CFLAGS+=-DSTATIC_$ctx->{NAME}_MODULES=\"\$($ctx->{NAME}_INIT_FUNCTIONS)$ctx->{INIT_FUNCTION_SENTINEL}\"\n");
}
sub StaticLibrary($$)
{
my ($self,$ctx) = @_;
$self->output("STATIC_LIBS += $ctx->{RESULT_STATIC_LIBRARY}\n") if ($ctx->{TYPE} eq "LIBRARY");
$self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
$self->output("$ctx->{RESULT_STATIC_LIBRARY}: \$($ctx->{NAME}_FULL_OBJ_LIST)\n");
}
sub Binary($$)
{
my ($self,$ctx) = @_;
unless (defined($ctx->{INSTALLDIR})) {
} elsif ($ctx->{INSTALLDIR} eq "SBINDIR") {
$self->output("\$(eval \$(call sbinary_install_template,$ctx->{RESULT_BINARY}))\n");
} elsif ($ctx->{INSTALLDIR} eq "BINDIR") {
$self->output("\$(eval \$(call binary_install_template,$ctx->{RESULT_BINARY}))\n");
}
$self->_prepare_list($ctx, "FULL_OBJ_LIST");
$self->_prepare_list($ctx, "DEPEND_LIST");
$self->_prepare_list($ctx, "LINK_FLAGS");
if (defined($ctx->{USE_HOSTCC}) && $ctx->{USE_HOSTCC} eq "YES") {
$self->output("\$(eval \$(call host_binary_link_template, $ctx->{RESULT_BINARY}, \$($ctx->{NAME}_FULL_OBJ_LIST) \$($ctx->{NAME}_DEPEND_LIST), \$($ctx->{NAME}_LINK_FLAGS)))\n");
} else {
$self->output("\$(eval \$(call binary_link_template, $ctx->{RESULT_BINARY}, \$($ctx->{NAME}_FULL_OBJ_LIST) \$($ctx->{NAME}_DEPEND_LIST), \$($ctx->{NAME}_LINK_FLAGS)))\n");
}
}
sub write($$)
{
my ($self, $file) = @_;
$self->_prepare_mk_files();
$self->output("ALL_OBJS = " . array2oneperline($self->{all_objs}) . "\n");
open(MAKEFILE,">$file") || die ("Can't open $file\n");
print MAKEFILE $self->{output};
close(MAKEFILE);
print __FILE__.": creating $file\n";
}
my $sort_available = eval "use sort 'stable'; return 1;";
$sort_available = 0 unless defined($sort_available);
sub by_path {
return 1 if($a =~ m#^\-I/#);
return -1 if($b =~ m#^\-I/#);
return 0;
}
sub CFlags($$)
{
my ($self, $key) = @_;
my $srcdir = $self->{config}->{srcdir};
my $builddir = $self->{config}->{builddir};
my $src_ne_build = ($srcdir ne $builddir) ? 1 : 0;
return unless defined ($key->{FINAL_CFLAGS});
return unless (@{$key->{FINAL_CFLAGS}} > 0);
my @sorted_cflags = @{$key->{FINAL_CFLAGS}};
if ($sort_available) {
@sorted_cflags = sort by_path @{$key->{FINAL_CFLAGS}};
}
# Rewrite CFLAGS so that both the source and the build
# directories are in the path.
my @cflags = ();
foreach my $flag (@sorted_cflags) {
if($src_ne_build) {
if($flag =~ m#^-I([^/].*$)#) {
my $dir = $1;
if ($dir =~ /^\$\(/) {
push (@cflags, $flag);
next;
}
$dir =~ s#^\$\((?:src|build)dir\)/?##;
push(@cflags, "-I$builddir/$dir", "-I$srcdir/$dir");
next;
}
}
push(@cflags, $flag);
}
my $cflags = join(' ', @cflags);
$self->output("\$(patsubst %.ho,%.d,\$($key->{NAME}_OBJ_FILES:.o=.d)) \$($key->{NAME}_OBJ_FILES): CFLAGS+= $cflags\n");
}
1;
|