Using buildroot

From MOD Wiki
Jump to navigation Jump to search

This page describes how to make a plugin package for mod-plugin-builder (or MPB for short) using buildroot.

Plugin packages reside in plugins/package/ directory.

We have a few plugin examples available here.

Plugin package example

Here's an example of a plugin package file:

PLUGINPKG_VERSION = 1.0.0
PLUGINPKG_SITE = http://download.sourceforge.net/myplugin/
PLUGINPKG_SOURCE = myplugin-$(PLUGINPKG_VERSION).tar.gz
PLUGINPKG_BUNDLES = myplugin.lv2

$(eval $(cmake-package))

We're using PLUGINPKG as a generic name, you must use your package name in uppercase here.

Let's divide this into small pieces...

Alternatives to retrieve source code (DOES THIS SECTION FITS IN HERE??)

The '.mk' file will define how your source code is retrieved.
In most of the existing packages the '.mk' file tells buildroot to download the source. You can use a local tarball or point directly to the source code if you wish.

Point directly to the source code

Just replace the top section with the following:

<PACKAGE_NAME>_SITE_METHOD = local
<PACKAGE_NAME>_SITE = /path/to/source

Make sure to remove the <PACKAGE_NAME>_SOURCE line, if it exists.

If you try changing the eg-amp-lv2 example don't forget to remove the trailing path from the make command. It should look like this:

<PACKAGE_NAME>_TARGET_MAKE = $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D)

If you place the source code in same folder as the '.mk' file you can set the <PACKAGE_NAME>_SITE like this:

<PACKAGE_NAME>_SITE_METHOD = local
<PACKAGE_NAME>_SITE = $($(PKG)_PKGDIR)/

You can find a working example of such setup here.

Point to a local tarball

If you make a tar.gz file and put it in the same folder as the '.mk' file, you can replace the top section with the following:

<PACKAGE_NAME>_VERSION = 1.0
<PACKAGE_NAME>_SITE_METHOD = file
<PACKAGE_NAME>_SITE = $($(PKG)_PKGDIR)
<PACKAGE_NAME>_SOURCE = eg-amp-1.0.tar.gz

If you want to use an arbitrary path just replace the <PACKAGE_NAME>_SITE variable.

Version and download location

First we define the version, plus the download location and filename to download the source code from.

PLUGINPKG_VERSION = 1.0.0
PLUGINPKG_SITE = http://download.sourceforge.net/myplugin/
PLUGINPKG_SOURCE = myplugin-$(PLUGINPKG_VERSION).tar.gz

If you rather use a git repository, use something like this:

PLUGINPKG_VERSION = 25451be928b69c288f6978fb3b3fcf202dbd1ee1
PLUGINPKG_SITE = git://github.com/myself/myplugin
PLUGINPKG_SITE_METHOD = git

LV2 bundles

Moving on, we define which bundles to use.

Your build system can install more bundles than what's defined here, but only the defined ones will be picked up to be published locally and on the cloud.

Use a space to separate the bundle names. Newline escaping is not supported, everything must be in the same line.

(Note: they must be installed to $DESTDIR/usr/lib/lv2/)

PLUGINPKG_BUNDLES = mybundle1.lv2 mybundle2.lv2

Build rules

Finally, we defined the steps to build the package.

If you're using autotools or cmake, buildroot has this covered for you already.

Using other build systems means you have to specify how to configure, build and install the code.

autotools

For autotools, use:

$(eval $(autotools-package))

cmake

For cmake, use:

$(eval $(cmake-package))

waf

Here's an example for waf:

PLUGINPKG_TARGET_WAF = $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(HOST_DIR)/usr/bin/python ./waf

define PLUGINPKG_CONFIGURE_CMDS
	(cd $(@D); $(PLUGINPKG_TARGET_WAF) configure --prefix=/usr)
endef

define PLUGINPKG_BUILD_CMDS
	(cd $(@D); $(PLUGINPKG_TARGET_WAF) build -j $(PARALLEL_JOBS))
endef

define PLUGINPKG_INSTALL_TARGET_CMDS
	(cd $(@D); $(PLUGINPKG_TARGET_WAF) install --destdir=$(TARGET_DIR))
endef

$(eval $(generic-package))

raw makefile

And here's an example for raw makefiles:

PLUGINPKG_TARGET_MAKE = $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D)

define PLUGINPKG_BUILD_CMDS
	$(PLUGINPKG_TARGET_MAKE)
endef

define PLUGINPKG_INSTALL_TARGET_CMDS
	$(PLUGINPKG_TARGET_MAKE) install DESTDIR=$(TARGET_DIR)
endef

$(eval $(generic-package))

Tips and tricks

If using autotools or cmake and you need to specify options during configure, use something like this:

PLUGINPKG_CONF_OPTS=-DBUILD_GUI=OFF

If using autotools without an existing 'configure' script (ie, autogen.sh needs to be run first), use this:

PLUGINPKG_AUTORECONF = YES

If using autotools, cmake or raw makefiles and multiple jobs breaks your build, use this:

PLUGINPKG_MAKE = $(MAKE1)

Compile it

We're all set to compile.

$ cd ~/mod-plugin-builder/
$ ./build eg-amp-lv2
$ ls ~/mod-workdir/plugins/
eg-amp.lv2

Success, the plugin has been built. If you get an error of no-such file or directory, check that you have set WORKDIR the same as when you bootstrapped the plugin-builder.

Final notes

Plugin packages are buildroot files. Because of that it must comply with Buildroot rules.
A few important notes:

  • The package name is defined by the folder name and cannot contain '.'
  • There must be a <packagename>.mk file inside the package folder
  • The package name and '.mk' file name must be the same
  • Inside the '.mk' file all defined variables must start with the package name in uppercase replacing '-' with '_'
  • You need to define the generated plugin bundle names in the <PACKAGE_NAME>_BUNDLES variable
  • Browse through other examples so you get an idea of other variations of the makefiles (how to use cmake or waf for example)
  • If you want to rebuild after a change to your plugin or the .mk then it is often easiest to just delete the previous build's directory for your plugin ~/mod-workdir/plugins-dep/build/<packagename>-<version>

Browse through other examples so you get an idea of variations of project files.

SHOULD THIS GO ANYHERE ??

THIS BIT WAS IN THE CREATING MPB PAGE. DOES IT HAVE ANY RELEVANT INFORMATION THAT IS NOT IN SOME OTHER WAY IN THE ABOVE SECTION AND SHOULD BE INCORPORATED?

Get source code and create a '.mk' file

In case you haven't started your LV2 plugin yet just please follow through the links above in #LV2 Basics.
We have a few plugin examples available here. For this guide we'll use the eg-amp.lv2 example, already included inside of mod-plugin-builder.

Assuming you have a working LV2 plugin code, you'll now need to create a buildroot mk file to build it.
Buildroot requires you to create the new mk file as plugins/package/NAME/NAME.mk - using the same name for both the folder and mk file.

The documentation for this file type is quite extensive, so it's not possible to cover everything here.
On the mod-plugin-builder repository (that you should have cloned before) there are many mk file examples under plugins/package/.

TIP: The eg-* "packages" have their plugin code stored locally instead of downloading from external sources.