summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-04-03 09:28:38 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-04-03 09:28:38 +0200
commite1dc57a131fe297882a9d6dbf2d20fc7be662123 (patch)
treef64ecd33a5bba9d82b939fe75fcf7cf8d55c71dc
parent3335c6c9aad6a276533a055f269c8ff12af0e4a7 (diff)
added DlUnrestricted example extension, modified makefiles to use php-config to find out the extension-dir
-rw-r--r--Examples/CallPhpFunctions/Makefile2
-rw-r--r--Examples/ConstStaticProp/cpp/Makefile2
-rw-r--r--Examples/DlUnrestricted/Makefile135
-rw-r--r--Examples/DlUnrestricted/dlunrestricted.cpp43
-rw-r--r--Examples/DlUnrestricted/dlunrestricted.ini4
-rw-r--r--Examples/DlUnrestricted/dlunrestricted.php13
-rw-r--r--Examples/Exceptions/ExceptionCatch/Makefile2
-rw-r--r--Examples/Exceptions/ExceptionThrow/Makefile2
-rw-r--r--Examples/Extension/Makefile2
-rw-r--r--Examples/FunctionNoParameters/Makefile2
-rw-r--r--Examples/FunctionReturnValue/Makefile2
-rw-r--r--Examples/FunctionVoid/Makefile2
-rw-r--r--Examples/FunctionWithParameters/Makefile2
-rw-r--r--Examples/Globals/Makefile2
14 files changed, 205 insertions, 10 deletions
diff --git a/Examples/CallPhpFunctions/Makefile b/Examples/CallPhpFunctions/Makefile
index 08312ba..cd9ee43 100644
--- a/Examples/CallPhpFunctions/Makefile
+++ b/Examples/CallPhpFunctions/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/ConstStaticProp/cpp/Makefile b/Examples/ConstStaticProp/cpp/Makefile
index 8272434..7e951b4 100644
--- a/Examples/ConstStaticProp/cpp/Makefile
+++ b/Examples/ConstStaticProp/cpp/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/DlUnrestricted/Makefile b/Examples/DlUnrestricted/Makefile
new file mode 100644
index 0000000..86cddfd
--- /dev/null
+++ b/Examples/DlUnrestricted/Makefile
@@ -0,0 +1,135 @@
+#
+# Makefile template
+#
+# This is an example Makefile that can be used by anyone who is building
+# his or her own PHP extensions using the PHP-CPP library.
+#
+# In the top part of this file we have included variables that can be
+# altered to fit your configuration, near the bottom the instructions and
+# dependencies for the compiler are defined. The deeper you get into this
+# file, the less likely it is that you will have to change anything in it.
+#
+
+#
+# Name of your extension
+#
+# This is the name of your extension. Based on this extension name, the
+# name of the library file (name.so) and the name of the config file (name.ini)
+# are automatically generated
+#
+
+NAME = dlunrestricted
+
+
+#
+# Php.ini directories
+#
+# In the past, PHP used a single php.ini configuration file. Today, most
+# PHP installations use a conf.d directory that holds a set of config files,
+# one for each extension. Use this variable to specify this directory.
+#
+
+INI_DIR = /etc/php5/mods-available
+
+
+#
+# The extension dirs
+#
+# This is normally a directory like /usr/lib/php5/20121221 (based on the
+# PHP version that you use. We make use of the command line 'php-config'
+# instruction to find out what the extension directory is, you can override
+# this with a different fixed directory
+#
+
+EXTENSION_DIR = $(shell php-config --extension-dir)
+
+
+#
+# The name of the extension and the name of the .ini file
+#
+# These two variables are based on the name of the extension. We simply add
+# a certain extension to them (.so or .ini)
+#
+
+EXTENSION = ${NAME}.so
+INI = ${NAME}.ini
+
+
+#
+# Compiler
+#
+# By default, the GNU C++ compiler is used. If you want to use a different
+# compiler, you can change that here. You can change this for both the
+# compiler (the program that turns the c++ files into object files) and for
+# the linker (the program that links all object files into the single .so
+# library file. By default, g++ (the GNU C++ compiler) is used for both.
+#
+
+COMPILER = g++
+LINKER = g++
+
+
+#
+# Compiler and linker flags
+#
+# This variable holds the flags that are passed to the compiler. By default,
+# we include the -O2 flag. This flag tells the compiler to optimize the code,
+# but it makes debugging more difficult. So if you're debugging your application,
+# you probably want to remove this -O2 flag. At the same time, you can then
+# add the -g flag to instruct the compiler to include debug information in
+# the library (but this will make the final libphpcpp.so file much bigger, so
+# you want to leave that flag out on production servers).
+#
+# If your extension depends on other libraries (and it does at least depend on
+# one: the PHP-CPP library), you should update the LINKER_DEPENDENCIES variable
+# with a list of all flags that should be passed to the linker.
+#
+
+COMPILER_FLAGS = -Wall -c -O2 -std=c++11 -fpic -o
+LINKER_FLAGS = -shared
+LINKER_DEPENDENCIES = -lphpcpp
+
+
+#
+# Command to remove files, copy files and create directories.
+#
+# I've never encountered a *nix environment in which these commands do not work.
+# So you can probably leave this as it is
+#
+
+RM = rm -f
+CP = cp -f
+MKDIR = mkdir -p
+
+
+#
+# All source files are simply all *.cpp files found in the current directory
+#
+# A builtin Makefile macro is used to scan the current directory and find
+# all source files. The object files are all compiled versions of the source
+# file, with the .cpp extension being replaced by .o.
+#
+
+SOURCES = $(wildcard *.cpp)
+OBJECTS = $(SOURCES:%.cpp=%.o)
+
+
+#
+# From here the build instructions start
+#
+
+all: ${OBJECTS} ${EXTENSION}
+
+${EXTENSION}: ${OBJECTS}
+ ${LINKER} ${LINKER_FLAGS} -o $@ ${OBJECTS} ${LINKER_DEPENDENCIES}
+
+${OBJECTS}:
+ ${COMPILER} ${COMPILER_FLAGS} $@ ${@:%.o=%.cpp}
+
+install:
+ ${CP} ${EXTENSION} ${EXTENSION_DIR}
+ ${CP} ${INI} ${INI_DIR}
+
+clean:
+ ${RM} ${EXTENSION} ${OBJECTS}
+
diff --git a/Examples/DlUnrestricted/dlunrestricted.cpp b/Examples/DlUnrestricted/dlunrestricted.cpp
new file mode 100644
index 0000000..91b7bb3
--- /dev/null
+++ b/Examples/DlUnrestricted/dlunrestricted.cpp
@@ -0,0 +1,43 @@
+/**
+ * functionvoid.cpp
+ * @author Jasper van Eck<jasper.vaneck@copernica.com>
+ *
+ * An example file to show the working of a void function call.
+ */
+
+/**
+ * Libraries used.
+ */
+#include <iostream>
+#include <phpcpp.h>
+
+/**
+ * Namespace to use
+ */
+using namespace std;
+
+/**
+ * my_function_void()
+ */
+void my_function_void()
+{
+ cout << "In my_function_void()" << endl;
+}
+
+
+// Symbols are exported according to the "C" language
+extern "C"
+{
+ // export the "get_module" function that will be called by the Zend engine
+ PHPCPP_EXPORT void *get_module()
+ {
+ // create extension
+ static Php::Extension extension("my_function_void","1.0");
+
+ // add function to extension
+ extension.add("my_void_function", my_function_void);
+
+ // return the extension module
+ return extension.module();
+ }
+}
diff --git a/Examples/DlUnrestricted/dlunrestricted.ini b/Examples/DlUnrestricted/dlunrestricted.ini
new file mode 100644
index 0000000..1cb5f03
--- /dev/null
+++ b/Examples/DlUnrestricted/dlunrestricted.ini
@@ -0,0 +1,4 @@
+; configuration for phpcpp module
+; priority=30
+extension=functionvoid.so
+
diff --git a/Examples/DlUnrestricted/dlunrestricted.php b/Examples/DlUnrestricted/dlunrestricted.php
new file mode 100644
index 0000000..d057f92
--- /dev/null
+++ b/Examples/DlUnrestricted/dlunrestricted.php
@@ -0,0 +1,13 @@
+<?php
+/*
+ * functionvoid.php
+ * @author Jasper van Eck<jasper.vaneck@copernica.com>
+ *
+ * An example file to show the working of a void function call.
+ */
+
+/*
+ * Run the function with the given name. As you can see, the given name
+ * can be different from the actual function name.
+ */
+my_void_function();
diff --git a/Examples/Exceptions/ExceptionCatch/Makefile b/Examples/Exceptions/ExceptionCatch/Makefile
index d8d2c74..83537dd 100644
--- a/Examples/Exceptions/ExceptionCatch/Makefile
+++ b/Examples/Exceptions/ExceptionCatch/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/Exceptions/ExceptionThrow/Makefile b/Examples/Exceptions/ExceptionThrow/Makefile
index b153a3f..c8571ca 100644
--- a/Examples/Exceptions/ExceptionThrow/Makefile
+++ b/Examples/Exceptions/ExceptionThrow/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/Extension/Makefile b/Examples/Extension/Makefile
index e6b0b9a..a55b6c1 100644
--- a/Examples/Extension/Makefile
+++ b/Examples/Extension/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/FunctionNoParameters/Makefile b/Examples/FunctionNoParameters/Makefile
index e170ba3..ccd4ac2 100644
--- a/Examples/FunctionNoParameters/Makefile
+++ b/Examples/FunctionNoParameters/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/FunctionReturnValue/Makefile b/Examples/FunctionReturnValue/Makefile
index cf41971..0a2e1c3 100644
--- a/Examples/FunctionReturnValue/Makefile
+++ b/Examples/FunctionReturnValue/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/FunctionVoid/Makefile b/Examples/FunctionVoid/Makefile
index fc14780..fbf4bdd 100644
--- a/Examples/FunctionVoid/Makefile
+++ b/Examples/FunctionVoid/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/FunctionWithParameters/Makefile b/Examples/FunctionWithParameters/Makefile
index 271e019..bbebb43 100644
--- a/Examples/FunctionWithParameters/Makefile
+++ b/Examples/FunctionWithParameters/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++
diff --git a/Examples/Globals/Makefile b/Examples/Globals/Makefile
index 764fb5f..a38d8c8 100644
--- a/Examples/Globals/Makefile
+++ b/Examples/Globals/Makefile
@@ -4,7 +4,7 @@ CPP_FLAGS = -Wall -c -I. -O2 -std=c++11
PREFIX = /usr
#Edit these lines to correspond with your own directories
-LIBRARY_DIR = ${PREFIX}/lib/php5/20121212
+LIBRARY_DIR = $(shell ${PHP_CONFIG} --extension-dir)
PHP_CONFIG_DIR = /etc/php5/cli/conf.d
LD = g++