Simplifying Mk includes


In the Ports system we have some ports that are depended upon by large numbers of other ports, and thus sometimes have large amounts of boilerplate that needs to be duplicated in many ports.

Historically the solution has been to create a shared Mk resource, called bsd.${appname}.mk and place it either in ports/Mk, or the MASTERDIR of the main port. To avoid having the trouble of deciding where to put the .include directive in the port's Makefile, USE_ variables have been defined in to include these files for the porter.


Practical issues

Style issues


The new file, will contain any code to handle inclusion of ports/Mk/*, and the repetitions of code can be reduced;

in lieu of:

.if defined(USE_OPENSSL)
.include "${PORTSDIR}/Mk/"

.if defined(USE_EMACS)
.include "${PORTSDIR}/Mk/"

we can instead use:

.for _useflag in openssl emacs gnustep php java ocaml 
. if defined (USE_${_useflag:U})
.  include "${PORTSDIR}/Mk/bsd.${_useflag}.mk"
. endif

meaning that creating a new USE flag is no harder than simply adding the name to the end of the .for loop -- as well as enforcing consistency in USE naming.

We can also move conditionally included files to a plugins/ subdirectory (to be painted before the bikes go in it), ending up with a file hierarchy under ports/Mk that looks something like this: [tree deleted]


This needs to be incremental in its introduction.

  1. First, the code from for includes needs to be extracted and put into a separate file to keep the include code simple and maintainable, rather than its current state of being scattered around ports/160361

  2. Any ports that .include mk files from ${PORTSDIR} directly need to use USE_ flags instead.

  3. Finally change the inclusion blocks into a .for loop as described above.

SimplifyingMkIncludes (last edited 2013-09-21 23:53:53 by MarkLinimon)