Hacker News new | ask | show | jobs
by mturmon 1177 days ago
Here's one way to do this.

I have used this method (directory mod-time triggering, let's say) for a simulation-summarizer which analyzes whatever pile of simulation-output-files happen to be in a given directory. If you run a new simulation, the directory changes and the analysis is re-done by running "make".

I used the Gnu make $(wildcard ...) for the template expansion, instead of using shell expansion. This is to take care of the no-file case, so that jsons/*.json will expand to nothing rather than to the literal jsons/*.json (which does not exist).

  $ cat Makefile 
  file.out: jsons
         cat $(wildcard jsons/*.json) /dev/null > file.out
  
  
  $ ls -R
  Makefile  jsons/
  
  ./jsons:
  foo.json
  
  $ make
  cat jsons/foo.json /dev/null > file.out
  
  $ make   # no file mods => no-op
  make: `file.out' is up to date.  
  
  $ touch jsons/bar.json
  
  $ make   # new file => re-make
  cat jsons/bar.json jsons/foo.json /dev/null > file.out
  
  $ make     
  make: `file.out' is up to date.
  
  $ rm jsons/foo.json 
  
  $ make  # deletion => re-make
  cat jsons/bar.json /dev/null > file.out
  
  $ rm jsons/bar.json 
  
  $ make  # nothing there
  cat  /dev/null > file.out
  
  $ make
  make: `file.out' is up to date.