0

I have a Makefile that builds a shapefile as an intermediate steps.

.INTERMEDIATE : senate_boundaries.shp
senate_boundaries.shp : Senate\ shape\ files.zip
     unzip -j "$<"

A full shapefile comes with more than just a .shp, but also a .prj file, a .dbf file, and a bunch of others. These files are created when "Senate shape files.zip" is unzipped.

These other files are never an explicit target or dependency.

.INTERMEDIATE : senate_boundaries.prj senate_boundaries.dbf 

does not seem to do anything.

How can I tell Make to clean up these other files?

fgregg
  • 3,173
  • 30
  • 37
  • make doesn't know anything about them (even despite marking them `INTERMEDIATE`) so I'm not sure it should delete them from that. What generates the `.prj` and `.dbf` files? – Etan Reisner Apr 30 '15 at 16:47
  • They are in the zip file. – fgregg Apr 30 '15 at 17:02
  • The best I think you could do is use the feature of pattern rules described in the last paragraph [here](http://www.gnu.org/software/make/manual/make.html#Pattern-Examples) and then use something like `senate_boundarie%.shp senate_boundarie%.prj senate_boundarie%.dbf: Senate\ shape\ files.zip` which should have make handle them correctly. (Though you should really consider getting rid of the spaces in the zip file name make *really* doesn't do well with spaces in file names.) – Etan Reisner Apr 30 '15 at 17:09
  • 1
    Related: http://stackoverflow.com/questions/2973445/gnu-makefile-rule-generating-a-few-targets-from-a-single-source-file – fgregg May 01 '15 at 00:29

1 Answers1

1

You can add something like this to your recipe:

rm -f $(wildcard Senate\shape\*.prj)

But that will only work for that one file and you would have to manually add each extension to get rid of.

so something like this might do the trick:

rm -f $(shell ls Senate\shape\ | grep -v .shp&)

Another option is to unzip into a temp directory and then copy the file you want out and remove the the temp directory.

bentank
  • 616
  • 3
  • 7