]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add fsxs script for building out of tree modules. Thanks stkn.
authorMichael Jerris <mike@jerris.com>
Wed, 5 Jul 2006 14:40:28 +0000 (14:40 +0000)
committerMichael Jerris <mike@jerris.com>
Wed, 5 Jul 2006 14:40:28 +0000 (14:40 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1755 d0543943-73ff-0310-b7d9-9358b9ac24b2

Makefile.am
fsxs.in [new file with mode: 0755]

index 0e339478219bb7abe8bff8e24e9e075aeb66852e..46bbae02d002449e75a37b4ec944a59e52d37393 100644 (file)
@@ -1,3 +1,5 @@
+
+
 EXTRA_DIST =
 SUBDIRS = 
 AUTOMAKE_OPTS = gnu foreign
@@ -122,7 +124,7 @@ src/include/switch_log.h\
 src/include/switch_xml.h
 
 BUILT_SOURCES = version depends
-CLEANFILES = src/include/switch_version.h
+CLEANFILES = src/include/switch_version.h fsxs
 
 
 lib_LTLIBRARIES                = libfreeswitch.la
@@ -132,6 +134,7 @@ libfreeswitch_la_LIBADD  = -lteletone -lresample -lsrtp -lsqlite3 -lspeakup
 nodist_libfreeswitch_la_SOURCES = src/include/switch_version.h
 
 bin_PROGRAMS = freeswitch
+bin_SCRIPTS = fsxs
 freeswitch_SOURCES =   src/switch.c\
                        src/include/switch_version.h
 freeswitch_CFLAGS = $(AM_CFLAGS)
@@ -231,6 +234,27 @@ install_mod: modules
 dox:
        cd docs && doxygen $(PWD)/docs/Doxygen.conf
 
+fsxs: fsxs.in
+       @echo creating fsxs
+       @sed -e "s,@MODULES_DIR\@,$(PREFIX)/mod," \
+           -e "s,@LIB_DIR\@,$(PREFIX)/lib," \
+           -e "s,@BIN_DIR\@,$(PREFIX)/bin," \
+           -e "s,@INC_DIR\@,$(PREFIX)/include," \
+           -e "s,@CFG_DIR\@,$(PREFIX)/conf," \
+           -e "s,@DB_DIR\@,$(PREFIX)/db," \
+           -e "s,@PREFIX\@,$(PREFIX)," \
+           -e "s,@CC\@,$(CC)," \
+           -e "s,@LD\@,$(CC)," \
+           -e "s,@INSTALL\@,$(INSTALL)," \
+           -e "s,@MKINSTALLDIRS\@,$(mkdir_p)," \
+           \
+           -e "s|@CFLAGS\@|$(CFLAGS) -fPIC $(shell $(APR_CONFIG) --cflags --cppflags)|" \
+           -e "s|@INCLUDES\@|-I$(PREFIX)/include $(shell $(APR_CONFIG) --includes) $(shell $(APU_CONFIG) --includes)|" \
+           -e "s|@SOLINK\@|$(SOLINK)|" \
+           -e "s|@LDFLAGS\@|-L$(PREFIX)/lib|" \
+           -e "s|@LIBS\@|-lfreeswitch|" \
+           fsxs.in > fsxs
+
 eclean: clean
        rm -f `find . -type f -name \*~`
        rm -f `find . -type f -name \.*~`
diff --git a/fsxs.in b/fsxs.in
new file mode 100755 (executable)
index 0000000..805c48a
--- /dev/null
+++ b/fsxs.in
@@ -0,0 +1,282 @@
+#!/usr/bin/perl
+#
+# FreeSwitch fsxs
+#
+# (C) 2006 Stefan Knoblich <stkn@netdomination.org>
+
+use strict;
+
+#
+# @FOO@ will be replaced by the freeswitch build process
+#
+my %vars = (
+       CC => '@CC@',
+       LD => '@LD@',
+       MKDIR => '@MKINSTALLDIRS@',
+       INSTALL => '@INSTALL@',
+       LIBS => '@LIBS@',
+       CFLAGS => '@CFLAGS@',
+       INCLUDES => '@INCLUDES@',
+       LDFLAGS => '@LDFLAGS@',
+       SOLINK => '@SOLINK@',
+
+       MODULES_DIR => '@MODULES_DIR@',
+       LIB_DIR => '@LIB_DIR@',
+       BIN_DIR => '@BIN_DIR@',
+       INC_DIR => '@INC_DIR@',
+       DB_DIR => '@DB_DIR@',
+       CFG_DIR => '@CFG_DIR@',
+       PREFIX => '@PREFIX@'
+);
+
+#
+# Misc variables
+#
+my @files = ();
+
+my $command;
+my $target;
+
+my $needs_target = 1;
+my $debug = 0;
+
+#
+# functions 
+#
+
+sub do_exec {
+       my $retval = system( "@_ >/dev/null" );
+       if( $retval ) {
+               exit $retval;
+       }
+}
+
+sub fsxs_usage {
+       print "FreeSwitch fsxs\n(C) 2006 Stefan Knoblich <stkn\@netdomination.org>\n";
+       print "\n";
+       print "Usage:\n";
+       print "\t$0 compile [options] <file1 ...>\n";
+       print "\t$0 link    [options] <target> <file1 ...>\n";
+       print "\t$0 build   [options] <target> <file1 ...>\n";
+       print "\t$0 install [options] <file1 ...>\n";
+       print "\t$0 show    <var1 ...>\n\n";
+       print "Command description:\n";
+       print "\tcompile: Compile source file(s) into object file(s)\n";
+       print "\tlink:    Create module from object file(s)\n";
+       print "\tbuild:   Build module from source file(s) (compile + link)\n";
+       print "\tinstall: Install module(s) into freeswitch module directory\n";
+       print "\tshow:    Show defined variable(s)\n";
+       print "\n";
+
+       print "Options:\n";
+       print "\t--add-cflags  Append custom cflags   [compile, build]\n";
+       print "\t--set-cflags  Override cflags        [compile, build]\n";
+       print "\n";
+       print "\t--add-ldflags Append custom ldflags  [link, build]\n";
+       print "\t--set-ldflags Override ldflags       [link, build]\n";
+       print "\t--add-libs    Append additional libs [link, build]\n";
+       print "\t--set-libs    Override libs          [link, build]\n";
+       print "\n";
+       print "\t--destdir     Installation prefix    [install]\n";
+       print "\n";
+
+       print "Examples:\n";
+       print "\t$0 compile --add-cflags=\"-DFOO=1 -DBAR\" mod_test.c mod_test2.c\n\n";
+       print "\t$0 link --add-ldflags=\"-ltest\" mod_test.so mod_test.o mod_test2.o\n\n";
+       print "\t$0 build --add-cflags=\"-DFOO\" --add-ldflags=\"-ltest\" mod_test.so mod_test.c mod_test2.c\n\n";
+       exit 1;
+}
+
+sub fsxs_compile {
+       my $cc_cmd;
+
+       $cc_cmd = "$vars{CC}";
+       if( defined( $vars{INCLUDES} ) && $vars{INCLUDES} ) {
+               $cc_cmd = $cc_cmd . " $vars{INCLUDES}"
+       }
+       $cc_cmd = $cc_cmd . " $vars{CFLAGS} -c -o";
+
+       foreach( @_ ) {
+               chomp( $_ );
+
+               # replace file extension
+               my $outfile = $_;
+               $outfile =~ s/\.(cpp|cc|c)$/.o/;
+
+               print "CC\t$_\n";
+               if( $debug ) {
+                       print "$cc_cmd $outfile $_\n"
+               }
+               do_exec( "$cc_cmd $outfile $_" );
+       }
+}
+
+sub fsxs_link {
+       my $target = shift;
+       my @objs = @_;
+       my $ld_cmd;
+
+       $ld_cmd = "$vars{LD}";
+       $ld_cmd = $ld_cmd . " $vars{LDFLAGS} $vars{SOLINK} -o";
+
+       print "LD\t$target\t[@objs]\n";
+       if( $debug ) {
+               print "$ld_cmd $target @objs $vars{LIBS}\n"
+       }
+       do_exec( "$ld_cmd $target @objs $vars{LIBS}" );
+}
+
+sub fsxs_install {
+       my @files = @_;
+       my $destination = $vars{DESTDIR} . $vars{MODULES_DIR};
+
+       # check if destination exists, create if it doesn't
+       if( ! -e $destination ) {
+               if( $debug ) {
+                       print "$vars{MKDIR} $destination\n";
+               }
+               do_exec( "$vars{MKDIR} $destination" );
+       }
+       if( $debug ) {
+               print "$vars{INSTALL} -m644 @files $destination\n";
+       }
+       do_exec( "$vars{INSTALL} -m644 @files $destination" );
+}
+
+sub fsxs_show {
+       my @varlist = @_;
+
+       if( $#varlist < 0 ) {
+               # none requested, show all variables with names
+               my $key;
+               foreach $key ( keys %vars ) {
+                       print "$key: $vars{$key}\n";
+               }
+       }
+       elsif( $#varlist > 0 ) {
+               # more than one requested, show with name
+               foreach( @varlist ) {
+                       if( defined $vars{$_} ) {
+                               print "$_: $vars{$_}\n";
+                       }
+               }
+       } else {
+               # show only one variable, without name
+               if( defined $vars{$varlist[0]} ) {
+                       print "$vars{$varlist[0]}\n";
+               }
+       }
+}
+
+#
+# main part
+#
+if( $#ARGV < 0 ) {
+       fsxs_usage;
+}
+chomp( $command = shift @ARGV );
+
+if( $command =~ /^install|build|link|compile|show$/ ) {
+
+       if( $command =~ /^show|compile|install$/ ) {
+               $needs_target = 0;
+       }
+}
+else {
+       print STDERR "Unknown command: $command\n";
+       fsxs_usage;
+}
+
+# parse environment variables
+if( defined $ENV{DEBUG} && $ENV{DEBUG} ) {
+       $debug = 1;
+}
+
+# parse arguments
+foreach(@ARGV) {
+       chomp( $_ );
+
+       if( $command ne 'show' )
+       {
+               if( /^\--add-cflags=(.*)$/ ) {
+                       $vars{CFLAGS} = "$vars{CFLAGS} $1";
+               }
+               elsif( /^\--set-cflags=(.*)$/ ) {
+                       $vars{CFLAGS} = "$1";
+               }
+               elsif( /^\--add-ldflags=(.*)$/ ) {
+                       $vars{LDFLAGS} = "$vars{LDFLAGS} $1";
+               }
+               elsif( /^\--set-ldflags=(.*)$/ ) {
+                       $vars{LDFLAGS} = "$1";
+               }
+               elsif( /^\--add-libs=(.*)$/ ) {
+                       $vars{LIBS} = "$vars{LIBS} $1";
+               }
+               elsif( /^\--set-libs=(.*)$/ ) {
+                       $vars{LIBS} = "$1";
+               }
+               elsif( /^\--destdir=(.*)$/ ) {
+                       $vars{DESTDIR} = "$1";
+               }
+               elsif( /^\--debug$/ ) {
+                       $debug = 1;
+               }
+               elsif( /^(DESTDIR|CFLAGS|CC|LDFLAGS|LD|LIBS)=(.*)$/ ) {
+                       if( $debug ) {
+                               print "Overriding $1 (new value: $2)\n";
+                       }
+                       $vars{$1} = "$2";
+               }
+               elsif( /^([^\-]+.*)$/ ) {
+                       if( $needs_target ) {
+                               $target = "$1";
+                               $needs_target = 0;
+                       } else {
+                               push(@files, "$1");
+                       }
+               }
+       } else {
+               # show command has different parameter handling
+               if( /^\--(.*)$/ ) {
+                       push( @files, uc "$1" );
+               }
+               elsif( /^([^\-]+.*)$/ ) {
+                       push( @files, uc "$1" );
+               }
+       }
+}
+
+#
+# execute commands
+#
+if( $command eq 'link' ) {
+       fsxs_link( $target, @files );
+}
+elsif( $command eq 'compile' ) {
+       fsxs_compile( @files );
+}
+elsif( $command eq 'build' ) {
+       my @objs = ();
+
+       fsxs_compile( @files );
+
+       foreach( @files ) {
+               chomp( $_ );
+               $_ =~ s/\.(cpp|cc|c)$/.o/;
+               push( @objs, "$_" );
+       }
+
+       fsxs_link( $target, @objs );
+}
+elsif( $command eq 'show' ) {
+       fsxs_show( @files );
+}
+elsif( $command eq 'install' ) {
+       fsxs_install( @files );
+}
+else {
+       fsxs_usage;
+}
+
+exit 0;