How to properly include an external library source in a NuttX build?

Create issue
Issue #88 resolved
David Drinnan created an issue

Does the NuttX build framework (ie. the Makefile design) support adding external libraries to chip sources?

Put another way, if I want to add an external library to the source of one of the chips, and build it from nuttx make files, is there a suggested way to include it in the build? I'm thinking a way that fits into the existing Makefile framework provided by NuttX.

Take for example, the Nordic Device Family Pack.

The #include lines in the source of this DFP are designed to have the directory with the header files included as a -I include path at compile time. So it seems the best way to add the build of this source to a chip in the NuttX source is to manually add CTAGS += nordic/Device/Include to the Make.defs in the chip-specific source folder, nrf52. That works, but I can't help but feel it's hacky to change CTAGS at such a low-level in the build framework, in a file called Make.defs no less.

Comments (9)

  1. David Drinnan reporter

    Alternatively, I can symlink all the header files into the base chip directory arch/arm/src/nrf52, but that clutters up that directory with lots more header files from external libraries.

  2. David Drinnan reporter

    Or add CFLAGS += -I$(ARCH_SRCDIR)/chip/include to the base Makefile for the arm architecture, and symlink all the external DFP headers into the nrf52/include directory.

  3. Gregory Nutt

    You can add the definition EXTRA_LIBS in your Make.defs file.

    It expects the library to reside in nuttx/libs but you should be able to add a symbolic link there.

  4. Gregory Nutt

    You can add to the CFLAGS in the Make.defs too. I would prefer not to modify in global, architecture-independent build logic for specific cases.

  5. David Drinnan reporter

    I didn't know about EXTRA_LIBS, that's good to know. Looks promising. I'll have to consider that a bit more.

    Ok, and good to know you don't see this is as a common enough need to put it in the global, architecture-independent build logic. I honestly didn't know, but figured it might be a common need and thus maybe worth putting there.

  6. Gregory Nutt

    There is also EXTRA_LIBPATHS that can be defined in your private Make.defs. With extensions to CFLAGS for include files and EXTRA_LIBS and EXTRA_LIBPATHS, all in your Make.defs, you should be able to link with any library.

    I will be closing this issue now. I am not sure that there was ever really and "issue" here anyway.

  7. Gregory Nutt

    Resolved per discussion. EXTRA_LIBS, EXTRA_LIBPATHS, and CFLAGS may be defined in the private Make.defs file to add libraries and library paths. CFLAGS may be extended to add external include file paths.

  8. Log in to comment