help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: include question


From: Dill, John
Subject: RE: include question
Date: Fri, 10 Dec 2004 10:25:42 -0600

>> If you don't even want to try reading the file at all when it's already
>> been included, you have to put the ifndef around the include statement:
>> 
>>     ifndef _defs.mk
>>     include defs.mk
>>     endif
>
>IMO, blech.
>
>If one is adventurous, it's possible to create a function that, if the 
>makefile content >variable exists, evals it, otherwise, it does the actual 
>inclusion.  Then, all the
>included makefile does is to define this content variable and eval it.
>
>Since we're talking about included makefiles, I've noticed that a circular 
>inclusion is >detected.  What's the algorithm by which this is done?  I'd like 
>to implement the same
>algorithm in my include-maketfile function.
>
>Thanks,
>Noel

Here is something that I find useful for finding the necessary include files 
which define the functions I use in a implementation file which may be useful.  
It searches for the functions used by $(call name,...), and extracts the name 
of each called function.  Then does a recursive grep from a directory to find a 
file which defines that function.

I use this to guarantee that I find all the include files necessary when I have 
functions in separate files which build off each other.  When I get the 
inclusion guard implemented, it should reduce my maintenance/performance 
problems substantially.

Maybe someone else can benefit from it.
Best regards,
John

---------------------------------------------------------------------------------
left_paren:=(
right_paren:=)

# This function obtains the call functions from a file.
# $(1) - The file name.
custom_function_list=$(shell sed -ne '/$$$(left_paren)call /ba' -e '$$!b' -e 
':a' -e 's/$$$(left_paren)call \([^,$(right_paren)]*\),/<BEGIN>\1<END>/' -e 
'ta' -e 's/^/<BAD>/' -e ':b' -e 's/\(.*\)<BEGIN>\(.*\)<END>.*/\2 \1/' -e 'tb' 
-e 's/[ ]*<BAD>.*//' -e '$$!p' $(1) | tr ' ' '\n' | sort | uniq)

# This function obtains the files which define the functions specified.
# $(1) - The function list to search for.
# $(2) - The root directory to grep from.
function_include_file=$(foreach iter,$(1),$(shell grep -r '^$(iter)=' $(if 
$(strip $(2)),$(2),.)/* | sed 's/:.*//'))

# This function formats the output of the function include list.
# $(1) - The list of files.
format_include_list=$(shell echo '$(1)' | tr ' ' '\n' | sort | uniq)

FILE=
DIR=

default:
        $(if $(strip $(FILE)),,@echo "Usage: make FILE=<file> DIR=[dir] -f custo
m_function_dependency")
        @echo "File to search: $(FILE)"
        @echo "Custom function list: $(call custom_function_list,$(FILE))"
        @echo ""
        @echo "Directory to recursively search: $(DIR)"
        @echo "Function include list: $(call format_include_list,$(call function
_include_file,$(call custom_function_list,$(FILE)),$(DIR)))"
        @echo ""




reply via email to

[Prev in Thread] Current Thread [Next in Thread]