factory make
- Description:
Describes the different make directives.
This allows to compile C/C++ code as middleware for Javascript or Python.
-
The package meta-data is stored in the
./package.jsonfile, created at initialization, as detailed here. -
Source files are in the
./srcdirectory. -
Target files are in the:
./public/directory for all documentation and downloadable web files../node_modules/directory for all compiled or imported third-party used files.
-
Useful makefile environment variables, that can be used is package makefile and scripts:
- The
AIDE_PACKAGE_NAMEcontains the package name as defined in package.json. - The
AIDE_NODE_MODULES_DIRdefines where the./node_modulesdirectory is. - The
AIDE_NODE_MODULEistrueif the the actual package is used as a dependency in the./node_modulesdirectory. - The
AIDE_ROOT_PACKAGE_NAMEcontains the root package name when it is used as a dependency. - The environment variables and C/C++ macro
ON_MAC,ON_RASPI,ON_WINare defined if on MacOS, RasPI or Windows respectively. - The environment variables and C/C++ macro
VERBOSEis set totrueto indicate a verbose mode.- This environment variable can be used in any sub-process or C/C++ source file.
- Invoking make with a
--debug=$optionsetsVERBOSEtotrue.- The
make --debug=none $targetcommand setsVERBOSEtotruewithout any other make debugging information.
- The
- The
export VERBOSE=truecan also be set,- at the beginning of the main makefile or
- in the environement before calling
make.
- The
-
Do not edit:
README.mdin the package root directory, it is generated by build frompackage.json.package-lock.jsonin the package root directory, it is used to managenode_modulespackages.
-
Methods
(static) build()
- Description:
Build all target files from source files.
-
This corresponds to the
npm run buildcommand in thepackage.jsonfile. -
User defined build commands are defined in the makefile BUILD variable.
-
This command compiles C/C++ files if any, installs node-gyp files if used, builds the python wrapper if relevant, generates documentation files if possible, and finally builds all target files specified in the
BUILDvariable of themakefilefile.
-
(static) build_mpl()
- Description:
Compiles Maple files if any.
- If Maple is available, any
.mpl, file is executed in the./srcdirectory to generate: - By contract, all Maple generated files must be added to the
gitsource file bundle, so that if Maple is not available for another checkout instance of the package, generated file are available in a fixed form. - These functions are documented as
aidemaplestatic function:- New function can be created in
aidebuildderived package using, as starting source file:- The maple2latex.mpl almost emty function, and
- The maple2latex.hpp related documentation.
- A
$namefunction is by contract stored in a$name.mplfile, while tests or other Maple commands are intest.mpl. - Any
./src/*.mplfile is run with:- The output stored in
./public/*.mpl.out.txtfor verification and public share.- This file contains errors if any, otherwise contains only the function definition.
- An uglified version of the file (i.e., of minimal size) stored in
./node_modules/.inc/*.mplfor latter include.- Further use simply requires to insert a
$include <*.mpl>in the maple source code.
- Further use simply requires to insert a
- The output stored in
- Package defined functions can be tested using the
test.mplsource file, when runningmake test. - Caveat: Source file comments (which are strongly recommended) must always start a new line, whereas not be added at the end of a maple command line, because maple source file is uglified on one line when included.
- New function can be created in
- If Maple is available, any
(static) build_cpp()
- Description:
Compiles C/C++ files if any.
Organization of the files and directories
-
C/C++ headers are stored in
.hppfiles. -
C/C++ sources yielding library routines are stored in
.cppfiles. -
C/C++ main file sources yielding executables are stored in
.Cfiles. -
C/C++ template file sources not taken into account unless explicitely included are stored in
.tppfiles. -
Target files are stored:
- in the
./node_modules/.incdirectory for C/C++ include header files of libraries. - in the
./node_modules/.libdirectory for static C/C++ compiled libraries. - in the
./node_modules/.bindirectory for binary executable files.
- in the
-
The
"build_cpp": falsedirective in thepackage.jsonfile prevents to compile C/C++ code, even if any. -
Here we build static
./node_modules/.lib/lib$name.alibraries to simplify the link phase and a better compatibility. -
The
make testcommands compiles and run the tests; it is recommended to provide such test.
Compilation options
Compilation options include the compiler choice, compilation flags, include directories, precompiled library directories and names, to be defined in the
./src/makefilefollowing the given model:CXX = c++ # 'CXX' : defines the C/C++ compiler CCFLAGS = -$option # 'defines' : compilation options INCDIRS = -I$include_dir ... # 'include_dirs' : source header directories LIBDIRS = -L$library_dir ... # 'library_dirs' : precompiled library directories LIBS = -l$library ... # 'libraries' : libraries to link with the code AIDEDEPS = aidesys # 'AIDEDEPS' : other aidebuild packages dependencies-
The
CCFLAGSandINCDIRRare used for source file compilation. -
The
LIBDIRSandLIBSare used for executable linking. -
The
AIDEDEPSlist aidebuild packages dependencies, allowing to automatically builds them. -
Note: Actually the
-std=c++17C++ standard is in use.
Compiling with an alternative compiler
Using this piece of makefile it is possible to erase all C/C++ compilation and recompile with an alternative compiler, here using, for instance, the usual MacOS clang compiler.
export CXX = clang++ recompile: /bin/rm -rf ../node_modules/.lib/*.a ../node_modules/.bin/test make build_cppDevelopment hints
- This command allows to identified undefined symbols (i.e., defined in a .hpp fils but not implemented in a .cpp file)
nm -C --demangle --undefined-only ../node_modules/.lib/$module_name.a | grep $module_name-
(static) build_gyp()
- Description:
Compiles the node-gyp wrapper files, in order use the code via a web service.
-
The node-gyp wrapping allows to use C/C++ source in a Javascript server side node express utilities for web applications and services.
-
It is detailed in the aideweb package, which is a root package for such functionality, e.g. using a WrapperCCService.
-
It is recommended to install
gypglobally, to save local space, i.e. run:
sudo npm install -g node-gyp-
You may also run
sudo npm install -g bindings express express-fileupload node-addon-apiinstead of locally. -
The
"gypfile": truedirective in thepackage.jsonfile enablesnode-gypbuilt.
-
(static) build_python()
- Description:
Builds a python wrapper for the local C/C++ source code and its dependencies.
- It is based on swig and available as a user adaptable script.
- The
"swig": truedirective in thepackage.jsonfile enables building the python wrapper. - The python 3.10 and 3.11 versions are actually usable, easily adaptable to others.
Development hints
- In the makefile, you likely have to explicitly list, in the right order, used *.hpp files used by other files because the default .hpp order is random. This is to be done in the PY_HPP file, e.g.,
PY_HPP="../node_modules/wjson/src/Value.hpp ../.."A minimal python wrapping is exemplified in this
test.pyfile.- In order to avoid, in
.hppor.cppfile, to take python incompatible pieces of code (e.g., C++ operator) into account a construct of the form can be used:
#ifndef SWIG // Here is code not to be wrapped for python by swig #endif-
As for usual C/C++ compilation
.hppand.cppfiles are taken into account but.tppare not unless explicitly included. -
The makefile specifies the
PYTHONPATHenvironment variable allowing to load the defined modules
export PYTHONPATH += :../node_modules/python/site-packages- Since SWIG does NOT consider namespace, all objects are prefixed with the compiled module name, e.g.:
python >>> import wjson >>> wjson.alert(True, "", "Looks fine") # even if aidesys::alert comes not from wjson but the aidesys namespace- A recommended
test.pyfile implements functional and non-regression tests.- Tests are run in the
./srcdirectory.
- Tests are run in the
(static) build_public()
- Description:
Compiles all documentation and downloadable web files.
-
This generates a HTML documentation in the
./publicdirectory and generates theREADME.md. -
Refer for jsdoc2 for a presentation of the general mechanism.
-
The following generation process is performed:
- The
README.mdfile in automatically generated from thepackage.jsonand beyond standard meta-data options:- An optional
introduction.mdallows to present the package in the README beyond meta-data presentation - An optional
usagesection in thepackage.jsonas exemplified here allows to add a sequence of HTML lines to described the package usage.
- An optional
- All
.hpp.js.sh, source files are parsed using jsdoc in order to generate the relative documentation files. - All
.js.css.hpp.cpp.share shared after being beautified in order to have a standard format and normalized presentation. - Broken links are detected.
- The
-
The following complementary files are processed:
- All
.jsand.cssare compacted and copied in order to be optimally downloaded. - All
.html, and.png,.jpg,.gifimages are copied in the public directory. - Any
.odgdrawing is translated to.pngiflibreofficeis installed, and the source is copied. - Any
.tex(except*.inc.texinput file that only to be included) section file is- concatenated to this preamble to be compiled as a
.pdffile; - with a bibliography using
.bibfile added if any\cite{…}command are present; - usually structured in
\subsectionto be reused in larger documents,- you may refer to this source example compiled here.
- concatenated to this preamble to be compiled as a
- All
-
(static) test()
- Description:
Runs functional and non-regression tests.
-
This corresponds to the
npm testcommand in thepackage.jsonfile. -
The following tests are performed in this order:
- The
test.shfile, if any, is run withbashin the./srcdirectory. - The
test.Cfile, if any, contains aint main()routine and is compiled and executed for testmake test [MAIN=test] [ARGV="arg1... "]runs- If [MAIN=test] (default) runs Bash + C/C++ + JavaScript + Python tests.
make gtest [MAIN=test] [ARGV="arg1... "]runs C/C++ tests only, via gdb, in order to observe debugging information.- The following commands are issued:
break exit ; run $ARGV ; backtrace ; backtrace all ; quit 0so that if the program is terminates with errors, the exit stack is shown.
- The following commands are issued:
make vtest [MAIN=test] [ARGV="arg1... "]runs C/C++ tests only, via valgrind, with standard options, in order to observe debugging information.
- The
test.jsfile, if any, is run withnode. - The
test.pyfile, if any, is run afterbuild_python. - Constructs any target specified in the makefile
TESTvariable.
- The
Note: The ARGV applies to
test.sh,test.candtest.jsfiles.-
(static) clean()
- Description:
Cleans installation files.
-
This corresponds to the
npm run cleancommand in thepackage.jsonfile. -
Removes the ./node_modules and ./package-lock.json directory and file.
-
Also remove all temporary
*~files generated by source normalization (uncrustify command) or esp32gpiocontrol updates, … -
Runs the
./src/clean.shscript, in the./srcdirectory, if any, if order to perform additional clean operation. -
Constructs any target specified in the makefile
CLEANvariable.
-
(static) sync()
- Description:
Syncs, thus publishes, the files with respect to the git repository, and get the npmjs repository status.
- Runs git pull, commit and push with default options and no commit message (which is only acceptable for preliminary development or minor changes not worth documenting them).
Publishing on the npmjs repository
- To publish on https://www.npmjs.com:
- Set the
package.jsonboolean field"npm_publish": trueto indicate that the software has been published. - Sign up or Sign in.
- In the package root directory with
package.json:npm adduserto connect the package to the account,npm publish --access-publicto publish, while precisions are given if required.
- Set the
- To update a published package on
https://www.npmjs.com:- Properly update the version number in
package.jsonaccording to semantic-versioning. - In the package root directory run
npm publish.
- Properly update the version number in
- Managing conflicts: most ofter conflicts are related to generated files, using
git merge --autostash(with care) solves the conflict, preserving local source changes.
Archiving on the softwareheritage
- To archived on https://archive.softwareheritage.org
- Set the
package.jsonboolean field"softwareheritage": trueto indicate that the software has been archived. - Use this link to save it.
- Enter
gitinOrigin type - Enter the documentation link, e.g.
https://gitlab.inria.fr/line/aide-group/$projet-nameinOrigin Url
- Enter
- Set the
(static) show()
- Description:
Opens the documentation page using the current defined browser in the $BROWSER variable.
(static) usage()
- Description:
Shows the makefile usage, which is the default operation unless the makefile defined another.
(static) install()
- Description:
Installs specific any source file, this is usually not called directly, but via
npm install.- When the
npm installcommand is run, after npm installation, it runsmake -s -C ./src installwhich:- Updates the
.src/.makefile.incfile from internet. - Runs the
./src/install.shscript withbash -ein the./srcdirectory if any. - Constructs any target specified in the makefile
INSTALLvariable. Remark: In order to initialize a package directory, runs the init script.
- Updates the
- When the