Beginner Question: Best way to substitute variables
Florent Thoumie
flz at xbsd.org
Thu Dec 30 13:58:04 PST 2004
Frank Behrens a écrit :
> Meanwhile I use FreeBSD for several years and now comes the time to
> give something back. I'm creating a port and could not find an answer
> to my question:
>
> What is the best way to set variables in scripts (e.g. pkg-install)
> and text files (e.g. pkg-message) depending from Makefile variables
> (e.g. PREFIX)?
> I understand the Makefile rules and it is no problem to use variable
> paths depending from $PREFIX, $DOCSDIR and other, but how they are
> later used in scripts, like pkg-install and rc.d/scripts? IMHO
> changing these and other variables in the Makefile should be enough
> to adjust the complete port.
>
> As a possible solution I see:
> Put all files in a separate directory, create Makefile dependencies
> and replace the desired strings with "sed". But this seems to be not
> the usual way, I could not find any example port.
>
> Please, could you point me to an example port, where this problem has
> been solved in a practical way conform to FreeBSd development rules.
The question is some weeks old now but I think I can add some
piece of answer to the thread.
Recently, 2 new variables appeared in bsd.port.mk that handles
this kind of situation for you. See SUB_FILES and SUB_LIST in
Mk/bsd.port.mk and net/bnbt or net/ldapsh for examples.
Basically, you put file.in in ${FILESDIR} and set SUB_FILES=file.
Substitution works like with pkg-plist, you can use %%VAR%% and
it'll be replaced automagically. Some variables are added by default
to SUB_LIST but you can add some (eg. SUB_LIST= RC_SUBR=$RC_SUBR).
I began to wrote some documentation to add to the PH but I accidentally
lost it. I'll try to do this ASAP.
Best Regards.
--
Florent Thoumie
flz at xbsd.org
More information about the freebsd-ports
mailing list