Search code examples
makefilesymlinkflags

Symlinks and make flags in chain of Makefiles


I'm using a Makefile to copy files and symlinks from a source directory structure into a target directory that will eventually be made into a filesystem image. The idea is to get the relative path of each file or symlink using find, then add the appropriate path prefix's to create the source and destination paths for a cp -a.

CW_SOURCES := $(patsubst %,$(SOURCE)/%,$(shell find $(LOCAL_PATH)/filesystem -type f -o -type l))
CW_DESTS   := $(subst $(SOURCE)/$(LOCAL_PATH)/filesystem,$(TARGET),$(CW_SOURCES))

$(CW_DESTS): $(TARGET)/% : $(SOURCE)/$(LOCAL_PATH)/filesystem/%
    @echo $< to $@
    $(eval CW_DIR := $(dir $@))
    mkdir -p $(CW_DIR)
    cp -a $< $@

This works fine, so long as I invoke make with

make --check-symlink-times all,
make -L all,

otherwise make doesn't treat the symlinks as objects in and of themselves, but as missing dependencies (because the symlinks don't necessarily point to anything real at this point).

Please don't tell me that symlinks are not compatible across all platforms make runs on, I know that.

So the problem is that this Makefile is run somewhere down the line in a long list of Makefiles calling one another, so I can't call make with the flag that it needs for this one Makefile.

Just wondering if anyone sees a way around this problem other than the obvious (the obvious being don't treat the symlinks as targets and just copy them every time). Several global variables that are defined in other Makefiles up the chain also need to be available to this Makefile.


Solution

  • You can modify the MAKEFLAGS variable at the top of the makefile:

    MAKEFLAGS += -L