Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] Cross-compiling Mosquitto

Yes, that is better that what I did. Great. I will give it a try on a couple of boards this week and report back.

Frank

On 05/26/2014 03:24 PM, Roger Light wrote:
Hi Frank,

Sorry for the huge delay replying, this just fell down my list of
emails I'm afraid.

Thanks for the details, I've implemented a variation of what you've
suggested, e.g.

${CROSS_COMPILE}${CC}

rather than

${CROSS_COMPILE}gcc

This doesn't break things for none-gcc compilers.

Cheers,

Roger

On Wed, Mar 26, 2014 at 4:06 PM, Frank Pagliughi
<fpagliughi@xxxxxxxxxxxxxx> wrote:
Hi All,

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++ \
     AR=arm-linux-ar LD=arm-linux-ld

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 install

And 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.
# Set to the proper compiler prefix for the target board.
#CROSS_COMPILE:=arm-linux-

That could then be used to set the variables:

CC=$(CROSS_COMPILE)gcc
CXX=$(CROSS_COMPILE)g++
AR=$(CROSS_COMPILE)ar
LD=$(CROSS_COMPILE)ld
STRIP-$(CROSS_COMPILE)strip

And  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:

ifdef CROSS_COMPILE
     DESTDIR ?= $(PWD)/$(CROSS_COMPILE)build
endif

Thanks,
Frank



_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev

_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev




Back to the top