# The use of 'make config' in scripted environments



## sub_mesa (Jun 19, 2014)

Dear BSD users,

I could use some help with the following. I'm working on a solution to automate port building for my project, ZFSguru. Previously I used scripts that do this semi automated, but now I'm working on a solution with full automation.

The actual building of the ports works great. But what about the port options? Typically, `make config` is used to set option knobs. This can only be used interactively. And I want a scripted solution.

The solutions I have looked at:


Usage of the BATCH argument as in `make -DBATCH`. This works, but will build all ports with default knobs.
Usage of `make config` or just plain `make install` using a non-interactive terminal (script). This works much the same as the BATCH solution above.
Read the MakeFile from applicable ports and create a substitute of `make config` just for my purpose.
Patch/Modify `dialog4ports` so that I extract the options from the Input (stdin).

Now I don't want to make things too complicated. All I really want is this:

1) `make config` or similar command executed by script
2) the default port options are chosen, and written to the /var/db/ports directory

This allows me to grab /var/db/ports and compare it with the stored options to see if any option has changed. If there is a change, then the human operator must decide about the option before the build process is started again for that port. 

The problem is, `make config` when used in non-interactive shell, will indeed choose the default port options and continue with the port build process. However, it does *NOT* write the default port knobs in /var/db/ports directory. It only creates an empty directory such as /var/db/ports/devel_gmake. What is missing is the /var/db/ports/devel_gmake/options file with things like:


```
# This file is auto-generated by 'make config'.
# Options for gmake-3.82_1
_OPTIONS_READ=gmake-3.82_1
_FILE_COMPLETE_OPTIONS_LIST=NLS
OPTIONS_FILE_SET+=NLS
```

So all I want is to use `make config` in a scripted environment, equivalent to an interactive shell using `make config` and pressing the Enter key when presented with the port options. This will choose the defaults and write the chosen options to the options file located in /var/db/ports directory. But this is not working in a non-interactive shell because no options file is created.

Would love some suggestions on how to resolve this.

Your help is much appreciated!
Kind regards,
sub.mesa / Jason


----------



## SirDice (Jun 19, 2014)

sub_mesa said:
			
		

> I'm working on a solution to automate port building for my project, ZFSguru. Previously I used scripts that do this semi automated, but now I'm working on a solution with full automation.


Use ports-mgmt/poudriere.


----------



## kpa (Jun 19, 2014)

Seconded. Ports building in a live enviroment is still quite error prone despite efforts to fix the long standing problems and the only real solution is to use a jail based builder that can guarantee a clean build enviroment for every built port.


----------



## sub_mesa (Jun 19, 2014)

Thanks for suggesting Poudriere. However, I'm not looking to replace my current solution, which is probably more advanced than anything out there. It basically starts with downloading the sourcecode, and finishes with LiveCD and other produced stuff ready for upload to the master server.



> Ports building in a live enviroment is still quite error prone despite efforts to fix the long standing problems and the only real solution is to use a jail based builder that can guarantee a clean build enviroment for every built port.


The automated build system I created does everything in a jail or chroot and should have pristine building capabilities, as well as full parallel building with dependencies in place.

It's also basically finished, except for polishing and one major feature still open: the port options. Currently, everything is built with default option knobs. Hence, before I can use it to replace my older build system, I need to be able to select option knobs. For example, I build Virtualbox addon packages with both X support and without. So I have two addons - called Services in ZFSguru slang. Each installs the same port, but with different port options. My build system can handle all that and I'm quite pleased with the results so far.

I have tried to look at /usr/ports/Mk/bsd.port.mk because some of the stuff for dialog4ports is in there.

I also tried things like `echo -e "\n" | make config`. But that doesn't work; probably because the input buffer is cleared at the start, to avoid key presses during port building to affect the next `make config` that pops up. What I want seems rather simple: mimic the effect of pressing the enter key. But it appears that `make config` was not designed to be operated by a script.


----------



## ondra_knezour (Jun 19, 2014)

What about making slave port which only change options of his master? IMHO ideal for something like virtualbox-with-x11 and virtualbox-without-x11 build in one run. You have to just set changed options, master port, conflict with master port and you are good to go. See the Sendmail with SASL support port as example.

Also check source for the ports-mgmt/portmaster port. This one checks dependencies and display the options dialogs collectively only for those, which have OPTIONS changed *or* missing, which is something I understand you are looking for.


----------

