LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-10-2011, 06:28 PM   #1
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 67
make vpath and implicit rules: error


I'm having trouble with vpath and implicit rules

Code:
INCLUDE_DIR = inc

INKSCAPE  ?= inkscape
CONVERT   ?= convert

vpath %.png $(INCLUDE_DIR)
vpath %.svg $(INCLUDE_DIR)

.PHONY: all clean allclean

clean:
	$(RM) *.aux *.bbl *.blg *.dvi *.log *.out *.nav *.snm *.toc *.vrb *~
	$(RM) $(INCLUDE_DIR)/*.png

# figures

%.png: %.svg
	$(INKSCAPE) -e $(INCLUDE_DIR)/$@ $<

%-g.png: %.png
	$(CONVERT) -colorspace gray $< $(INCLUDE_DIR)/$@
I have a folder called "inc" with a bunch of .svg files. I have a rule for converting the .svg into a .png and a rule for converting the .png into a grayscale -g.png.

The problem is that making the grayscale PNGs won't always work because make seems to expand all of the recipes at once.

so in a clean working directory
Code:
$ make example-g.png
will expand the implicit targets to
Code:
example.png: inc/example.svg
example-g.png: example.png
but if I first do
Code:
$ make example.png
then making the grayscale png will result in the following make rule
Code:
example-g.png: inc/example.png
Is there a fix for this?
 
Old 12-10-2011, 10:24 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Code:
%.png: %.svg
	$(INKSCAPE) -e $(INCLUDE_DIR)/$@ $<

%-g.png: %.png
	$(CONVERT) -colorspace gray $< $(INCLUDE_DIR)/$@
These rules are incorrect, you have to tell make the correct path to the generated file:

Code:
$(INCLUDE_DIR)/%.png: %.svg
	$(INKSCAPE) -e $@ $<

$(INCLUDE_DIR)/%-g.png: %.png
	$(CONVERT) -colorspace gray $< $@
It's the same problem as this thread.
 
Old 12-10-2011, 10:26 PM   #3
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Original Poster
Rep: Reputation: 67
Ah, so it's not really incorrect, but a limitation of make...

Last edited by Meson; 12-10-2011 at 10:57 PM. Reason: oops
 
Old 12-10-2011, 11:26 PM   #4
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Original Poster
Rep: Reputation: 67
For anyone passing by. I wanted to preserve the bash-completion of the png files without the dirname, so what I did was:

Code:
%-g.png: %.png
        [[ -f $< ]] && prereq=$< || prereq=$(INCLUDE_DIR)/$<; \
        $(CONVERT) -colorspace gray $$prereq $(INCLUDE_DIR)/$@
I'm not sure if there's a more elegant way to do this.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] error "mixed implicit and normal rules" while trying to build busybox Keith Hedger Linux - Software 7 01-02-2015 11:24 PM
Make-3.82 error:Makefile:282:error: mixed implicit and normal rules Ramanc51 Linux - Newbie 5 06-08-2011 07:55 AM
VPATH mechanism in make file sonu kumar Linux - Newbie 1 01-11-2010 11:42 AM
about makefile using implicit rules lswhbcb Programming 8 05-19-2007 10:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration