From: George Foot Newsgroups: comp.os.msdos.djgpp Subject: Re: How do I do this with make? Date: 23 Jan 1998 23:35:24 GMT Organization: Oxford University, England Lines: 118 Message-ID: <6ab9fs$8a3$1@news.ox.ac.uk> References: <69nuae$492$1 AT star DOT cs DOT vu DOT nl> <6a805f$dij$1 AT news DOT ox DOT ac DOT uk> <6aac5a$7po$1 AT star DOT cs DOT vu DOT nl> NNTP-Posting-Host: sable.ox.ac.uk Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On 23 Jan 1998 15:14:50 GMT in comp.os.msdos.djgpp Ruiter de M wrote: : OK, now we got this working, does this thing also work if I want to do : this: : 10/%.jpg: %.pgm : same commands : 20/%.jpg: %.pgm : same commands : ... : 90/%.jpg: %.pgm : same commands : If so, how do I do it exactly? My guess (first part can be generated): : 10/%.jpg 20/%.jpg ... 90/%.jpg: %.pgm : same commands : But, if I remember well, the direction part is added automaticly to : the %.pgm and that is what I don't want. Hrm, so what you actually have is a sequence of commands to generate a .jpg file in a subdirectory from a .pgm file in the current directory? I don't really see what you're trying to do here, I'm afraid. Surely if you use the same set of commands to generate the files in each subdirectory, they'll all be the same? Or did you mean `some' commands, not `same' commands? If you did, see the addendum at the end of this message. You might be able to use $( VPATH = . > > .PHONY: all > > all: $(TARGETS) > > %.jpg: %.pgm > @echo "Make $@ from $<" > @touch $@ i.e. adapt what I said before so that it knows how to make %.jpg from %.pgm, use the VPATH variable to tell it to also look for dependencies in the current directory, and set TARGETS to the list of target files in the subdirectories. Provided each of these has a corresponding file in the current directory (or in the subdirectory) this makefile should be able to build them all. The `touch' isn't needed if you actually put a command to generate the file. I can't suggest what to put in the TARGETS variable because I don't understand what you want to do well enough. You could do a patsubst replacing %.pgm with %.jpg on all the files in the current directory, and addprefix the subdirectory names to that, but I don't know how you know which files should be in which subdirectories. : I can't test things right now, the files I want to process are at home : on a hard disk which `crashed' yesterday (all root-dir entries are : gone) :-(. Ouch, bad luck. It doesn't take too much thought, though, to write a makefile to echo the commands that would be run, and generate some dummy files -- it's how I tested the file above ;). ----- Addendum: If you meant `some commands', so that what you have is several ways of making .jpg files from .pgm files and you want to use all of these ways, putting the resulting .jpg files in different directories, this should be simpler. Use the VPATH system as I mentioned above, and generate your targets line like this: SOURCES := $(wildcard *.pgm) DIRS := 10 20 30 40 50 60 70 80 90 TARGETS := $(patsubst %.pgm, %.jpg, $(foreach dir, $(DIRS), $(addprefix $(dir)/, $(SOURCES)))) This replaces the `pgm' with `jpg' on all the source files, and appends each directory name to each file. So if you have foo.pgm and bar.pgm, you get: 10/bar.jpg 10/foo.jpg 20/bar.jpg 20/foo.jpg 30/bar.jpg ..... Then you just do exactly what you originally though to do -- make rules to generate 10/%.jpg from %.pgm, 20/%.jpg from %.pgm, etc. The complete makefile that I would suggest is listed at the end of this message, after my signature. -- george DOT foot AT merton DOT oxford DOT ac DOT uk ----- makefile ----- SOURCES := $(wildcard *.pgm) DIRS := 10 20 30 40 50 60 70 80 90 TARGETS := $(patsubst %.pgm, %.jpg, $(foreach dir, $(DIRS), $(addprefix $(dir)/, $(SOURCES)))) VPATH = . all: $(TARGETS) 10/%.jpg: %.pgm @echo "10: Make $@ from $<" @touch $@ 20/%.jpg: %.pgm @echo "20: Make $@ from $<" @touch $@ 30/%.jpg: %.pgm @echo "30: Make $@ from $<" @touch $@