Solved How to check wheter a variable is defined in a makefile externally

I need to check if a variable is defined inside a makefile file executing the command make. For example, to get the value for a makefile variable I can run the command
Code:
% make -C /usr/ports/misc/mc -V WRKDIR
/usr/ports/misc/mc/work
%
if the variable is empty or not defined the command returns an empty string, for example
Code:
% make -C /usr/ports/misc/mc -V FORBIDDEN

%
make returns an empty string and exit code 0 (FORBIDDEN is not defined for misc/mc port)
 
In search engine I found how to check inside a makefile but not using (FreeBSD) make command. I want to run make command to check variable in a javascript (node) script, I can only check stdout and exit code.
 
The variables to check are in ports tree makefiles, the FORBIDDEN variable is used as a definition. In the file /usr/ports/Mk/bsd.port.mk it is tested in this way:
Code:
.      elif defined(FORBIDDEN)
IGNORE=        is forbidden: ${FORBIDDEN}
.      endif
only for definition.
 
you can also do this directly with make -V:

Code:
% make -C /usr/ports/misc/mc -V'${defined(FORBIDDEN):?1:0}'
0
% make -C /usr/ports/misc/mc -V'${defined(COMMENT):?1:0}'
1
This way there is no pipe, it is more direct and on stdout. For me it's better, I can ask variables in one make call:
Code:
% make -C /usr/ports/misc/mc -V COMMENT -V DESCR -V PKGBASE -V PKGVERSION -V '${defined(FORBIDDEN):?1:0}' -V '${defined(BROKEN):?1:0}'
Midnight Commander, a free Norton Commander clone
/usr/ports/misc/mc/pkg-descr
mc
4.8.32
0
0
This is what I am looking for. Thanks
 
Back
Top