Low level (C level) PLATform introspection with ELisp.
That is, reach down to the C dungeon to get information about the current platform.
This library is really an exercise in compiling and loading
a dynamic Emacs module on one of the three main platforms: UN*X,
Mac OS and Windows. The library (either a .so, a .dylib, or a
.dll) can either be manually compiled and loaded in a running
Emacs, or can be compiled and loaded from the main platel.el file using
the emc Emacs library. All the
supporting code is kept in the c sub-directory.
The library exports, for the time being, one command and two functions.
platel-endianness: a command that shows a message saying whether the current platform is little or big endian.platel-is-little-endian: a function that returnsTif the current platform is little-endian.platel-is-big-endian: a function that returnsTif the current platform is little-endian.
The process is clear. Compile the library that is the dynamic Emacs
module and load it in Emacs.
You can do it manually, but that would limit how the module (read:
any module) can be distributed and loaded, especially via a
package distribution system like elpa.
Let's see what this entailed.
Just use make? Not so fast. There are (at least) three platforms
to consider, and "reinvent the wheel" plus NIH syndrome are very
powerful motivators.
As a result, platel can be built "manually" in two ways.
- Use three flavors of
Makefile. - Use
cmake.
As previosly stated, platel can be - automatically - (re)built
directly from Emacs using the emc library.
Choose what you prefer.
To start, note that the actual Emacs module code in the the c
sub-directory. Apart from the CMakeLists.txt file which will be used
for the cmake building process, there are a few make files.
platel.make: a generic UN*X make file (tested on Ubuntu.platel-darwin.make: a Mac OS specific make file (tested on an Intel Macbook Pro laptop running Sequoia).platel.nmake: a Microsoftnmakemake file (tested on W11).Makefile: earlier version ofplatel-darwin.make.
All make files have targets all (the default one), clean,
install, and uninstall.
To build and install on UN*X just issue:
$ cd /path/to/platel/c
$ make -f platel.make
$ make -f platel.make install
The install target starts the building as weel, so you really just
need the last command.
At this point you can check that the library file
platel_emacs_module.so is present in the top platel directory.
$ ls /path/to/platel/*.so
platel_emacs_module.so
Invoking the following will clean up the installation.
$ cd /path/to/platel/c
$ make -f platel.make uninstall
To build and install on Mac Os just issue:
$ cd /path/to/platel/c
$ make -f platel-darwin.make
$ make -f platel-darwin.make install
Again, the install target starts the building as weel, so you really just
need the last command.
At this point you can check that the library file
platel_emacs_module.dylib is present in the top platel directory.
$ ls /path/to/platel/*.dylib
platel_emacs_module.dylib
Invoking the following will clean up the installation.
$ cd /path/to/platel/c
$ make -f platel.make uninstall
To build and install on Windows just issue:
W:\Path\to\platel\c> nmake /F platel.nmake
W:\Path\to\platel\c> nmake /F platel.nmake install
Of course, this assumes that you have started cmd or Power Shell
from the proper Visual Studio
startup item, in order to have the overall Visual Studio environment
completely setup (which is what emc provides for you on Windows).
As before, the install target starts the building as weel, so you really just
need the last command.
At this point you can check that the library file
platel_emacs_module.dll is present in the top platel directory.
W:\Path\to\platel\c> dir /b ..\*.dll
platel_emacs_module.dylib
The /b switch is for "bare" display by dir.
Note that the Windows build process creates also .exp and .lib
(and .obj) files supporting the .dll creation. The
platel_emacs_module.def file is necessary to fully control the
.dll creation and it is part of the source distribution.
Invoking the following will clean up the installation.
W:\Path\to\platel\c> make /F platel.nmake uninstall
If you have loaded the platel_emacs_module in your Emacs session,
now you can issue the command platel-endianness. On an Intel
machine you will see the following message in the minibuffer.
PLATEL: platform is little endian.
The functions platel-is-big-endian and platel-is-little-endian
will also be available for ELisp programming.
There is currently (March 2025) no way to easily unload a module
from a running Emacs, according to the current documentation.
Re-installing and even uninstalling platel may not work, unless you
restart your Emacs first.
All in all, this exercise falls in the catogory of "let me just add a
small feature to Emacs". The result being the construction of several
supporting pieces of code and the learning of several tools and their
idioc... idiosyncrasies (cf., cmake and nmake).
It has bee a trip. Yes, it has been a waste of time, but seriously: if you are reading this, admit it! You would have done the same.
Enjoy
Marco Antoniotti, Milan, Italy, (c) 2024-2025