2005-12-13 19:38:12 +00:00
# Samba Build System
# - create output for Makefile
#
# Copyright (C) Stefan (metze) Metzmacher 2004
# Copyright (C) Jelmer Vernooij 2005
# Released under the GNU GPL
2004-05-13 10:20:53 +00:00
2005-10-21 21:43:39 +00:00
package smb_build::makefile ;
2007-12-04 14:20:46 +01:00
use smb_build::output ;
2007-11-21 11:10:45 +01:00
use File::Basename ;
2004-11-12 02:00:58 +00:00
use strict ;
2006-04-12 13:02:56 +00:00
use Cwd 'abs_path' ;
2005-10-21 21:43:39 +00:00
2005-10-26 23:36:04 +00:00
sub new ($$$)
2005-10-21 21:43:39 +00:00
{
2005-10-26 23:36:04 +00:00
my ( $ myname , $ config , $ mkfile ) = @ _ ;
2008-02-25 19:11:04 +01:00
my $ self = { } ;
2005-10-21 21:43:39 +00:00
bless ( $ self , $ myname ) ;
2008-02-25 19:11:04 +01:00
$ self - > _set_config ( $ config ) ;
2005-10-21 22:49:23 +00:00
$ self - > { output } = "" ;
2005-10-26 19:07:01 +00:00
$ self - > { mkfile } = $ mkfile ;
2005-10-21 22:49:23 +00:00
$ self - > output ( "################################################\n" ) ;
$ self - > output ( "# Autogenerated by build/smb_build/makefile.pm #\n" ) ;
$ self - > output ( "################################################\n" ) ;
$ self - > output ( "\n" ) ;
2005-10-21 21:43:39 +00:00
return $ self ;
}
2008-02-25 19:11:04 +01:00
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 } ;
}
}
2005-10-21 22:49:23 +00:00
sub output ($$)
{
my ( $ self , $ text ) = @ _ ;
$ self - > { output } . = $ text ;
}
2005-10-26 19:07:01 +00:00
sub _prepare_mk_files ($)
2004-05-13 10:20:53 +00:00
{
2005-10-21 22:49:23 +00:00
my $ self = shift ;
2005-10-26 19:07:01 +00:00
my @ tmp = ( ) ;
2005-10-26 14:18:27 +00:00
2005-10-26 19:07:01 +00:00
foreach ( @ smb_build:: config_mk:: parsed_files ) {
s/ .*$//g ;
push ( @ tmp , $ _ ) ;
2005-10-26 14:18:27 +00:00
}
2008-02-25 18:05:47 +01:00
$ self - > output ( "
2007-10-18 13:27:48 +02:00
ifneq ( \ $ ( MAKECMDGOALS ) , clean )
ifneq ( \ $ ( MAKECMDGOALS ) , distclean )
ifneq ( \ $ ( MAKECMDGOALS ) , realdistclean )
" ) ;
2005-10-26 19:07:01 +00:00
$ self - > output ( "MK_FILES = " . array2oneperline ( \ @ tmp ) . "\n" ) ;
2008-02-25 18:05:47 +01:00
$ self - > output ( "
2007-10-18 13:27:48 +02:00
endif
endif
endif
" ) ;
2005-06-27 12:09:52 +00:00
}
2004-05-13 10:20:53 +00:00
sub array2oneperline ($)
{
my $ array = shift ;
my $ output = "" ;
2005-07-21 21:27:39 +00:00
foreach ( @$ array ) {
next unless defined ( $ _ ) ;
2004-05-13 10:20:53 +00:00
2005-07-21 21:27:39 +00:00
$ output . = " \\\n\t\t$_" ;
2004-05-13 10:20:53 +00:00
}
return $ output ;
}
2008-02-18 12:35:39 +01:00
sub _prepare_list ($$$)
2004-05-13 10:20:53 +00:00
{
2008-02-18 12:35:39 +01:00
my ( $ self , $ ctx , $ var ) = @ _ ;
2007-06-27 15:37:03 +00:00
my @ tmparr = ( ) ;
push ( @ tmparr , @ { $ ctx - > { $ var } } ) if defined ( $ ctx - > { $ var } ) ;
2004-05-13 10:20:53 +00:00
2007-06-27 15:37:03 +00:00
my $ tmplist = array2oneperline ( \ @ tmparr ) ;
2005-10-26 19:07:01 +00:00
return if ( $ tmplist eq "" ) ;
2004-05-13 10:20:53 +00:00
2008-02-14 12:03:34 +01:00
$ self - > output ( "$ctx->{NAME}_$var =$tmplist\n" ) ;
2004-05-13 10:20:53 +00:00
}
2008-02-13 21:03:01 +01:00
sub SharedModulePrimitives ($$)
{
my ( $ self , $ ctx ) = @ _ ;
#FIXME
}
2007-11-15 15:44:17 +01:00
sub SharedModule ($$)
2004-05-13 10:20:53 +00:00
{
2005-10-21 22:49:23 +00:00
my ( $ self , $ ctx ) = @ _ ;
2004-05-13 10:20:53 +00:00
2006-03-09 14:39:36 +00:00
my $ init_obj = "" ;
2007-10-05 19:51:29 +00:00
2007-11-15 15:44:17 +01:00
my $ sane_subsystem = lc ( $ ctx - > { SUBSYSTEM } ) ;
$ sane_subsystem =~ s/^lib// ;
2007-10-05 19:51:29 +00:00
2007-11-21 14:49:35 +01:00
if ( $ ctx - > { TYPE } eq "PYTHON" ) {
2008-02-16 17:18:23 +01:00
$ self - > output ( "PYTHON_DSOS += $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n" ) ;
2007-11-25 20:55:53 +01:00
} else {
2008-02-16 17:14:03 +01:00
$ self - > output ( "PLUGINS += $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n" ) ;
2008-02-16 16:22:05 +01:00
$ self - > output ( "installplugins:: $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n" ) ;
$ self - > output ( "\t\@echo Installing $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n" ) ;
$ self - > output ( "\t\@mkdir -p \$(DESTDIR)\$(modulesdir)/$sane_subsystem/\n" ) ;
$ self - > output ( "\t\@cp $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n" ) ;
2007-11-25 23:23:30 +01:00
if ( defined ( $ ctx - > { ALIASES } ) ) {
foreach ( @ { $ ctx - > { ALIASES } } ) {
2008-02-16 16:22:05 +01:00
$ self - > output ( "\t\@rm -f \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n" ) ;
$ self - > output ( "\t\@ln -fs $ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n" ) ;
}
}
$ self - > output ( "uninstallplugins::\n" ) ;
$ self - > output ( "\t\@echo Uninstalling \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n" ) ;
$ self - > output ( "\t\@-rm \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n" ) ;
if ( defined ( $ ctx - > { ALIASES } ) ) {
foreach ( @ { $ ctx - > { ALIASES } } ) {
$ self - > output ( "\t\@-rm \$(DESTDIR)\$(modulesdir)/$sane_subsystem/$_.\$(SHLIBEXT)\n" ) ;
2007-11-25 23:23:30 +01:00
}
2006-03-21 07:18:25 +00:00
}
2006-03-07 16:41:04 +00:00
}
2005-10-26 19:07:01 +00:00
2008-02-14 12:03:34 +01:00
$ self - > output ( "$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n" ) ;
2007-11-15 15:44:17 +01:00
$ self - > _prepare_list ( $ ctx , "FULL_OBJ_LIST" ) ;
2005-12-13 21:00:52 +00:00
$ self - > _prepare_list ( $ ctx , "DEPEND_LIST" ) ;
2007-06-27 17:48:30 +00:00
$ self - > _prepare_list ( $ ctx , "LINK_FLAGS" ) ;
2004-05-13 10:20:53 +00:00
2008-02-20 04:33:43 +01:00
if ( defined ( $ ctx - > { INIT_FUNCTION } ) and $ ctx - > { TYPE } ne "PYTHON" and
$ ctx - > { INIT_FUNCTION_TYPE } =~ /\(\*\)/ ) {
2006-03-09 14:39:36 +00:00
my $ init_fn = $ ctx - > { INIT_FUNCTION_TYPE } ;
$ init_fn =~ s/\(\*\)/init_module/ ;
my $ proto_fn = $ ctx - > { INIT_FUNCTION_TYPE } ;
$ proto_fn =~ s/\(\*\)/$ctx->{INIT_FUNCTION}/ ;
$ self - > output ( << "__EOD__"
2006-11-06 17:28:27 +00:00
bin / $ ctx - > { NAME } _init_module . c:
2006-03-09 14:39:36 +00:00
\ @ echo Creating \ $\ @
\ @ echo \ " #include \\\"includes.h\\\"\" > \$\@
\ @ echo \ " $ proto_fn ; \ " >> \ $\ @
2007-11-09 10:26:32 +01:00
\ @ echo \ " _PUBLIC_ $ init_fn \ " >> \ $\ @
\ @ echo \ " { \ " >> \ $\ @
\ @ echo \ " return $ ctx - > { INIT_FUNCTION } ( ) ; \ " >> \ $\ @
\ @ echo \ " } \ " >> \ $\ @
\ @ echo \ " \ " >> \ $\ @
2006-03-09 14:39:36 +00:00
__EOD__
) ;
2006-11-06 17:28:27 +00:00
$ init_obj = "bin/$ctx->{NAME}_init_module.o" ;
2006-03-09 14:39:36 +00:00
}
2007-11-15 15:44:17 +01:00
$ self - > output ( << "__EOD__"
#
2008-02-14 12:03:34 +01:00
$ ctx - > { SHAREDDIR } / $ ctx - > { LIBRARY_REALNAME } : \ $( $ ctx - > { NAME } _DEPEND_LIST ) \ $( $ ctx - > { NAME } _FULL_OBJ_LIST ) $ init_obj
2007-11-15 15:44:17 +01:00
\ @ echo Linking \ $\ @
\ @ mkdir - p $ ctx - > { SHAREDDIR }
2008-02-20 19:20:13 +11:00
\ @ \ $ ( MDLD ) \ $ ( LDFLAGS ) \ $ ( MDLD_FLAGS ) \ $ ( INTERN_LDFLAGS ) - o \ $\ @ \ $ ( INSTALL_LINK_FLAGS ) \ \
2008-02-14 12:03:34 +01:00
\ $( $ ctx - > { NAME } \ _FULL_OBJ_LIST ) $ init_obj \ \
\ $( $ ctx - > { NAME } _LINK_FLAGS )
2007-11-15 15:44:17 +01:00
__EOD__
) ;
if ( defined ( $ ctx - > { ALIASES } ) ) {
foreach ( @ { $ ctx - > { ALIASES } } ) {
$ self - > output ( "\t\@rm -f $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n" ) ;
$ self - > output ( "\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n" ) ;
}
}
$ self - > output ( "\n" ) ;
}
2008-02-13 21:03:01 +01:00
sub SharedLibraryPrimitives ($$)
2007-11-15 15:44:17 +01:00
{
my ( $ self , $ ctx ) = @ _ ;
2008-02-13 18:59:57 +01:00
$ self - > output ( "$ctx->{NAME}_SOVERSION = $ctx->{SO_VERSION}\n" ) if ( defined ( $ ctx - > { SO_VERSION } ) ) ;
$ self - > output ( "$ctx->{NAME}_VERSION = $ctx->{VERSION}\n" ) if ( defined ( $ ctx - > { VERSION } ) ) ;
2008-02-13 21:03:01 +01:00
if ( not grep ( /STATIC_LIBRARY/ , @ { $ ctx - > { OUTPUT_TYPE } } ) ) {
2008-02-14 12:03:34 +01:00
$ self - > output ( "$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n" ) ;
2007-11-15 15:44:17 +01:00
$ self - > _prepare_list ( $ ctx , "FULL_OBJ_LIST" ) ;
}
2008-02-13 21:03:01 +01:00
}
sub SharedLibrary ($$)
{
my ( $ self , $ ctx ) = @ _ ;
2008-04-13 14:09:09 -07:00
if ( ! defined ( $ ctx - > { LIBRARY_SONAME } ) ) {
$ ctx - > { LIBRARY_SONAME } = "" ;
}
2008-02-16 16:58:26 +01:00
$ self - > output ( "SHARED_LIBS += $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}\n" ) if ( defined ( $ ctx - > { SO_VERSION } ) ) ;
2008-02-13 21:03:01 +01:00
2007-11-15 15:44:17 +01:00
$ self - > _prepare_list ( $ ctx , "DEPEND_LIST" ) ;
$ self - > _prepare_list ( $ ctx , "LINK_FLAGS" ) ;
2006-03-07 14:00:57 +00:00
$ self - > output ( << "__EOD__"
2008-02-18 15:31:15 +01:00
$ ctx - > { RESULT_SHARED_LIBRARY } : \ $( $ ctx - > { NAME } _DEPEND_LIST ) \ $( $ ctx - > { NAME } _FULL_OBJ_LIST )
2006-03-07 14:00:57 +00:00
\ @ echo Linking \ $\ @
2008-02-29 14:32:37 +01:00
\ @ mkdir - p \ $( \ @ D )
2008-02-20 19:20:13 +11:00
\ @ \ $ ( SHLD ) \ $ ( LDFLAGS ) \ $ ( SHLD_FLAGS ) \ $ ( INTERN_LDFLAGS ) - o \ $\ @ \ $ ( INSTALL_LINK_FLAGS ) \ \
2008-02-14 12:03:34 +01:00
\ $( $ ctx - > { NAME } \ _FULL_OBJ_LIST ) \ \
\ $( $ ctx - > { NAME } _LINK_FLAGS ) \ \
2008-02-16 20:24:47 +01:00
\ $ ( if \ $ ( SONAMEFLAG ) , \ $ ( SONAMEFLAG ) $ ctx - > { LIBRARY_SONAME } )
2006-03-07 14:00:57 +00:00
__EOD__
) ;
2008-02-16 20:24:47 +01:00
if ( $ ctx - > { LIBRARY_REALNAME } ne $ ctx - > { LIBRARY_SONAME } ) {
$ self - > output ( "\t\@test \$($ctx->{NAME}_VERSION) = \$($ctx->{NAME}_SOVERSION) || ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}\n" ) ;
}
$ self - > output ( "ifdef $ctx->{NAME}_SOVERSION\n" ) ;
$ self - > output ( "\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}\n" ) ;
$ self - > output ( "endif\n" ) ;
2004-05-13 10:20:53 +00:00
}
2008-02-16 20:38:21 +01:00
sub MergedObj ($$)
{
my ( $ self , $ ctx ) = @ _ ;
2008-02-18 18:55:37 +01:00
return unless defined ( $ ctx - > { OUTPUT } ) ;
2008-02-16 20:56:46 +01:00
$ self - > output ( "$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n" ) ;
2008-02-16 20:38:21 +01:00
$ self - > output ( << "__EOD__"
#
2008-02-18 18:55:37 +01:00
$ ctx - > { RESULT_MERGED_OBJ } : \ $( $ ctx - > { NAME } _OBJ_LIST )
2008-02-16 20:38:21 +01:00
\ @ echo Partially linking \ $@
2008-02-29 14:32:37 +01:00
\ @ mkdir - p \ $( \ @ D )
2008-02-18 18:55:37 +01:00
\ $ ( PARTLINK ) - o \ $@ \ $( $ ctx - > { NAME } _OBJ_LIST )
2008-02-16 20:38:21 +01:00
__EOD__
) ;
}
2005-10-26 19:07:01 +00:00
sub StaticLibrary ($$)
2004-05-13 10:20:53 +00:00
{
2005-10-21 22:49:23 +00:00
my ( $ self , $ ctx ) = @ _ ;
2004-05-13 10:20:53 +00:00
2006-04-29 11:32:54 +00:00
return unless ( defined ( $ ctx - > { OBJ_FILES } ) ) ;
2008-02-16 16:58:26 +01:00
$ self - > output ( "STATIC_LIBS += $ctx->{TARGET_STATIC_LIBRARY}\n" ) if ( $ ctx - > { TYPE } eq "LIBRARY" ) ;
2005-10-26 19:07:01 +00:00
2008-02-14 12:03:34 +01:00
$ self - > output ( "$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n" ) ;
2006-04-27 19:50:13 +00:00
$ self - > _prepare_list ( $ ctx , "FULL_OBJ_LIST" ) ;
2005-10-26 23:36:04 +00:00
2008-02-26 14:20:31 +01:00
$ self - > output ( "$ctx->{RESULT_STATIC_LIBRARY}: \$($ctx->{NAME}_FULL_OBJ_LIST)\n" ) ;
2004-05-13 10:20:53 +00:00
}
2005-10-26 19:07:01 +00:00
sub Binary ($$)
2004-05-13 10:20:53 +00:00
{
2005-10-21 22:49:23 +00:00
my ( $ self , $ ctx ) = @ _ ;
2004-05-13 10:20:53 +00:00
2005-10-26 19:07:01 +00:00
unless ( defined ( $ ctx - > { INSTALLDIR } ) ) {
} elsif ( $ ctx - > { INSTALLDIR } eq "SBINDIR" ) {
2008-02-29 13:58:20 +01:00
$ self - > output ( "SBIN_PROGS += bin/$ctx->{BINARY}\n" ) ;
2005-10-26 19:07:01 +00:00
} elsif ( $ ctx - > { INSTALLDIR } eq "BINDIR" ) {
2008-02-29 13:58:20 +01:00
$ self - > output ( "BIN_PROGS += bin/$ctx->{BINARY}\n" ) ;
2005-10-26 19:07:01 +00:00
}
2008-02-18 15:31:15 +01:00
$ self - > output ( "binaries:: $ctx->{TARGET_BINARY}\n" ) ;
2005-12-15 15:59:10 +00:00
2006-04-27 19:50:13 +00:00
$ self - > _prepare_list ( $ ctx , "FULL_OBJ_LIST" ) ;
2005-12-13 21:00:52 +00:00
$ self - > _prepare_list ( $ ctx , "DEPEND_LIST" ) ;
$ self - > _prepare_list ( $ ctx , "LINK_FLAGS" ) ;
2004-05-13 10:20:53 +00:00
2005-12-15 15:59:10 +00:00
$ self - > output ( << "__EOD__"
2008-02-18 15:31:15 +01:00
$ ctx - > { RESULT_BINARY } : \ $( $ ctx - > { NAME } _DEPEND_LIST ) \ $( $ ctx - > { NAME } _FULL_OBJ_LIST )
2005-12-15 15:59:10 +00:00
\ @ echo Linking \ $\ @
2007-04-02 17:23:23 +00:00
__EOD__
) ;
2007-04-02 18:14:27 +00:00
if ( defined ( $ ctx - > { USE_HOSTCC } ) && $ ctx - > { USE_HOSTCC } eq "YES" ) {
2007-04-02 17:23:23 +00:00
$ self - > output ( << "__EOD__"
2008-02-13 21:03:01 +01:00
\ @ \ $ ( HOSTLD ) \ $ ( HOSTLD_FLAGS ) - L \ $ { builddir } /bin/s tatic - o \ $\ @ \ $ ( INSTALL_LINK_FLAGS ) \ \
2008-02-14 12:03:34 +01:00
\ $\ ( $ ctx - > { NAME } _LINK_FLAGS )
2007-04-02 17:23:23 +00:00
__EOD__
) ;
} else {
$ self - > output ( << "__EOD__"
2008-02-13 21:03:01 +01:00
\ @ \ $ ( BNLD ) \ $ ( BNLD_FLAGS ) \ $ ( INTERN_LDFLAGS ) - o \ $\ @ \ $ ( INSTALL_LINK_FLAGS ) \ \
2008-02-14 12:03:34 +01:00
\ $\ ( $ ctx - > { NAME } _LINK_FLAGS )
2005-04-02 01:43:54 +00:00
__EOD__
2007-04-02 17:23:23 +00:00
) ;
}
2004-05-13 10:20:53 +00:00
}
2007-11-21 11:10:45 +01:00
sub PythonFiles ($$)
{
my ( $ self , $ ctx ) = @ _ ;
foreach ( @ { $ ctx - > { PYTHON_FILES } } ) {
my $ target = "bin/python/" . basename ( $ _ ) ;
2007-12-04 14:20:46 +01:00
my $ source = output:: add_dir_str ( $ ctx - > { BASEDIR } , $ _ ) ;
2008-02-16 16:15:21 +01:00
$ self - > output ( "$target: $source\n\n" ) ;
2008-02-16 17:18:23 +01:00
$ self - > output ( "PYTHON_PYS += $target\n" ) ;
2007-12-04 14:20:46 +01:00
}
2007-11-21 11:10:45 +01:00
}
2005-10-26 23:36:04 +00:00
sub ProtoHeader ($$)
{
my ( $ self , $ ctx ) = @ _ ;
2008-02-29 14:43:54 +01:00
my $ priv = output:: add_dir_str ( $ ctx - > { BASEDIR } , $ ctx - > { PRIVATE_PROTO_HEADER } ) ;
$ self - > output ( "PROTO_HEADERS += $priv\n" ) ;
2005-12-27 20:29:19 +00:00
2008-02-29 14:43:54 +01:00
$ self - > output ( "$priv: $ctx->{MK_FILE} \$($ctx->{NAME}_OBJ_LIST:.o=.c) \$(srcdir)/script/mkproto.pl\n" ) ;
$ self - > output ( "\t\@echo \"Creating \$@\"\n" ) ;
$ self - > output ( "\t\@mkdir -p \$(\@D)\n" ) ;
2008-04-02 00:01:04 +02:00
$ self - > output ( "\t\@\$(PERL) \$(srcdir)/script/mkproto.pl --srcdir=\$(srcdir) --builddir=\$(builddir) --public=/dev/null --private=\$@ \$($ctx->{NAME}_OBJ_LIST)\n\n" ) ;
2005-10-26 23:36:04 +00:00
}
2005-10-26 19:07:01 +00:00
sub write ($$)
2004-05-13 10:20:53 +00:00
{
2008-02-13 21:03:01 +01:00
my ( $ self , $ file ) = @ _ ;
2004-05-13 10:20:53 +00:00
2005-12-23 13:02:52 +00:00
$ self - > output ( "ALL_OBJS = " . array2oneperline ( $ self - > { all_objs } ) . "\n" ) ;
2005-10-26 23:36:04 +00:00
$ self - > _prepare_mk_files ( ) ;
2006-03-18 23:31:40 +00:00
$ self - > output ( $ self - > { mkfile } ) ;
2005-09-17 13:08:49 +00:00
open ( MAKEFILE , ">$file" ) || die ( "Can't open $file\n" ) ;
2005-10-21 21:43:39 +00:00
print MAKEFILE $ self - > { output } ;
2005-09-17 13:08:49 +00:00
close ( MAKEFILE ) ;
2004-05-13 10:20:53 +00:00
2005-10-26 20:06:26 +00:00
print __FILE__ . ": creating $file\n" ;
2004-05-13 10:20:53 +00:00
}
2004-11-12 01:40:02 +00:00
2008-02-25 18:29:04 +01:00
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 - > { OBJ_LIST } ) ;
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 ;
$ dir =~ s #^\$\((?:src|build)dir\)/?##;
push ( @ cflags , "-I$builddir/$dir" , "-I$srcdir/$dir" ) ;
next ;
}
}
push ( @ cflags , $ flag ) ;
}
my $ cflags = join ( ' ' , @ cflags ) ;
2008-03-04 10:47:40 +01:00
$ self - > output ( "\$(patsubst %.ho,%.d,\$($key->{NAME}_OBJ_LIST:.o=.d)) \$($key->{NAME}_OBJ_LIST): CFLAGS+= $cflags\n" ) ;
2008-02-25 18:29:04 +01:00
}
2004-11-12 01:40:02 +00:00
1 ;