> <\body> Building your own package with > In this tutorial, we are going to construct a package called which defines a simple function and to glue it in the interpreter. package> <\session|shell|default> The first step to create a package (hereafter >) is to make a folder named after your package (preferably in lower case and number>): \; <\input|Shell] > PKG=$HOME/mypkg;mkdir $PKG \; Next, we create a folder which will contains the source files that produce the library attached to the package . All the files , of this folder will be compiled and put in the library >. \; <\input|Shell] > mkdir $PKG/src \; We edit the file |~/mypkg/src/my_fct.cpp> in the folder and insert the following instructions: <\cpp-code> namespace mmx { \ \ \ \ double my_fct(double x) { return 2*x; } } \; This file defines a function called (which multiplies a by ).\ \; Next, we create a folder that will contain all the header files of the package. \; <\input|Shell] > mkdir $PKG/include; mkdir $PKG/include/mypkg; \; All the headers will be put in the folder so that the include instructions will have the form: . This avoids name conflicts in case several packages provide header files with the same name. In this folder, we edit the file > and insert the declaration of : <\cpp-code> namespace mmx { \ \ \ \ double my_fct(double x); } We are now ready to generate a preliminary \ version of the package with its configuration files. For this purpose, we use the script , which is provided by the package of . In order to be able to use this script, we update our environment as follows: \; <\input|Shell] > source $HOME/Devel/buildmmx/local_env \; where is the folder where > has been built. \; To generate default configurations files, we proceed as follows: \; <\unfolded-io|Shell] > mmxmake $PKG -init <|unfolded-io> mmxmake: created /Users/mourrain/mypkg/specif mmxmake: updated /Users/mourrain/mypkg/specif/mypkg-cmake.mmx mmxmake: created /Users/mourrain/mypkg/CMakeModules mmxmake: updated /Users/mourrain/mypkg/CMakeModules/FindMypkg.cmake.in mmxmake: updated /Users/mourrain/mypkg/CMakeModules/MypkgConfig.cmake.in mmxmake: updated /Users/mourrain/mypkg/include/mypkg/mypkg-config.hpp.cmake mmxmake: created /Users/mourrain/mypkg/doc mmxmake: created /Users/mourrain/mypkg/doc/tools mmxmake: updated /Users/mourrain/mypkg/doc/tools/tm2html mmxmake: created /Users/mourrain/mypkg/doc/doxygen mmxmake: updated /Users/mourrain/mypkg/doc/doxygen/doxyfile.in mmxmake: created /Users/mourrain/mypkg/css mmxmake: created /Users/mourrain/mypkg/doc/css mmxmake: updated /Users/mourrain/mypkg/doc/css/mmxdoc.css mmxmake: updated /Users/mourrain/mypkg/CMakeLists.txt mmxmake: created /Users/mourrain/mypkg/doc/texmacs mmxmake: updated /Users/mourrain/mypkg/doc/texmacs/installation_cmake.en.tm mmxmake: updated /Users/mourrain/mypkg/src/CMakeLists.txt mmxmake: updated /Users/mourrain/mypkg/doc/CMakeLists.txt The files needed for the configuration of the package have been generated. We can now configure and build the package. For that purpose, we create a folder > \ which will contain the files generated during the construction (binary files, libraries, ...). The configuration is run in this folder. We use the command applied on the path to the source folder :\ \; <\unfolded-io|Shell] > BUILD=$HOME/buildmypkg; mkdir $BUILD; cd $BUILD; cmake $PKG <|unfolded-io> mkdir: /Users/mourrain/buildmypkg: File exists == Configuring mypkg 0.1 \ \ \ [*] enable library build (SRC=ON) \ \ \ [ ] disable test build (TEST=OFF) \ \ \ [*] enable application build (APP=ON) \ \ \ [*] enable glue with mmx interpreter (GLUE=ON) \ \ \ [ ] disable axel plugins (AXL=OFF) \ \ \ [*] enable dtk plugins (DTK=ON) \ \ \ [ ] disable automatic documentation (DOC=OFF) \ \ \ [ ] disable benchmarks (BENCH=OFF) \ \ \ [ ] disable examples (EXPL=OFF) \ \ \ [ ] disable static inclusion (EMBEDDED=OFF) \ \ \ [*] enable shared library build (SHARED=ON) \ \ \ [ ] disable static library build (STATIC=OFF) \ \ \ [ ] disable debugging (DEBUG=OFF) \ \ \ [*] enable optimization (OPTIMIZE=ON) \ \ \ [*] enable cpp exceptions (EXCEPTIONS=ON) \ \ \ [ ] disable threads (THREADS=OFF) \ \ \ [ ] disable external packages (EXTERNAL=OFF) \ \ \ [ ] disable development mode (DEV=OFF) \ \ \ [ ] simd level (SIMD=OFF) -- Configuring done -- Generating done -- Build files have been written to: /Users/mourrain/buildmypkg To compile the files of the packages, the command can be used (in the folder ): \; <\unfolded-io|Shell] > make <|unfolded-io> [35m[1mScanning dependencies of target mypkg [0m[100%] [32mBuilding CXX object src/CMakeFiles/mypkg.dir/my_fct.cpp.o [0m[31m[1mLinking CXX shared library ../lib/libmypkg.dylib [0m[100%] Built target mypkg This building step \ creates in the folder a dynamic library (or ) which contains the definition of . We are now going to connect the C++ function with a function in the interpreter. For that, we create also a folder which will contain the files needed for the plugin that will be loaded the interpreter: \; <\input|Shell] > mkdir $PKG/glue \; In this folder, we edit the file > and insert the following instructions: <\mmx-code> foreign cpp import { \ \ cpp_include "mypkg/my_fct.hpp"; \ \ \ \ f: Double -\ Double == my_fct; } \; The instruction includes the corresponding \ C++ header file and declares the C++ function . The next instruction declares a new function in the interpreter which is calling the C++ function . To generate the C++ files that will be compiled to get the plugin, we use the command \; <\unfolded-io|Shell] > cd $PKG; mmxglue $PKG <|unfolded-io> mmxglue: processing autonomous package mypkg-0.1 mmxglue: \ \ processing f.mmx mmxglue: \ \ \ \ gluing f mmxglue: updated /Users/mourrain/mypkg/glue/f.cpp mmxglue: updated /Users/mourrain/mypkg/glue/glue_mypkg.cpp mmxmake: updated /Users/mourrain/mypkg/CMakeModules/FindMypkg.cmake.in mmxmake: updated /Users/mourrain/mypkg/doc/doxygen/doxyfile.in mmxmake: updated /Users/mourrain/mypkg/CMakeLists.txt mmxmake: updated /Users/mourrain/mypkg/glue/CMakeLists.txt This creates in the glue folder a file binding the function with the function Double>, a file used when loading the plugin in the interpreter. It also updates the configuration files of the package.\ In order to be able to compile the plugin, we will need some files from the package . We setup the local configuration, as follows: \; <\input|Shell] > cp ~/Devel/buildmmx/CMakeModules/FindBasix.cmake CMakeModules <\input|Shell] > cp ~/Devel/buildmmx/CMakeModules/FindLibtool.cmake CMakeModules \; The folder is the folder where has been built. To compile the plugin, we can now type: <\unfolded-io|Shell] > cd $BUILD; make <|unfolded-io> == Configuring mypkg 0.1 \ \ \ [*] enable library build (SRC=ON) \ \ \ [ ] disable test build (TEST=OFF) \ \ \ [*] enable application build (APP=ON) \ \ \ [*] enable glue with mmx interpreter (GLUE=ON) \ \ \ [ ] disable axel plugins (AXL=OFF) \ \ \ [*] enable dtk plugins (DTK=ON) \ \ \ [ ] disable automatic documentation (DOC=OFF) \ \ \ [ ] disable benchmarks (BENCH=OFF) \ \ \ [ ] disable examples (EXPL=OFF) \ \ \ [ ] disable static inclusion (EMBEDDED=OFF) \ \ \ [*] enable shared library build (SHARED=ON) \ \ \ [ ] disable static library build (STATIC=OFF) \ \ \ [ ] disable debugging (DEBUG=OFF) \ \ \ [*] enable optimization (OPTIMIZE=ON) \ \ \ [*] enable cpp exceptions (EXCEPTIONS=ON) \ \ \ [ ] disable threads (THREADS=OFF) \ \ \ [ ] disable external packages (EXTERNAL=OFF) \ \ \ [ ] disable development mode (DEV=OFF) \ \ \ [ ] simd level (SIMD=OFF) -- Configuring done -- Generating done -- Build files have been written to: /Users/mourrain/buildmypkg [ 33%] Built target mypkg [35m[1mScanning dependencies of target mmxmypkg [0m[ 66%] [32mBuilding CXX object glue/CMakeFiles/mmxmypkg.dir/f.cpp.o [0m[100%] [32mBuilding CXX object glue/CMakeFiles/mmxmypkg.dir/glue_mypkg.cpp.o [0m[31m[1mLinking CXX shared library ../lib/libmmxmypkg.dylib [0m[100%] Built target mmxmypkg \; <\unfolded-io|Shell] > source $BUILD/local_env; mmx-light <|unfolded-io> \; <\session|mathemagix|default> <\input> <|input> use "mypkg" <\unfolded-io> <|unfolded-io> help f <|unfolded-io> <\text> Double>> <\unfolded-io> <|unfolded-io> f 3.2 <|unfolded-io> <\input> <|input> \; . If you don't have this file, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.> <\initial> <\collection>