summaryrefslogtreecommitdiff
path: root/matlab_eps.mk
blob: c1848963701baaa0cb80f60caf4cc1c8c3987d43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- make -*-

CLEAN_TARGETS      += clean_matlab_eps_targets
REAL_CLEAN_TARGETS += real_clean_matlab_eps_targets

# MATLAB ?= matlab -nodesktop -nosplash
# MATLAB_quit = quit
MATLAB ?= cmd2screen.sh
MATLAB_quit ?= 
MATLAB_CLEAR = "clear;"
MATLAB_STORE_OLDPWD = "oldpwd=pwd;"
MATLAB_RESTORE_OLDPWD = "cd(oldpwd);"
MATLAB_PWD = "cd '$(CURDIR)';"
MATLAB_INITIATE_FIGURE = "h=figure('visible', 'off'); clf;"
MATLAB_EPS_PRINT_strt = print('-depsc',
MATLAB_EPS_PRINT_stop = );


matlab_sources  = $(wildcard plot_*.m)
matlab_eps_targets  = $(matlab_sources:plot_%.m=%.eps)	
matlab_pdf_targets  = $(matlab_eps_targets:%.eps=$(pics_destdir)/%.pdf)	


copy_matlab_pdf_targets: dest_dir_matlab $(matlab_pdf_targets)

$(matlab_eps_targets): %.eps : plot_%.m
	tmp=`mktemp`; \
	touch $${tmp}; \
	echo $(MATLAB_CLEAR) >> $${tmp}; \
	echo $(MATLAB_STORE_OLDPWD) >> $${tmp}; \
	echo $(MATLAB_PWD) >> $${tmp}; \
	echo $(MATLAB_INITIATE_FIGURE)  >> $${tmp}; \
	cat $<  >> $${tmp}; \
	echo "$(MATLAB_EPS_PRINT_strt)'$@'$(MATLAB_EPS_PRINT_stop)" >> $${tmp}; \
	echo $(MATLAB_RESTORE_OLDPWD) >> $${tmp}; \
	echo "$(MATLAB_quit)" >> $${tmp}; \
	cat $${tmp} | $(MATLAB); \
	rm -f $${tmp}

$(matlab_pdf_targets): $(pics_destdir)/%.pdf : %.eps
	epstopdf --autorotate=All --outfile=$@ $< 

clean_matlab_eps_targets:
ifneq ($(strip $(matlab_eps_targets)),)
	rm -f $(matlab_eps_targets)
endif

real_clean_matlab_eps_targets: clean_matlab_eps_targets
ifneq ($(strip $(matlab_pdf_targets)),)
	rm -f $(matlab_pdf_targets)
endif

dest_dir_matlab: 
	$(INSTALL) -d -m 0755 $(pics_destdir)

.INTERMEDIATE: $(matlab_eps_targets)