submodules

Many open-source software projects utilize git submodules to pull in code from another repository into the project. For example, an audio plugin that is written using JUCE expects the source code of the JUCE framework to be in the external/JUCE folder. Instead of just hard-copying over the code, it is recommended to use git submodules.

While this might seem nice as the developer, from the package management side, this has some issues. Pulling in the source code of the parent project will not automatically also pull in the submodules. Packagers manually have to define where which repository needs to be installed. Thankfully pkgsrc has a useful function to deal with this issue, called ${SOURCEFORGE}_SUBMODULES, e.g. GITHUB_SUBMODULES.

Fetching automatically

${SOURCEFORGE}_SUBMODULES is a list that contains entries on where to install what as a submodule. The passed information needs follows the following scheme:

GITHUB_SUBMODULES+=	username repositoryname tag/hash submodulepath

So for example if a repository called atlas should be installed into dist, it should be written like this:

GITHUB_SUBMODULES+=     nim-lang atlas fa19ace5c5d176d0e19f9b6ad08239ce2ceea676 dist/atlas

In the example above, the repository located at https://github.com/nim-lang/atlas will be pulled into dist/atlas at the tag fa19ace....

The SUBMODULES list is available for the following source forges:

Fetching manually

Many source forges are not included in this system and thus need manual fetching, extracting and moving of the source code. For example, if a submodule is hosted on sourcehut. In this case the code below can be used for some inspiration on how to set things up.

NOTE: Replace the EXAMPLE/example with the name of the submodule’s project name.

EXAMPLE_TAG=			aa6fb162006f3015aa84c4305e15cb4d230f5ad6
EXAMPLE_DISTNAME=		example-${REPOSITORY_TAG}
DISTFILES+=			${EXAMPLE_DISTFILE}
SITES.${REPOSITORY_DISTFILE}=	https://git.sr.ht/~username/example/archive/${EXAMPLE_TAG}.tar.gz
EXTRACT_DIR.${EXAMPLE_DISTFILE}=${WRKSRC}

...

post-extract:
	${MKDIR} ${WRKSRC}/dist
	${MV} ${WRKSRC}/example-${EXAMPLE_TAG} ${WRKSRC}/dist/example

This will fetch the git repository example from the user username and extract it into ${WRKSRC}. This normally is the root of the package. Next the dist folder is created and then the repository is moved into this folder.

NOTE: Sometimes folders for submodules already are present. In such a case, delete the folder first to avoid moving the submodule into the already existing folder:

post-extract:
	${RM} -rf ${WRKSRC}/dist/example
	${MV} ${WRKSRC}/example-${EXAMPLE_TAG} ${WRKSRC}/dist/example

Footnotes