Environment Variable to Customize .INCLUDE_DIRS

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Environment Variable to Customize .INCLUDE_DIRS

Afif Elghraoui
Hello,
I'm looking for a way to be able to store custom makefile rules in
special folders.
I see that the Makefile variable .INCLUDE_DIRS is set to "/usr/include
/usr/local/include /usr/include" on my machine by default, but is there
an environment variable I can set to add different directories (like
$HOME/include) in the same
way that can be done for CPATH, LIBRARY_PATH, and MANPATH for other things?

I know that i can also pass in a custom include path on the command
line, but I would like to have some files with generic rules that I can
include without any special command line invocation or hardcoding the
absolute path.

Thanks and regards
Afif

--
Afif Elghraoui
Laboratory for Pathogenesis of Clinical Drug Resistance and Persistence
San Diego State University
Alvarado Medical Center
6367 Alvarado Court, Suite 206
San Diego, CA 92120
p. 858-222-0454
http://tuberculosis.sdsu.edu


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variable to Customize .INCLUDE_DIRS

Rakesh Sharma-6
Afif Elghraoui <aelghraoui <at> sdsu.edu> writes:

>
> Hello,
> I'm looking for a way to be able to store custom makefile rules in
> special folders.
> I see that the Makefile variable .INCLUDE_DIRS is set to "/usr/include
> /usr/local/include /usr/include" on my machine by default, but is there
> an environment variable I can set to add different directories (like
> $HOME/include) in the same
> way that can be done for CPATH, LIBRARY_PATH, and MANPATH for other
things?
>
> I know that i can also pass in a custom include path on the command
> line, but I would like to have some files with generic rules that I can
> include without any special command line invocation or hardcoding the
> absolute path.
>
> Thanks and regards
> Afif
>

.INCLUDE_DIRS is a readonly construct in GNU make, so you can't take that
route to do what you are intending. However, all's not lost; say your
environment variable is INC_LOCAL, then do this in your makefile:

# these are the makefiles you want included (YMMV)
INC_MKS := a.mk junk.mk

INC_DEFAULT_MKS :=#

ifneq '$(INC_LOCAL)' ''
INC_LOCAL_MKS := $(foreach i,$(INC_MKS),$(if $(wildcard
$(INC_LOCAL)/$i),$(wildcard $(INC_LOCAL)/$i),$(eval INC_DEFAULT_MKS += $i)))
else
INC_DEFAULT_MKS := $(INC_MKS)
endif

include $(INC_LOCAL_MKS) $(INC_DEFAULT_MKS)

$(info list=$(INC_MKS))
$(info makefiles loaded from the env variable  =$(INC_LOCAL_MKS))
$(info makefiles loaded from the default paths =$(INC_DEFAULT_MKS))



_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variable to Customize .INCLUDE_DIRS

Steven Simpson
In reply to this post by Afif Elghraoui
On 22/01/16 16:57, Afif Elghraoui wrote:
> I know that i can also pass in a custom include path on the command
> line, but I would like to have some files with generic rules that I
> can include without any special command line invocation or hardcoding
> the absolute path.

I keep a bash function in ~/.bash_aliases to transform the value of
$MAKEPATH into a series of -I switches:

function make_with_path () {
     local EXTRAS
     local index=1
     local copy="$MAKEPATH"
     local old
     while [ -n "$copy" ] ; do
         EXTRAS=("${EXTRAS[@]}" -I "${copy%%:*}")
         old="$copy"
         copy="${copy#*:}"
         if [ "$old" == "$copy" ] ; then break ; fi
     done
     `which make` "${EXTRAS[@]}" "$@"
}

alias make=make_with_path

It has been known to break some things occasionally, for which I have to
unalias make.


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variable to Customize .INCLUDE_DIRS

Rakesh Sharma-6
In reply to this post by Afif Elghraoui
Afif Elghraoui <aelghraoui <at> sdsu.edu> writes:

>
> Hello,
> I'm looking for a way to be able to store custom makefile rules in
> special folders.
> I see that the Makefile variable .INCLUDE_DIRS is set to "/usr/include
> /usr/local/include /usr/include" on my machine by default, but is there
> an environment variable I can set to add different directories (like
> $HOME/include) in the same
> way that can be done for CPATH, LIBRARY_PATH, and MANPATH for other
things?
>
> I know that i can also pass in a custom include path on the command
> line, but I would like to have some files with generic rules that I can
> include without any special command line invocation or hardcoding the
> absolute path.
>
> Thanks and regards
> Afif
>

If you use GNU make, then you can even roll your own function to include the
generic rules makefiles, like as,

(assume that the env variable IPATH holds the list of custom/local include
dirs, e.g., $HOME/local/include, etc.)
***** Note: dirs in IPATH are SPACE separated and not COLON ******


# $(call local_include,$1)
define local_include
include $(strip
   $(if $(IPATH),\
      $(foreach f,$1,\
         $(strip \
            $(eval k :=)\
            $(foreach d,$(IPATH),\
               $(if $k,,\
                  $(if $(wildcard $d/$f),\
                     $(strip $(wildcard $d/$f)$(eval k += .))\
                  )\
               )\
            )\
            $(if $k,,$f)\
         )\
      ),\
      $1\
   )\
)
endef


# put the names of all your generic rules files here
GENERIC_RULES := f1.mk junk.mk f4.mk

# now have them included from the custom path IPATH
# in case found, otherwise attempt from the default
i$(eval $(call local_include,$(GENERIC_RULES)))

# take a look at where from each of the generic rules
# was picked up from...
$(info generic rules list=$(INC_MKS))
$(info generic rules coming from:$(MAKEFILE_LIST))
####################################################


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variable to Customize .INCLUDE_DIRS

Afif Elghraoui
In reply to this post by Afif Elghraoui
Many thanks for the responses, but there should have been more to my
post than what I originally wrote, since this was an email draft I
started a long time ago.

على الجمعـة 22 كانون الثاني 2016 ‫08:57، كتب Afif Elghraoui:
> I'm looking for a way to be able to store custom makefile rules in
> special folders.
> I see that the Makefile variable .INCLUDE_DIRS is set to "/usr/include
> /usr/local/include /usr/include" on my machine by default, but is there
> an environment variable I can set to add different directories (like
> $HOME/include) in the same
> way that can be done for CPATH, LIBRARY_PATH, and MANPATH for other things?
>

So it looks like the answer to this is currently no.

> I know that i can also pass in a custom include path on the command
> line, but I would like to have some files with generic rules that I can
> include without any special command line invocation or hardcoding the
> absolute path.
>

I think adding official support for a search path environment variable
would be a good thing for Make. I think it would help encourage people
to develop and release Make libraries that build on top of each other if
the include search path could be trusted to include all necessary
locations across different sites. It's fair to expect an environment
variable would be maintained since people already do it for PATH,
MANPATH, and such.

Please consider this a feature request-- I originally posted on
help-make because I wanted to make sure that this feature didn't already
exist and I'd missed it in the manual.

Many thanks and regards
Afif

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variable to Customize .INCLUDE_DIRS

Afif Elghraoui
In reply to this post by Afif Elghraoui
Based on Paul Smith's comment in #47880 [1], there's a pretty simple
solution to this problem. Adding something like the following to
~/.bashrc would do the trick:


MAKELIBS="$HOME/.local/include /other/include"
for path in $MAKELIBS
do
     MAKEFLAGS+="-I$path"
done
export MAKEFLAGS

regards
Afif

1. http://savannah.gnu.org/bugs/?47880#comment1


On 01/22/2016 08:57 AM, Afif Elghraoui wrote:

> Hello,
> I'm looking for a way to be able to store custom makefile rules in
> special folders.
> I see that the Makefile variable .INCLUDE_DIRS is set to "/usr/include
> /usr/local/include /usr/include" on my machine by default, but is
> there an environment variable I can set to add different directories
> (like $HOME/include) in the same
> way that can be done for CPATH, LIBRARY_PATH, and MANPATH for other
> things?
>
> I know that i can also pass in a custom include path on the command
> line, but I would like to have some files with generic rules that I
> can include without any special command line invocation or hardcoding
> the absolute path.
>
> Thanks and regards
> Afif
>


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variable to Customize .INCLUDE_DIRS

Paul Smith-20
On Wed, 2016-05-25 at 11:20 -0700, Afif Elghraoui wrote:

> Based on Paul Smith's comment in #47880 [1], there's a pretty simple 
> solution to this problem. Adding something like the following to 
> ~/.bashrc would do the trick:
>
>
> MAKELIBS="$HOME/.local/include /other/include"
> for path in $MAKELIBS
> do
>      MAKEFLAGS+="-I$path"
> done
> export MAKEFLAGS

That is not valid shell syntax, plus the quoting is not ideal.  You want
something like:

> for path in "$HOME/.local/include" /other/include
> do
>      MAKEFLAGS="$MAKEFLAGS -I$path"
> done
> export MAKEFLAGS

But yes, that's the basic idea.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make