|[mosquitto-dev] Cross-compiling Mosquitto|
I recently cross-compiled Mosquitto 1.3 for an embedded ARM/Linux board, and although it wasn't too difficult, it did require a modification to the Makfiles to do an "install," and it might be nice to update the build files to make the process easier.
Cross-compiling the binaries was easy. It just required setting all of the variables for the build tools. Assuming a cross-compiler prefix of "arm-linux-" I did this:
$ make CC=arm-linux-gcc CXX=arm-linux-g++ \That worked great. Then I tried to install the binaries to a staging directory, but the build uses the install "-s" switch to strip the binaries of debug symbols. This is the desired behavior, but, by default, it uses the native (x86) strip program. We need the one from the cross compiler. So I did a global search/replace in all the Makefiles of "$(INSTALL) -s" with:
$(INSTALL) -s --strip-program=$(STRIP)And then I did the install with:
$ make STRIP=arm-linux-strip DESTDIR=$PWD/_install installAnd that put all the cross-compiled binaries into ./_install, which I then copied onto the board.
So anyway, I was thinking that it might be kind of nice to have a "CROSS_COMPILE" variable in the config.mk to automate this. Perhaps, like with the Linux kernel, just set this to the GCC prefix, and have the tool variables set automatically. Maybe it can be added this to config.mk like:
# Uncomment to cross-compile the broker.That could then be used to set the variables:
CC=$(CROSS_COMPILE)gccAnd then, maybe to prevent someone from accidentally installing cross-compiled binaries onto their host, also update the DESTDIR to something local, perhaps using the compiler prefix to come up with a staging directory name:
Back to the top