2005-12-13 19:38:12 +00:00
# SMB Build System
# - the output generating functions
#
# Copyright (C) Stefan (metze) Metzmacher 2004
# Copyright (C) Jelmer Vernooij 2004
# Released under the GNU GPL
2004-05-13 10:20:53 +00:00
2004-11-12 02:00:58 +00:00
package output ;
use strict ;
2004-11-14 13:52:16 +00:00
sub generate_shared_library ($)
2004-05-13 10:20:53 +00:00
{
2004-11-14 13:52:16 +00:00
my $ lib = shift ;
2005-10-28 18:26:26 +00:00
my $ link_name ;
2006-03-09 14:39:36 +00:00
my $ lib_name ;
2004-11-14 13:52:16 +00:00
2006-04-27 19:50:13 +00:00
$ lib - > { DEPEND_LIST } = [] ;
2005-10-28 18:26:26 +00:00
2006-03-09 14:39:36 +00:00
$ link_name = lc ( $ lib - > { NAME } ) ;
$ lib_name = $ link_name ;
if ( $ lib - > { TYPE } eq "LIBRARY" ) {
$ link_name = $ lib - > { NAME } ;
$ link_name =~ s/^LIB// ;
$ link_name = lc ( $ link_name ) ;
$ lib_name = "lib$link_name" ;
}
2005-10-28 18:26:26 +00:00
2007-11-21 11:10:45 +01:00
if ( $ lib - > { TYPE } eq "PYTHON" ) {
$ lib - > { SHAREDDIR } = "bin/python" ;
} elsif ( defined ( $ lib - > { LIBRARY_REALNAME } ) ) {
2006-04-03 00:46:17 +00:00
$ lib - > { BASEDIR } =~ s/^\.\///g ;
2006-11-06 16:57:00 +00:00
$ lib - > { SHAREDDIR } = $ lib - > { BASEDIR } ;
2006-03-21 08:32:50 +00:00
} else {
2006-04-03 00:46:17 +00:00
if ( $ lib - > { TYPE } eq "MODULE" ) {
2007-10-05 19:51:29 +00:00
my $ sane_subsystem = lc ( $ lib - > { SUBSYSTEM } ) ;
$ sane_subsystem =~ s/^lib// ;
$ lib - > { SHAREDDIR } = "bin/modules/$sane_subsystem" ;
2006-04-03 00:46:17 +00:00
$ lib - > { LIBRARY_REALNAME } = $ link_name ;
2007-10-05 19:51:29 +00:00
$ lib - > { LIBRARY_REALNAME } =~ s/^$sane_subsystem\_//g ;
2006-04-03 00:46:17 +00:00
$ lib - > { LIBRARY_REALNAME } . = ".\$(SHLIBEXT)" ;
} else {
2008-12-23 01:53:38 +01:00
$ lib - > { SHAREDDIR } = "\$(shliboutputdir)" ;
2006-04-03 00:46:17 +00:00
$ lib - > { LIBRARY_REALNAME } = "$lib_name.\$(SHLIBEXT)" ;
}
2006-03-21 08:32:50 +00:00
}
2006-03-22 22:55:29 +00:00
2006-12-21 01:51:35 +00:00
$ lib - > { LIBRARY_DEBUGNAME } = $ lib - > { LIBRARY_REALNAME } ;
2008-03-09 00:49:39 +01:00
$ lib - > { LIBRARY_SONAME } = "\$(if \$($lib->{NAME}_SOVERSION),$lib->{LIBRARY_REALNAME}.\$($lib->{NAME}_SOVERSION),$lib->{LIBRARY_REALNAME})" ;
$ lib - > { LIBRARY_REALNAME } = "\$(if \$($lib->{NAME}_VERSION),$lib->{LIBRARY_REALNAME}.\$($lib->{NAME}_VERSION),$lib->{LIBRARY_REALNAME})" ;
2006-03-22 22:55:29 +00:00
2008-02-18 15:31:15 +01:00
$ lib - > { RESULT_SHARED_LIBRARY } = "$lib->{SHAREDDIR}/$lib->{LIBRARY_REALNAME}" ;
$ lib - > { OUTPUT_SHARED_LIBRARY } = "-l$link_name" ;
2008-05-28 01:41:57 +02:00
$ lib - > { TARGET_SHARED_LIBRARY } = "$lib->{SHAREDDIR}/$lib->{LIBRARY_DEBUGNAME}" ;
2004-05-13 10:20:53 +00:00
}
2008-02-16 20:38:21 +01:00
sub generate_merged_obj ($)
{
my $ lib = shift ;
my $ link_name = $ lib - > { NAME } ;
$ link_name =~ s/^LIB// ;
2008-03-04 00:43:24 +01:00
$ lib - > { MERGED_OBJNAME } = lc ( $ link_name ) . ".o" ;
$ lib - > { RESULT_MERGED_OBJ } = $ lib - > { OUTPUT_MERGED_OBJ } = "bin/mergedobj/$lib->{MERGED_OBJNAME}" ;
$ lib - > { TARGET_MERGED_OBJ } = $ lib - > { RESULT_MERGED_OBJ } ;
2008-02-16 20:38:21 +01:00
}
2004-11-14 13:52:16 +00:00
sub generate_static_library ($)
2004-05-13 10:20:53 +00:00
{
2004-11-14 13:52:16 +00:00
my $ lib = shift ;
2005-10-28 18:26:26 +00:00
my $ link_name ;
2004-05-13 10:20:53 +00:00
2006-04-27 19:50:13 +00:00
$ lib - > { DEPEND_LIST } = [] ;
2004-05-13 10:20:53 +00:00
2005-10-28 18:26:26 +00:00
$ link_name = $ lib - > { NAME } ;
$ link_name =~ s/^LIB// ;
$ lib - > { LIBRARY_NAME } = "lib" . lc ( $ link_name ) . ".a" ;
2004-05-13 10:20:53 +00:00
2008-03-04 01:26:19 +01:00
$ lib - > { RESULT_STATIC_LIBRARY } = "bin/static/$lib->{LIBRARY_NAME}" ;
$ lib - > { TARGET_STATIC_LIBRARY } = $ lib - > { RESULT_STATIC_LIBRARY } ;
$ lib - > { STATICDIR } = 'bin/static' ;
$ lib - > { OUTPUT_STATIC_LIBRARY } = "-l" . lc ( $ link_name ) ;
2004-05-13 10:20:53 +00:00
}
2004-11-14 13:52:16 +00:00
sub generate_binary ($)
2004-05-13 10:20:53 +00:00
{
2004-11-14 13:52:16 +00:00
my $ bin = shift ;
2004-05-13 16:15:46 +00:00
2006-04-27 19:50:13 +00:00
$ bin - > { DEPEND_LIST } = [] ;
2008-02-18 18:55:37 +01:00
push ( @ { $ bin - > { LINK_FLAGS } } , "\$($bin->{NAME}\_FULL_OBJ_LIST)" ) ;
2004-05-13 16:15:46 +00:00
2008-02-18 15:31:15 +01:00
$ bin - > { DEBUGDIR } = "bin" ;
$ bin - > { RESULT_BINARY } = $ bin - > { OUTPUT_BINARY } = "$bin->{DEBUGDIR}/$bin->{NAME}" ;
$ bin - > { TARGET_BINARY } = $ bin - > { RESULT_BINARY } ;
2004-11-14 13:52:16 +00:00
$ bin - > { BINARY } = $ bin - > { NAME } ;
2004-05-13 10:20:53 +00:00
}
2006-09-07 14:00:40 +00:00
sub merge_array ($$)
{
# $dest is a reference to an array
# $src is an array
my ( $ dest , $ src ) = @ _ ;
return unless defined ( $ src ) ;
return unless ( $# { $ src } >= 0 ) ;
foreach my $ line ( @ { $ src } ) {
next if ( grep /^$line$/ , @ { $$ dest } ) ;
push ( @ { $$ dest } , $ line ) ;
}
}
2006-03-06 21:14:41 +00:00
sub create_output ($$)
2004-05-13 10:20:53 +00:00
{
2006-03-06 21:14:41 +00:00
my ( $ depend , $ config ) = @ _ ;
2004-11-14 13:52:16 +00:00
my $ part ;
foreach $ part ( values % { $ depend } ) {
2006-04-27 19:50:13 +00:00
next unless ( defined ( $ part - > { OUTPUT_TYPE } ) ) ;
2004-11-14 13:52:16 +00:00
2006-11-06 20:17:25 +00:00
generate_binary ( $ part ) if grep ( /BINARY/ , @ { $ part - > { OUTPUT_TYPE } } ) ;
generate_shared_library ( $ part ) if grep ( /SHARED_LIBRARY/ , @ { $ part - > { OUTPUT_TYPE } } ) ;
generate_static_library ( $ part ) if grep ( /STATIC_LIBRARY/ , @ { $ part - > { OUTPUT_TYPE } } ) ;
2008-02-16 20:38:21 +01:00
generate_merged_obj ( $ part ) if grep ( /MERGED_OBJ/ , @ { $ part - > { OUTPUT_TYPE } } ) ;
2006-11-06 20:17:25 +00:00
$ part - > { OUTPUT } = $ part - > { "OUTPUT_" . @ { $ part - > { OUTPUT_TYPE } } [ 0 ] } ;
$ part - > { TARGET } = $ part - > { "TARGET_" . @ { $ part - > { OUTPUT_TYPE } } [ 0 ] } ;
2004-11-14 13:52:16 +00:00
}
2004-05-13 10:20:53 +00:00
2004-11-14 13:52:16 +00:00
foreach $ part ( values % { $ depend } ) {
next if not defined ( $ part - > { OUTPUT_TYPE } ) ;
2006-09-07 14:00:40 +00:00
merge_array ( \ $ part - > { FINAL_CFLAGS } , $ part - > { CPPFLAGS } ) ;
merge_array ( \ $ part - > { FINAL_CFLAGS } , $ part - > { CFLAGS } ) ;
2008-02-19 03:57:30 +01:00
foreach ( @ { $ part - > { UNIQUE_DEPENDENCIES_ALL } } ) {
2006-04-26 16:31:40 +00:00
my $ elem = $ depend - > { $ _ } ;
2004-11-14 13:52:16 +00:00
next if $ elem == $ part ;
2008-02-26 03:28:44 +01:00
merge_array ( \ $ part - > { FINAL_CFLAGS } , $ elem - > { CPPFLAGS } ) ;
merge_array ( \ $ part - > { FINAL_CFLAGS } , $ elem - > { CFLAGS } ) ;
2006-04-26 11:58:42 +00:00
}
2006-09-07 14:00:40 +00:00
# Always import the link options of the unique dependencies
2007-04-22 11:40:11 +00:00
foreach ( @ { $ part - > { UNIQUE_DEPENDENCIES_LINK } } ) {
2006-04-26 16:31:40 +00:00
my $ elem = $ depend - > { $ _ } ;
2006-04-26 11:58:42 +00:00
next if $ elem == $ part ;
2008-02-26 03:28:44 +01:00
push ( @ { $ part - > { LINK_FLAGS } } , @ { $ elem - > { LIBS } } ) if defined ( $ elem - > { LIBS } ) ;
push ( @ { $ part - > { LINK_FLAGS } } , @ { $ elem - > { LDFLAGS } } ) if defined ( $ elem - > { LDFLAGS } ) ;
2008-02-18 18:55:37 +01:00
if ( defined ( $ elem - > { OUTPUT_TYPE } ) and @ { $ elem - > { OUTPUT_TYPE } } [ 0 ] eq "MERGED_OBJ" ) {
push ( @ { $ part - > { FULL_OBJ_LIST } } , $ elem - > { TARGET } ) ;
} else {
push ( @ { $ part - > { LINK_FLAGS } } , "\$($elem->{NAME}_OUTPUT)" ) if defined ( $ elem - > { OUTPUT } ) ;
2008-03-04 14:09:11 +01:00
push ( @ { $ part - > { DEPEND_LIST } } , $ elem - > { TARGET } ) if ( defined ( $ elem - > { TARGET } ) ) ;
2008-02-18 18:55:37 +01:00
}
2004-05-13 10:20:53 +00:00
}
}
2006-04-24 16:16:43 +00:00
foreach $ part ( values % { $ depend } ) {
2008-02-18 19:46:27 +01:00
if ( defined ( $ part - > { STANDARD_VISIBILITY } ) and ( $ part - > { STANDARD_VISIBILITY } ne "default" ) and
2006-04-24 20:45:32 +00:00
( $ config - > { visibility_attribute } eq "yes" ) ) {
2006-09-07 14:00:40 +00:00
push ( @ { $ part - > { FINAL_CFLAGS } } , "-fvisibility=$part->{STANDARD_VISIBILITY}" ) ;
2006-04-24 20:45:32 +00:00
}
2006-04-24 16:16:43 +00:00
}
2005-05-20 23:19:06 +00:00
return $ depend ;
2004-05-13 10:20:53 +00:00
}
2004-11-12 01:40:02 +00:00
1 ;