1# -*- Makefile -*-
2# $Id: xfig.mk.in.in,v 1.14 2010/03/12 21:21:41 dan Exp $
3#
4# Makefile fragment for processing xfig files to produce postscript
5#
6# Copyright (c) 2002, 2003, 2004, 2005, 2006 Dan McMahill
7# All rights reserved.
8#
9# This code is derived from software written by Dan McMahill
10#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions
13# are met:
14# 1. Redistributions of source code must retain the above copyright
15#    notice, this list of conditions and the following disclaimer.
16# 2. Redistributions in binary form must reproduce the above copyright
17#    notice, this list of conditions and the following disclaimer in the
18#    documentation and/or other materials provided with the distribution.
19# 3. All advertising materials mentioning features or use of this software
20#    must display the following acknowledgement:
21#        This product includes software developed by Dan McMahill
22#  4. The name of the author may not be used to endorse or promote products
23#     derived from this software without specific prior written permission.
24#
25#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26#  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27#  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28#  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30#  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32#  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33#  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35#  SUCH DAMAGE.
36#
37
38
39#######################################
40#
41# README:
42#
43# To use this makefile fragment, set the variable:
44#	XFIGSRCS	= the xfig drawing files (.fig files)
45# in your top level Makefile.  You can also specify
46# XFIGDIRS which is a list of directories containing
47# xfig files.  All xfig files in the specified directories
48# are added to XFIGSRCS
49#
50# The following variables may be overridden in your top level Makefile
51#
52#  FIG2DEV		= the fig2dev executable
53#  FIG2DEV_FLAGS	= flags passed to fig2dev for all exporting
54#  FIG2DEV_EPS_FLAGS	= flags passed to fig2dev for exporting to eps
55#  FIG2DEV_PDF_FLAGS	= flags passed to fig2dev for exporting to pdf
56#
57#######################################
58
59
60# how to call fig2dev to convert xfig files to postscript
61FIG2DEV?=		@FIG2DEV@
62FIG2DEV_FLAGS?=
63FIG2DEV_EPS_FLAGS?=	-L eps
64FIG2DEV_PDF_FLAGS?=	-L pdf
65
66#######################################
67#
68# Process XFIGDIRS, adding to XFIGSRCS
69#
70#######################################
71
72BMK:.if defined(XFIGDIRS)
73BMK:.for __tmp__ in ${XFIGDIRS}
74BMK:.if exists(${__tmp__})
75BMK:_XFIG_ADD_${__tmp__}!=	ls ${__tmp__}/*.fig
76BMK:XFIGSRCS+=	${_XFIG_ADD_${__tmp__}}
77BMK:.endif
78BMK:.endfor
79BMK:.endif
80
81GMK:ifdef XFIGDIRS
82GMK:XFIGSRCS+= $(foreach __tmp__,$(XFIGDIRS),$(wildcard $(__tmp__)/*.fig))
83GMK:endif
84
85#######################################
86#
87# Process proj_XFIGDIRS, adding to proj_XFIGSRCS
88#
89#######################################
90
91BMK:.for __name__ in ${NAME}
92BMK:.if defined(${__name__}_XFIGDIRS)
93BMK:.for __tmp__ in ${${__name__}_XFIGDIRS}
94BMK:.if exists(${__tmp__})
95BMK:_XFIG_ADD2_${__tmp__}!=	ls ${__tmp__}/*.fig
96BMK:${__name__}_XFIGSRCS+=	${_XFIG_ADD2_${__tmp__}}
97BMK:.endif
98BMK:.endfor
99BMK:.endif
100BMK:.endfor
101
102GMK:define xfigdirs_template
103GMK:ifdef $(1)_XFIGDIRS
104GMK:$(1)_XFIGSRCS+= $(foreach __tmp2__,$($(1)_XFIGDIRS),$(wildcard $(__tmp2__)/*.fig))
105GMK:endif
106GMK:endef
107GMK:$(foreach __tmp__,$(NAME),$(eval $(call xfigdirs_template,$(__tmp__))))
108
109#######################################
110#
111# Process proj_XFIGSRCS to add to
112# proj_OTHER dependencies
113#
114#######################################
115
116# if we are using pdflatex, then don't bother with the .eps files
117# but create .pdf files instead
118
119BMK:.if defined(USE_PDFLATEX)
120GMK:ifdef USE_PDFLATEX
121XFIGOBJS?=	$(XFIGSRCS:.fig=.pdf)
122BMK:.else
123GMK:else
124XFIGOBJS?=	$(XFIGSRCS:.fig=.eps)
125BMK:.endif
126GMK:endif
127ALLXFIGOBJS+=	$(XFIGOBJS)
128
129BMK:.for __tmp__ in ${NAME}
130BMK:.if defined(${__tmp__}_XFIGSRCS)
131BMK:.if defined(USE_PDFLATEX)
132BMK:${__tmp__}_XFIGOBJS?=	${${__tmp__}_XFIGSRCS:.fig=.pdf}
133BMK:.else
134BMK:${__tmp__}_XFIGOBJS?=	${${__tmp__}_XFIGSRCS:.fig=.eps}
135BMK:.endif
136BMK:${__tmp__}_OTHER+=	${${__tmp__}_XFIGOBJS}
137BMK:ALLXFIGOBJS+=	${${__tmp__}_XFIGOBJS}
138BMK:.endif
139BMK:${__tmp__}_DIST+=	${${__tmp__}_XFIGSRCS} ${XFIGSRCS}
140BMK:.endfor
141
142GMK:# note, this had to be done in two steps (create proj_XFIGOBJS,
143GMK:# and then add to proj_OTHER and ALLXFIGOBJS) with GNU make 3.80
144GMK:# don't really know why.
145GMK:define xfigobjs_template
146GMK:ifdef $(1)_XFIGSRCS
147GMK:ifdef USE_PDFLATEX
148GMK:$(1)_XFIGOBJS?=	${$(1)_XFIGSRCS:.fig=.pdf}
149GMK:else
150GMK:$(1)_XFIGOBJS?=	${$(1)_XFIGSRCS:.fig=.eps}
151GMK:endif
152GMK:endif
153GMK:$(1)_DIST+=		${$(1)_XFIGSRCS}  ${XFIGSRCS}
154GMK:endef
155GMK:$(foreach __tmp__,$(NAME),$(eval $(call xfigobjs_template,$(__tmp__))))
156
157GMK:define xfigdeps_template
158GMK:ifdef $(1)_XFIGSRCS
159GMK:$(1)_OTHER+=	${$(1)_XFIGOBJS}
160GMK:ALLXFIGOBJS+=	${$(1)_XFIGOBJS}
161GMK:endif
162GMK:endef
163GMK:$(foreach __tmp__,$(NAME),$(eval $(call xfigdeps_template,$(__tmp__))))
164
165
166#######################################
167#
168# Add the dependencies
169#
170#######################################
171
172
173OTHER+=	$(XFIGOBJS)
174all::		$(ALLXFIGOBJS)
175
176clean::
177BMK:.for __tmp__ in $(ALLXFIGOBJS)
178BMK:	$(RM) -f $(__tmp__:Q)
179BMK:.endfor
180GMK:	$(RM) -f $(ALLXFIGOBJS)
181
182#######################################
183#
184# The suffix rules
185#
186#######################################
187
188.SUFFIXES : .fig .eps .pdf
189
190.fig.eps :
191BMK:	$(FIG2DEV:Q) $(FIG2DEV_FLAGS) $(FIG2DEV_EPS_FLAGS) $*.fig $*.eps
192GMK:	$(FIG2DEV) $(FIG2DEV_FLAGS) $(FIG2DEV_EPS_FLAGS) $*.fig $*.eps
193
194.fig.pdf :
195BMK:	$(FIG2DEV:Q) $(FIG2DEV_FLAGS) $(FIG2DEV_PDF_FLAGS) $*.fig $*.pdf
196GMK:	$(FIG2DEV) $(FIG2DEV_FLAGS) $(FIG2DEV_PDF_FLAGS) $*.fig $*.pdf
197
198