From: <sg...@us...> - 2007-10-21 01:13:10
|
Revision: 103 http://toc.svn.sourceforge.net/toc/?rev=103&view=rev Author: sgbeal Date: 2007-10-20 18:13:14 -0700 (Sat, 20 Oct 2007) Log Message: ----------- egg Added Paths: ----------- trunk/examples/swig/ trunk/examples/swig/GNUmakefile trunk/examples/swig/SomeModule.c trunk/examples/swig/SomeModule.h trunk/examples/swig/SomeModule.i trunk/examples/swig/dl_local.inc.php trunk/examples/swig/test.php trunk/examples/swig/toc2.make Added: trunk/examples/swig/GNUmakefile =================================================================== --- trunk/examples/swig/GNUmakefile (rev 0) +++ trunk/examples/swig/GNUmakefile 2007-10-21 01:13:14 UTC (rev 103) @@ -0,0 +1,34 @@ +#!/usr/bin/make -f +# Demonstration of using the toc2 doxygen helper... +include toc2.make + + +SWIG-PHP5-CPP.RULES_GENERATOR := $(toc2.dirs.makefiles)/makerules.swig-php5-cpp +SWIG-PHP5-CPP.DEPSFILE := .toc2.swig-php5-cpp.d +$(SWIG-PHP5-CPP.DEPSFILE): $(SWIG-PHP5-CPP.RULES_GENERATOR) $(toc2.files.makefile) + $(call toc2.call.generate-rules,swig-php5-cpp,SomeModule) > $@ +SomeModule.SWIG.PHP5-CPP.OBJECTS += SomeModule.o +-include $(SWIG-PHP5-CPP.DEPSFILE) + + +SWIG-PYTHON-CPP.RULES_GENERATOR := $(toc2.dirs.makefiles)/makerules.swig-python-cpp +SWIG-PYTHON-CPP.DEPSFILE := .toc2.swig-python-cpp.d +$(SWIG-PYTHON-CPP.DEPSFILE): $(SWIG-PYTHON-CPP.RULES_GENERATOR) $(toc2.files.makefile) + $(call toc2.call.generate-rules,swig-python-cpp,SomeModule) > $@ +SomeModule.SWIG.PYTHON-CPP.OBJECTS += SomeModule.o +-include $(SWIG-PYTHON-CPP.DEPSFILE) + + +all: swig-modules + +#include toc2-swig.make +#$(call toc2.call.define-swig-module,SomeModule) +#toc2.swig.SomeModule.args += -php5 -c++ +#package.clean_files += SomeModule.php php_SomeModule.h + +#$(toc2.swig.SomeModule_wrap.o): CPPFLAGS:=$(shell php-config5 --includes) +#SomeModule.DLL.OBJECTS := SomeModule.o $(toc2.swig.SomeModule_wrap.o) +#include $(toc2.dirs.makefiles)/toc2-c.make +#$(call toc2.call.rules.c-dll,SomeModule) +#all: swig-modules SomeModule.DLL + Added: trunk/examples/swig/SomeModule.c =================================================================== --- trunk/examples/swig/SomeModule.c (rev 0) +++ trunk/examples/swig/SomeModule.c 2007-10-21 01:13:14 UTC (rev 103) @@ -0,0 +1,19 @@ +#include "SomeModule.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int smod_func1( int a, int b ) +{ + return a + b; +} + +double smod_func2( double a, double b ) +{ + return a + b; +} + +#ifdef __cplusplus +} +#endif Added: trunk/examples/swig/SomeModule.h =================================================================== --- trunk/examples/swig/SomeModule.h (rev 0) +++ trunk/examples/swig/SomeModule.h 2007-10-21 01:13:14 UTC (rev 103) @@ -0,0 +1,13 @@ +#ifndef SOME_MODULE_H +#define SOME_MODULE_H 1 + +#ifdef __cplusplus +extern "C" { +#endif +int smod_func1( int, int ); +double smod_func2( double, double ); +#ifdef __cplusplus +} +#endif + +#endif // SOME_MODULE_H Added: trunk/examples/swig/SomeModule.i =================================================================== --- trunk/examples/swig/SomeModule.i (rev 0) +++ trunk/examples/swig/SomeModule.i 2007-10-21 01:13:14 UTC (rev 103) @@ -0,0 +1,6 @@ + +%{ +#include "SomeModule.h" +%} + +%include "SomeModule.h" Added: trunk/examples/swig/dl_local.inc.php =================================================================== --- trunk/examples/swig/dl_local.inc.php (rev 0) +++ trunk/examples/swig/dl_local.inc.php 2007-10-21 01:13:14 UTC (rev 103) @@ -0,0 +1,75 @@ +<?php +/* + Function: dl_local() + Reference: http://us2.php.net/manual/en/function.dl.php + Author: Brendon Crawford <endofyourself |AT| yahoo> + Usage: dl_local( "mylib.so" ); + Returns: Extension Name (NOT the extension filename however) + NOTE: + This function can be used when you need to load a PHP extension (module,shared object,etc..), + but you do not have sufficient privelages to place the extension in the proper directory where it can be loaded. This function + will load the extension from the CURRENT WORKING DIRECTORY only. + If you need to see which functions are available within a certain extension, + use "get_extension_funcs()". Documentation for this can be found at + "http://us2.php.net/manual/en/function.get-extension-funcs.php". +*/ + +function dl_local( $extensionFile ) { + //make sure that we are ABLE to load libraries + if( !(bool)ini_get( "enable_dl" ) || (bool)ini_get( "safe_mode" ) ) { + throw new Exception("dh_local(): Loading extensions is not permitted." ); + } + + //check to make sure the file exists + if( !file_exists( $extensionFile ) ) { + throw new Exception( "dl_local(): File '$extensionFile' does not exist." ); + } + + //check the file permissions + if( !is_executable( $extensionFile ) ) { + throw new Exception( "dl_local(): File '$extensionFile' is not executable." ); + } + + //we figure out the path + $currentDir = getcwd() . "/"; + $currentExtPath = ini_get( "extension_dir" ); + $subDirs = preg_match_all( "/\//" , $currentExtPath , $matches ); + unset( $matches ); + + //lets make sure we extracted a valid extension path + if( !(bool)$subDirs ) { + throw new Exception( "dl_local(): Could not determine a valid extension path [extension_dir]." ); + } + + $extPathLastChar = strlen( $currentExtPath ) - 1; + + if( $extPathLastChar == strrpos( $currentExtPath , "/" ) ) { + $subDirs--; + } + + $backDirStr = ""; + for( $i = 1; $i <= $subDirs; $i++ ) { + $backDirStr .= ".."; + if( $i != $subDirs ) { + $backDirStr .= "/"; + } + } + + //construct the final path to load + $finalExtPath = $backDirStr . $currentDir . $extensionFile; + + //now we execute dl() to actually load the module + if( !dl( $finalExtPath ) ) { + throw new Exception("dl({$finalExtPath}) failed"); + } + + //if the module was loaded correctly, we must bow grab the module name + $loadedExtensions = get_loaded_extensions(); + $thisExtName = $loadedExtensions[ sizeof( $loadedExtensions ) - 1 ]; + + //lastly, we return the extension name + return $thisExtName; + +}//end dl_local() + +?> Added: trunk/examples/swig/test.php =================================================================== --- trunk/examples/swig/test.php (rev 0) +++ trunk/examples/swig/test.php 2007-10-21 01:13:14 UTC (rev 103) @@ -0,0 +1,12 @@ +<?php + +require("dl_local.inc.php"); +assert( dl_local("SomeModule.so") ); +require("SomeModule.php"); + +echo smod_func1(1,2)."\n"; +echo smod_func2(1,2)."\n"; + +echo "Bye!\n"; +exit(0); +?> Added: trunk/examples/swig/toc2.make =================================================================== --- trunk/examples/swig/toc2.make (rev 0) +++ trunk/examples/swig/toc2.make 2007-10-21 01:13:14 UTC (rev 103) @@ -0,0 +1,149 @@ +#!/do/not/make +######################################################################## +# toc2.make.at: template makefile for toc2.make, a core concept of the +# toc2 build process. This is filtered at the end of the configure +# process. toc2.make must be included by your Makefiles, like so: +# +# include toc2.make +# +# Each makefile which does that will get a toc2.make created during +# the configure process. Each toc2.make is specific to that sub-dir +# (more specifically, each subdir at the same depth gets the same +# toc2.make). +# +# All of the "at-vars" in this file are expected to come in +# via the configure process, either from core tests or from +# the core itself. +# +# Ideally this file should be free of project-specific code: +# put that in $(toc2.top_srcdir)/toc2.$(package.name).make.at and +# in then $(toc2.top_srcdir)/configure.$(package.name) run: +# toc_test_require toc2_project_makefile +######################################################################## +default: all +all: +FORCE: ; @true + +######################################################################## +# $(package.name) and $(package.version) are the penultimate +# variables, holding the package name and version. They must not +# contain spaces, and some characters may confuse other tools. Most +# notable, a '+' in the name is likely to break the makedist tool. +package.version = 20071020 +package.name = toc2 + +######################################################################## +# $(SHELL) must be BASH, but the path might be system-specific. +SHELL = /bin/bash +##### prefix and DESTDIR are for autotools 'make install' compatibility +prefix ?= /usr/local +DESTDIR ?= + +ifneq (,$(COMSPEC)) +$(warning Smells like Windows!) +toc2.flags.smells_like_windows := 1 +toc2.platform.file_extensions.dll = .DLL# maintenance reminder: this must stay upper-case! +toc2.platform.file_extensions.lib = .a# yes, use .a for cygwin +toc2.platform.file_extensions.exe = .EXE# maintenance reminder: this must stay upper-case! +else +toc2.flags.smells_like_windows := 0 +toc2.platform.file_extensions.dll = .so +toc2.platform.file_extensions.lib = .a +toc2.platform.file_extensions.exe =# no whitespace, please +endif + +toc2.files.makefile := $(word 1,$(MAKEFILE_LIST))# accommodate Makefile/GNUmakefile +$(toc2.files.makefile): + +######################################################################## +# $(toc2.flags.quiet) is used by some toc2 code to enable/disable +# verbose output. Set it to 1 to enable it, or any other value to +# disable it. +toc2.flags.quiet ?= $(if @TOC2_BUILD_QUIETLY@,@TOC2_BUILD_QUIETLY@,0) + +toc2.top_srcdir = ../.. + +##### include configure-created code: +toc2.makefile.config_vars = $(toc2.top_srcdir)/toc2.$(package.name).configure.make +$(toc2.makefile.config_vars):# created by configure process +include $(toc2.makefile.config_vars) + + +toc2.project_makefile = $(wildcard $(toc2.top_srcdir)/toc2.$(package.name).make) +toc2.project_makefile_at = $(wildcard $(toc2.top_srcdir)/toc2.$(package.name).make.at) + +toc2.home ?= /home/stephan/cvs/toc2/toc2 +# todo: check if this is under $(toc2.top_srcdir), so we can make this path relative. + +toc2.dirs.makefiles = $(toc2.home)/make +toc2.dirs.bin = $(toc2.home)/bin +toc2.dirs.sbin = $(toc2.home)/sbin +toc2.dirs.relative_to_top = examples/swig +# e.g., in lib/foo, toc2.dirs.relative_to_top == lib/foo + +toc2.make = toc2.make +# deprecated TOP_toc2.make = $(toc2.top_srcdir)/$(toc2.make) + +##### some core utilities: +toc2.bins.awk = /usr/bin/awk +toc2.bins.perl = /usr/bin/perl +toc2.bins.sed = /bin/sed +toc2.bins.tar = /bin/tar +toc2.bins.gzip = /bin/gzip +toc2.bins.bzip = /bin/bzip2 +toc2.bins.zip = /usr/bin/zip +toc2.bins.ar = $(AR) +toc2.bins.installer = /home/stephan/cvs/toc2/toc2/bin/install-sh +toc2.bins.makedist = /home/stephan/cvs/toc2/toc2/bin/makedist + + +# The emoticons are now exported directly by toc2_core.sh to toc2.PACKAGE.configure.make: +# toc2.emoticons.okay=[1m:-)[m +# toc2.emoticons.warning=[1m:-O[m +# toc2.emoticons.error=[1m:-([m +# toc2.emoticons.grief=@TOC2_EMOTICON_GRIEF@ +# toc2.emoticons.wtf=@TOC2_EMOTICON_WTF@ + +toc2.clean_files += $(wildcard .toc2.* core *~) +toc2.distclean_files += $(toc2.make) + +ifeq (.,$(toc2.top_srcdir)) + toc2.distclean_files += \ + toc2.$(package.name).make \ + toc2.$(package.name).configure.make +endif + + +include $(toc2.dirs.makefiles)/toc2-functions-core.make +include $(toc2.dirs.makefiles)/toc2-subdirs.make +include $(toc2.dirs.makefiles)/toc2-cleanup.make +include $(toc2.dirs.makefiles)/toc2-install.make +include $(toc2.dirs.makefiles)/toc2-dist.make + +######################################################################## +# A kludge to get mkdep-toc2 deleted at a proper time... only if we're +# in the top-most dir and mkdep-toc2 exists... +# This code *should* be in toc2-c.make, but that file is not globally +# included. +toc2.bins.mkdep.c := $(wildcard $(toc2.home)/bin/mkdep-toc2.c) +toc2.bins.mkdep := $(if $(toc2.bins.mkdep.c),$(toc2.top_srcdir)/$(basename $(notdir $(toc2.bins.mkdep.c))),) +######################################################################## +# Set toc2.bins.mkdep.flags to whatever -I flags you want to use for +# $(toc2.bins.mkdep). Any non-I flags are ignored by mkdep. +toc2.bins.mkdep.flags += $(INCLUDES) $(CPPFLAGS) +ifeq (.,$(toc2.top_srcdir)) + .PHONY: distclean-mkdep-toc2 + distclean-mkdep-toc2: + @test "x." = "x$(toc2.top_srcdir)" -a \ + x != 'x$(toc2.bins.mkdep)' -a \ + -e "$(toc2.bins.mkdep)" || exit 0; \ + rm -f "$(toc2.bins.mkdep)" + distclean-.: distclean-mkdep-toc2 +endif + +######################################################################## +# finally, load the project-specific code: +ifneq (,$(toc2.project_makefile)) + include $(toc2.project_makefile) +endif + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |