file versus identical symlink as a target?

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

file versus identical symlink as a target?

Robert P. J. Day-2

  i'm sure i will be embarrassed when i learn how simple the answer is
to this but here's a snippet of a makefile i'm dealing with:

===== start snippet =====

TOOL_SRC_DIR      := $(LOCAL_DIR)/$(PETALINUX_VERSION)
PETA_ARCHIVE      := $(LOCAL_DIR)/$(PETALINUX_VERSION).tar.gz
PETA_SRC_CFG_FILE := $(TOOL_SRC_DIR)/linux/settings.sh

# Runtime build variables
TOOL_DIR          := $(REPO_ROOT)
PETA_CFG_FILE     := $(TOOL_DIR)/linux/settings.sh
PETA_CFG          := source $(PETA_CFG_FILE)

prep := $(PROJECT_STAGE_DIR) $(PROJECT_OUTPUT_DIR)

$(TOOL_SRC_DIR):
        $(info docker building rules: $@)
        mkdir -p $@

$(PETA_ARCHIVE): | $(TOOL_SRC_DIR)
        $(info docker building rules: $@)
        curl -v -o $@ -O
"$(BASE_URL)/generic-local/$(PETALINUX_ARCHIVE_NAME)/${PETALINUX_VERSION}.tar.gz";

$(PETA_SRC_CFG_FILE): | $(PETA_ARCHIVE)
        $(info docker building rules: $@)
        tar -xf $(PETA_ARCHIVE) -C $(LOCAL_DIR)/$(PETALINUX_VERSION)

===== end snippet =====

  long story short, the above has a target of ${PETA_ARCHIVE), which
is the name of a sizable (7G) petalinux tarball that make expects to
find under the top-level local/ directory. if i git clone this
project, then manually create local/ and "cp" that tarball into
local/, make deems that rule satisfied, and proceeds to untar the
tarball without downloading it.

  if, however, i would rather create a symlink under local/ to the
tarball to avoid all that copying, make insists on downloading it
anyway.

  so, in summary, can a target be a symlink and, if so, how? thank you
kindly.

rday

--

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                         http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

Reply | Threaded
Open this post in threaded view
|

Re: file versus identical symlink as a target?

Paul Smith-20
On Fri, 2019-11-01 at 06:53 -0400, Robert P. J. Day wrote:
>   if, however, i would rather create a symlink under local/ to the
> tarball to avoid all that copying, make insists on downloading it
> anyway.
>
>   so, in summary, can a target be a symlink and, if so, how? thank you
> kindly.

Yes, sure.  The operating system handles symlinks invisibly to the program;
when make asks for the modification time of a symlink the operating system
returns the modification time of the file the link points to.  In fact, you
have to run a special, different system call to operate with the symlink
instead of the linked-to file: all the normal file operations always
resolve the symlink automatically.

Your problem is exactly that: when you create the symlink that doesn't
change the modification time of the thing being linked to, so it appears to
be still out of date.  When you copy the file locally, of course, its
modification time is updated.

You have two choices: you can either touch the file when you create a
symlink to it so that it appears up to date, or (if that's a problem for
example it's in a central shared location and you don't want to change it
because that breaks other makefiles) you can use GNU make's -L option
(added in GNU make 3.81) to have it treat the modification time of the
symlink separately from the modification time of the linked-to file.