help-make
[Top][All Lists]
Advanced

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

list of current sources in single-makefile project?


From: gk
Subject: list of current sources in single-makefile project?
Date: Wed, 06 Nov 2002 14:46:08 -0800

What is the recommended and most efficient way of getting a current list of source files for an entire project?

My system is a single makefile, which includes makefiles in subdirectories.

To minimize pattern substitutions, etc. on every invocation of make, my thought was to auto-generate a makefile in each directory with the list of source files in that directory and have the directory be a prerequisite of the makefile so it will only be updated when the directory contents change.

Are there any gotchas when using directories as prerequisites? Does make handle them the same as regular files?
So far this seems to be working well.
Here is my makefile. Comments appreciated.

.SUFFIXES:
SUBDIRS:=$(shell find -type d -name "*")
SOURCE_MAKEFILE:=SOURCE.mk
SRCFILE_PATTERNS:=*.c *.h
OUTFILE_PATTERNS:=$(SOURCE_MAKEFILE) *.o
ABS_SRCFILE_PATTERNS:=$(patsubst %, $$dir/%, $(SRCFILE_PATTERNS))
ABS_OUTFILE_PATTERNS:=$(patsubst %, $$dir/%, $(OUTFILE_PATTERNS))
# initialize SOURCES and OUTFILES as simply expanded variables so that += works in included makefiles
SOURCES:=
OUTFILES:=
SOURCE_MAKEFILES:= $(CURDIR)/$(SOURCE_MAKEFILE) $(patsubst .%, $(CURDIR)%/$(SOURCE_MAKEFILE), $(SUBDIRS))
-include $(SOURCE_MAKEFILES)

.PHONY: sources clean debug
sources:
        @echo SOURCES=$(SOURCES)

# empty line is needed prior to echo 'OUTFILES+=\' since preceding line ends with backslash
%/$(SOURCE_MAKEFILE) : % Makefile
        @echo making $@
        @dir=$<;\
        echo 'SOURCES+=\' > $@;\
        ls -1 $(ABS_SRCFILE_PATTERNS) 2>/dev/null|xargs -i echo {} \\ >> $@;\
        echo >> $@; \
        echo 'OUTFILES+=\' >> $@;\
        ls -1 $(ABS_OUTFILE_PATTERNS) 2>/dev/null|xargs -i echo {} \\ >> $@;\

Makefile: ;     

# remove output files in the current directory
clean:
        @echo $@
        @echo deleted files in $(CURDIR):;\
        echo $(OUTFILE_PATTERNS)
        @#rm -f $(OUTFILE_PATTERNS)

debug:
        @echo SUBDIRS=$(SUBDIRS)
        @echo SOURCE_MAKEFILES=$(SOURCE_MAKEFILES)
        @echo SOURCES=$(SOURCES)
        @echo OUTFILES=$(OUTFILES)
        @echo ABS_SRCFILE_PATTERNS='$(ABS_SRCFILE_PATTERNS)'
        @echo ABS_OUTFILE_PATTERNS='$(ABS_OUTFILE_PATTERNS)'





reply via email to

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