1

How does one recursively copy files in Make? I'd like to make this as platform-neutral; in particular, I need this to work on plain Windows (no cp -r, no rsync, no cygwin, no Interix, etc.) and I would like for it to work in Linux with minimal changes (no robocopy, no xcopy/xcopy32). The environment where I work is very Windows-centric, and I'd like to make it possible for us to move to a Unix/Unix-like environment. Ideally, this should be standalone (few external dependencies), and it should only copy the files if they don't exist in the destination or the files in the destination are older than the source files.

Objective: Recursively walk ${SOURCE} and copy to analgous locations in ${DESTINATION} if the file doesn't exist or the corresponding file in ${DESTINATION} is older than the source.

I've seen How to copy a directory in a Makefile? and Recursive wildcards in GNU make?, but the solutions will not work in the Windows-centric environment where I work.

Community
  • 1
  • 1
user314104
  • 1,528
  • 14
  • 31
  • Have you considered using `tar`? By default, it won't overwrite newer files with older ones, so it might do the job you're after. It may depend on whether you can use one of the Unix workalike systems on Windows. – Jonathan Leffler Nov 20 '11 at 03:02
  • Stock installations of Windows do not have `tar`. – user314104 Nov 20 '11 at 05:12
  • 3
    Stock installations of Windows do not have `make` either, so you're equipping the machine to do development; add the tools you need to make it work. – Jonathan Leffler Nov 20 '11 at 16:43
  • I'd love to. But the automation tools that we have suck in this respect; it only pulls a single executable and runs it with its notion of what's on the command line. If I could have it my way at work, the automation tool stack would use Apache Ant. – user314104 Nov 20 '11 at 18:20

1 Answers1

2

make itself doesn't even have the capability to copy a single file. You will need to use some external program to do this. I don't believe any one suitable program exists out of the box on both Linux and Windows.

slowdog
  • 6,076
  • 2
  • 27
  • 30
  • 1
    +1. I'd like to add a stronger (and probably controversial) corollary here: `make` is no reimplementation of an operating system, unlike `ant`. `make` is an automation tool for shell scripts. There is no way to make it work well for backwater operating systems like non-cygwin Windows, so the sooner you drop the idea, the better. – thiton Nov 21 '11 at 11:45