2 # - create output for Makefile
4 # Copyright (C) Stefan (metze) Metzmacher 2004
5 # Copyright (C) Jelmer Vernooij 2005
6 # Released under the GNU GPL
8 package smb_build
::makefile
;
17 my ($myname, $config, $mkfile) = @_;
20 bless($self, $myname);
22 $self->_set_config($config);
26 $self->output("################################################\n");
27 $self->output("# Autogenerated by source4/build/smb_build/makefile.pm #\n");
28 $self->output("################################################\n");
30 $self->output($mkfile);
37 my ($self, $config) = @_;
39 $self->{config
} = $config;
41 if (not defined($self->{config
}->{srcdir
})) {
42 $self->{config
}->{srcdir
} = '.';
45 if (not defined($self->{config
}->{builddir
})) {
46 $self->{config
}->{builddir
} = '.';
49 if ($self->{config
}->{prefix
} eq "NONE") {
50 $self->{config
}->{prefix
} = $self->{config
}->{ac_default_prefix
};
53 if ($self->{config
}->{exec_prefix
} eq "NONE") {
54 $self->{config
}->{exec_prefix
} = $self->{config
}->{prefix
};
60 my ($self, $text) = @_;
62 $self->{output
} .= $text;
65 sub _prepare_mk_files
($)
70 foreach (@smb_build::config_mk
::parsed_files
) {
75 $self->output("MK_FILES = " . array2oneperline
(\
@tmp) . "\n");
78 sub array2oneperline
($)
84 next unless defined($_);
86 $output .= " \\\n\t\t$_";
92 sub _prepare_list
($$$)
94 my ($self,$ctx,$var) = @_;
97 push(@tmparr, @
{$ctx->{$var}}) if defined($ctx->{$var});
99 my $tmplist = array2oneperline
(\
@tmparr);
100 return if ($tmplist eq "");
102 $self->output("$ctx->{NAME}_$var =$tmplist\n");
107 my ($self,$ctx) = @_;
109 $self->_prepare_list($ctx, "FULL_OBJ_LIST");
110 $self->_prepare_list($ctx, "DEPEND_LIST");
111 $self->_prepare_list($ctx, "LINK_FLAGS");
113 $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");
118 my ($self,$ctx) = @_;
120 my $sane_subsystem = lc($ctx->{SUBSYSTEM
});
121 $sane_subsystem =~ s/^lib//;
123 $self->output("PLUGINS += $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n");
124 $self->output("\$(eval \$(call shared_module_install_template,$sane_subsystem,$ctx->{LIBRARY_REALNAME}))\n");
126 $self->_prepare_list($ctx, "FULL_OBJ_LIST");
127 $self->_prepare_list($ctx, "DEPEND_LIST");
128 $self->_prepare_list($ctx, "LINK_FLAGS");
130 if (defined($ctx->{INIT_FUNCTION
}) and $ctx->{INIT_FUNCTION_TYPE
} =~ /\(\*\)/ and not ($ctx->{INIT_FUNCTION
} =~ /\(/)) {
131 $self->output("\$($ctx->{NAME}_OBJ_FILES): CFLAGS+=-D$ctx->{INIT_FUNCTION}=samba_init_module\n");
134 $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");
137 if (defined($ctx->{ALIASES
})) {
138 $self->output("\$(eval \$(foreach alias,". join(' ', @
{$ctx->{ALIASES
}}) . ",\$(call shared_module_alias_template,$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME},$sane_subsystem,\$(alias))))\n");
142 sub StaticLibraryPrimitives
($$)
144 my ($self,$ctx) = @_;
146 $self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
147 $self->_prepare_list($ctx, "FULL_OBJ_LIST");
150 sub SharedLibraryPrimitives
($$)
152 my ($self,$ctx) = @_;
154 if (not grep(/STATIC_LIBRARY/, @
{$ctx->{OUTPUT_TYPE
}})) {
155 $self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
156 $self->_prepare_list($ctx, "FULL_OBJ_LIST");
160 sub SharedLibrary
($$)
162 my ($self,$ctx) = @_;
164 $self->output("SHARED_LIBS += $ctx->{RESULT_SHARED_LIBRARY}\n");
166 $self->_prepare_list($ctx, "DEPEND_LIST");
167 $self->_prepare_list($ctx, "LINK_FLAGS");
169 $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");
174 my ($self, $ctx) = @_;
176 $self->output("\$(call partial_link_template, $ctx->{OUTPUT}, \$($ctx->{NAME}_OBJ_FILES))\n");
179 sub InitFunctions
($$)
181 my ($self, $ctx) = @_;
182 $self->output("\$($ctx->{NAME}_OBJ_FILES): CFLAGS+=-DSTATIC_$ctx->{NAME}_MODULES=\"\$($ctx->{NAME}_INIT_FUNCTIONS)$ctx->{INIT_FUNCTION_SENTINEL}\"\n");
185 sub StaticLibrary
($$)
187 my ($self,$ctx) = @_;
189 $self->output("STATIC_LIBS += $ctx->{RESULT_STATIC_LIBRARY}\n") if ($ctx->{TYPE
} eq "LIBRARY");
190 $self->output("$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
191 $self->output("$ctx->{RESULT_STATIC_LIBRARY}: \$($ctx->{NAME}_FULL_OBJ_LIST)\n");
196 my ($self,$ctx) = @_;
198 unless (defined($ctx->{INSTALLDIR
})) {
199 } elsif ($ctx->{INSTALLDIR
} eq "SBINDIR") {
200 $self->output("\$(eval \$(call sbinary_install_template,$ctx->{RESULT_BINARY}))\n");
201 } elsif ($ctx->{INSTALLDIR
} eq "BINDIR") {
202 $self->output("\$(eval \$(call binary_install_template,$ctx->{RESULT_BINARY}))\n");
205 $self->_prepare_list($ctx, "FULL_OBJ_LIST");
206 $self->_prepare_list($ctx, "DEPEND_LIST");
207 $self->_prepare_list($ctx, "LINK_FLAGS");
209 if (defined($ctx->{USE_HOSTCC
}) && $ctx->{USE_HOSTCC
} eq "YES") {
210 $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");
212 $self->output("\$(eval \$(call binary_link_template, $ctx->{RESULT_BINARY}, \$($ctx->{NAME}_FULL_OBJ_LIST) \$($ctx->{NAME}_DEPEND_LIST), \$($ctx->{NAME}_LINK_FLAGS)))\n");
218 my ($self, $file) = @_;
220 $self->_prepare_mk_files();
222 $self->output("ALL_OBJS = " . array2oneperline
($self->{all_objs
}) . "\n");
224 open(MAKEFILE
,">$file") || die ("Can't open $file\n");
225 print MAKEFILE
$self->{output
};
228 print __FILE__
.": creating $file\n";
231 my $sort_available = eval "use sort 'stable'; return 1;";
232 $sort_available = 0 unless defined($sort_available);
235 return 1 if($a =~ m
#^\-I/#);
236 return -1 if($b =~ m
#^\-I/#);
242 my ($self, $key) = @_;
244 my $srcdir = $self->{config
}->{srcdir
};
245 my $builddir = $self->{config
}->{builddir
};
247 my $src_ne_build = ($srcdir ne $builddir) ?
1 : 0;
249 return unless defined ($key->{FINAL_CFLAGS
});
250 return unless (@
{$key->{FINAL_CFLAGS
}} > 0);
252 my @sorted_cflags = @
{$key->{FINAL_CFLAGS
}};
253 if ($sort_available) {
254 @sorted_cflags = sort by_path @
{$key->{FINAL_CFLAGS
}};
257 # Rewrite CFLAGS so that both the source and the build
258 # directories are in the path.
260 foreach my $flag (@sorted_cflags) {
262 if($flag =~ m
#^-I([^/].*$)#) {
264 if ($dir =~ /^\$\(/) {
265 push (@cflags, $flag);
268 $dir =~ s
#^\$\((?:src|build)dir\)/?##;
269 push(@cflags, "-I$builddir/$dir", "-I$srcdir/$dir");
273 push(@cflags, $flag);
276 my $cflags = join(' ', @cflags);
278 $self->output("\$(patsubst %.ho,%.d,\$($key->{NAME}_OBJ_FILES:.o=.d)) \$($key->{NAME}_OBJ_FILES): CFLAGS+= $cflags\n");