Hi Paul :)

> Why doesn't it
> work?  It doesn't work because GNU make actually caches the contents of
> directories as it reads them, for performance reasons.

    I supposed that some caching was the cause, but for me was
reasonable that $wildcard will not expand if the new file wasn't
cached.

> If you make that file an explicit target, rather than a side-effect,
> _then_ it will work.

    In the real makefile, it is an implicit target. I will see if I
can make explicit targets, because now all affected files are
implicit ones (well, they match something as path/* and the like).
Otherwise I'll stick to the $(shell) solution.

>   >> Is this a bug or a feature?
>   jb> Feature.
> Maybe, maybe not.  But, not as straightforward as it seems at any rate :).

    Interesting ;))))

    Thanks a lot for your answer and explanation. Now I have things
clearer, Paul :))

    Note that this is a generated Makefile, part of a bigger proyect
not yet released, but since it is GPL and it may be dumber than I
think, I attach it so you can see what is all about. Feel free to
ignore and feel free to criticize it ;)) Currently you cannot do
'make install' without doing before 'make all' due to the $(wildcard)
function issue, but I'll fix ASAP ;))

    Ra�l
# *** Makefile *** Generated Makefile, PLEASE DON'T EDIT.
# ./0
#
#           This is a *generated* Makefile, please don't edit ;))
#             Copyright (C) 2002 Ra�l N��ez de Arenas Coronado
#
#        This program is free software; you can redistribute it and/or
#         modify it under the terms of the GNU General Public License
#                as published by the Free Software Foundation;
#                      either version 2 of the License,
#                   or (at your option) any later version.
#
#      This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty
#          of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#           See the GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License
#            ('GPL') along with this program; if not, write to:
#
#                      Free Software Foundation, Inc.
#                        59 Temple Place, Suite 330
#                        Boston, MA 02111-1307  USA
#
#                    Report bugs to <[EMAIL PROTECTED]>
#

.PHONY: all install help clean
.DELETE_ON_ERROR:
.SECONDARY:
.SUFFIXES:
.SUFFIXES:.c .o .h .d .a .so
.DEFAULT:;@:


# Convenience variables
override GOALS=
override XDEFS:=-DCONFDIR=\"/usr/local/etc/\" -DDATADIR=\"/usr/local/lib/vcinit/\" 
override OBJECTS=$(sort $(patsubst %.c, %.o, $(wildcard src/*.c lib/*.c)))
override DEPENDS=$(sort $(patsubst %.c, %.d, $(wildcard src/*.c lib/*.c bin/*.c 
sbin/*.c)))

# Goals to build
override GOALS+=$(if $(filter src/%.o, $(OBJECTS)),src/library.a)
override GOALS+=$(if $(filter lib/%.o, $(OBJECTS)),lib/libvcinit.a)
override GOALS+=$(if $(filter lib/%.o, $(OBJECTS)),lib/libvcinit.so)
override GOALS+=$(basename $(wildcard bin/*.c sbin/*.c))


all: $(GOALS)

# Misc functions for installation (David <[EMAIL PROTECTED]> and myself).
#   This function install files to their proper location (just *files*),
# logging the names of those installed files in the process...
install_files=\
$(foreach filename,$(wildcard $(1)),{\
        [ -d $(filename) ] || {\
                cp -f $(filename) $(2) > /dev/null 2>&1 || {\
                        printf "Couldn't install file \"$(filename)\", aborting.\n";\
                        exit 1;\
                };\
                chmod $(3) $(2)$(notdir $(filename));\
                printf "$(2)$(notdir $(filename))\n";\
        };\
};)

# This function creates installation directories
makedir=\
if [ ! -z "$(1)" ];\
then\
        [ -d "$(1)" ] || mkdir -m 755 -p "$(1)" > /dev/null 2>&1 || {\
                printf "Cannot create directory \"$(1)\", aborting...\n";\
                exit 1;\
        };\
fi


install: all
        @$(call makedir,/usr/local/)
        @$(call makedir,/usr/local/bin/)
        @$(call makedir,/usr/local/sbin/)
        @$(call makedir,/usr/local/lib/)
        @$(call makedir,/usr/local/man/man1)
        @$(call makedir,/usr/local/man/man5)
        @$(call makedir,/usr/local/man/man8)
        @$(call makedir,/usr/local/info/)
        @$(call makedir,/usr/local/doc/vcinit/)
        @$(call makedir,/usr/local/etc/)
        @$(call makedir,/usr/local/lib/vcinit/)
        @$(call makedir,/usr/local/include/vcinit/)
        @$(call install_files,$(filter bin/%, $(filter-out 
bin/_%,$(GOALS))),/usr/local/bin/,555)
        @$(call install_files,$(filter sbin/%, $(filter-out 
sbin/_%,$(GOALS))),/usr/local/sbin/,555)
        @$(call install_files,doc/*.1,/usr/local/man/,444)
        @$(call install_files,doc/*.8,/usr/local/man/,444)
        @$(call install_files,doc/*.5,/usr/local/man/,444)
        @$(call install_files,doc/*.info,/usr/local/info/,444)
        @$(call install_files,doc/*.html,/usr/local/doc/vcinit/,444)
        @$(call install_files,doc/*.txt,/usr/local/doc/vcinit/,444)
        @$(call install_files,include/*.h,/usr/local/include/vcinit/,444)
        @$(call install_files,lib/*.h,/usr/local/include/vcinit/,444)
        @$(call install_files,lib/libvcinit.a,/usr/local/lib/,444)
        @$(call install_files,lib/libvcinit.so,/usr/local/lib/,555)
        @if [ -e /usr/local/lib/libvcinit.so ] ;\
        then \
                ln -sf /usr/local/lib/libvcinit.so /usr/local/lib/libvcinit.so.1 ;\
                printf "/usr/local/lib/libvcinit.so.1\n" ;\
        fi
        @$(foreach filename,$(wildcard conf/*), \
                { \
                        [ -f /usr/local/etc/$(notdir $(filename)) ] && \
                        mv -f /usr/local/etc/$(notdir $(filename)) \
                                /usr/local/etc/$(notdir $(filename))~ \
                        > /dev/null 2>&1;\
                } || true ;     )
        @$(call install_files,conf/*,/usr/local/etc/,644)
        @if [ -e data/Makefile ] ;\
        then \
                $(MAKE) -C data -f Makefile DATADIR=/usr/local/lib/vcinit/ ;\
        else \
                $(call install_files,data/*,/usr/local/lib/vcinit/,444) true ;\
        fi
        @rmdir -p \
                /usr/local/ /usr/local/bin/ /usr/local/sbin/ \
                /usr/local/man/man1 /usr/local/man/man8 /usr/local/man/man5 
/usr/local/man/ \
                /usr/local/info/ /usr/local/doc/vcinit/ /usr/local/etc/ 
/usr/local/lib/vcinit/ /usr/local/lib/ /usr/local/include/vcinit/ \
                > /dev/null 2>&1 || true


help:
        @printf "\n"
        @printf " Run the command 'make <target>' for doing what you want ;)\n"
        @printf " Those are the available make targets (default is 'all'):\n"
        @printf "\n"
        @printf "       all - Builds the package\n"
        @printf "   install - Installs the package (building if necessary)\n"
        @printf "     clean - Cleans the build tree\n"
        @printf " distclean - Cleans the build tree for distribution\n"
        @printf "      help - Shows this help\n"
        @printf "\n"


clean:
        @printf "Removing core files... " >&2 ; rm -f core bin/core sbin/core src/core 
> /dev/null 2>&1 ; printf "done.\n" >&2
        @printf "Removing object files... "  >&2 ; rm -f $(OBJECTS) bin/*.o sbin/*.o > 
/dev/null 2>&1 ; printf "done.\n" >&2
        @printf "Removing project goals and dependencies... "  >&2 ; rm -f $(GOALS) 
$(DEPENDS) > /dev/null 2>&1 ; printf "done.\n" >&2

distclean: clean
        @printf "Removing generated files... "  >&2 ; rm -f Makefile debug.h  > 
/dev/null 2>&1 ; printf "done.\n" >&2
        @printf "Removing empty directories... "  >&2 ; rmdir *  > /dev/null 2>&1 ; 
printf "done.\n"  >&2

# Clean and modify some variables
override IDIRS:=$(sort $(filter-out -I%, ))
override IDIRS:=$(patsubst %, -I%, src lib include bin sbin . $(IDIRS))
override LDIRS:=$(sort $(filter-out -L%, ))
override LDIRS:=$(patsubst %, -L%, $(LDIRS))
override LIBES:=$(sort $(filter lib%, libcrypt))
override LIBES:=$(patsubst lib%, -l%, $(LIBES))
override CDEFS:=$(sort $(filter-out -D%, ))
override CDEFS:=$(patsubst %, -D%, $(CDEFS))


## Flags ##
override CFLAGS+=$(IDIRS) $(CDEFS) $(XDEFS)  
override CFLAGS+=-Wall -W $(sort )  -DNDEBUG -UTEST -O2
override CFLAGS+=-DPROJECT=\"vcinit\" -DVERSION=\"1.0rc9\"
override LDFLAGS+=$(LDIRS) $(LIBES) -s  


## Implicit rules
src/%.o: src/%.c src/%.d Makefile
        @printf "Compiling object '$(notdir $@)'\n" >&2
        @/usr/bin/gcc $(CFLAGS) -MD -MP -DOBJNAME=\"$(basename $(notdir $@))\" -c -o 
$@ $<

lib/%.o: lib/%.c lib/%.d Makefile
        @printf "Compiling library object '$(notdir $@)'\n" >&2
        @/usr/bin/gcc $(CFLAGS) -fPIC -DPIC -MD -MP -DOBJNAME=\"$(basename $(notdir 
$@))\" -c -o $@ $<

bin/%.o: bin/%.c bin/%.d Makefile
        @printf "Compiling binary '$(notdir $@)'\n" >&2
        @/usr/bin/gcc $(CFLAGS) -MD -MP -DOBJNAME=\"$(basename $(notdir $@))\" -c -o 
$@ $<

bin/%: bin/%.o $(filter %.a,$(GOALS))
        @printf "Linking binary '$(notdir $@)'\n" >&2
        @/usr/bin/gcc $(LDFLAGS) -o $@ $^

sbin/%.o: sbin/%.c sbin/%.d Makefile
        @printf "Compiling system binary '$(notdir $@)'\n" >&2
        @/usr/bin/gcc $(CFLAGS) -MD -MP -DOBJNAME=\"$(basename $(notdir $@))\" -c -o 
$@ $<

sbin/%: sbin/%.o $(filter %.a,$(GOALS))
        @printf "Linking system binary '$(notdir $@)'\n" >&2
        @/usr/bin/gcc $(LDFLAGS) -o $@ $^

src/library.a: $(filter src/%,$(OBJECTS))
        @printf "Creating private library\n" >&2
        @/usr/bin/ar rcsu $@ $^

lib/libvcinit.a: $(filter lib/%,$(OBJECTS))
        @printf "Creating static library '$(notdir $@)'\n" >&2
        @/usr/bin/ar rcsu $@ $^

lib/libvcinit.so: $(filter lib/%,$(OBJECTS))
        @printf "Creating shared library '$(notdir $@)'\n" >&2
        @/usr/bin/gcc $(LDFLAGS) -o $@ -shared -Wl,-soname -Wl,libvcinit.so.1 $^

Makefile:;@:


## Dependencies
ifneq ($(DEPENDS),)
-include $(DEPENDS)
endif

_______________________________________________
Bug-make mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-make

Reply via email to