# set latexfile to the name of the main file without the .tex
latexfile := short
# put the names of figure files here.  include the .eps
figures = smiley.eps logo.eps

# if no references, run "touch latexfile.bbl; touch referencefile.bib"
# or delete dependency in .dvi and tarball sections
referencefile = refs

TEX = latex

#TEX = $(TEX)

A := $(realpath  aaaaaa bbbbb cccc)
C := $(realpath  aaaaaa bbbbb $(realpath kkkk))
B := $(abspath  aaaaaa bbbbb cccc)
objects := $(patsubst %.c,%.o,$(wildcard *.c) ahmed.c)
Z := $(subst c,o,$(wildcard *.c))
files := $(shell echo *.c)
M := $(wildcard *.c)
D := $(M:o=c)
E := $(addprefix kk, ahmeeeeeeed aawwww $(D) $(objects))
F := $(dir aaa/aadd $(M) kkk.c)
Y := $(findstring $(F) %cc, $(M))
O := $(lastword ssss mmmm $(F))
Q := $(join aa bb $(F), cc dd)

MMMMMM := $(if $(TEX),$(shell a))

DIRS := a b c d
FILES := $(foreach dir,$(DIRS),$(wildcard $(dir)/*))

AA := $(strip dadad $(F))

DD := $(sort dd cc $(F) aa)

OOOO := $(word 3, ssss mmmm $(F))

# support subdirectories
VPATH = Figs

# reruns latex if needed.  to get rid of this capability, delete the
# three lines after the rule.  Delete .bbl dependency if not using
# BibTeX references.
# idea from http://ctan.unsw.edu.au/help/uk-tex-faq/Makefile
$(latexfile).dvi : $(figures) $(latexfile).bbl $(latexfile).tex $(latexfile).bbl
	while ($(TEX) $(latexfile) ; grep -q 'Rerun to get cross' $(latexfile).log ) do true ;
	done

$(latexfile).dvi : file.tex


$(latexfile).dvi : file.eps

# keep .eps files in the same directory as the .fig files
%.eps : %.fig
	fig2dev -L eps $< > $(dir aaaa/ccc) $@

$(latexfile).pdf : $(latexfile).ps
	ps2pdf $(latexfile).ps $(latexfile).pdf

pdf : $(latexfile).pdf

$(latexfile).ps : $(latexfile).dvi
	dvips $(latexfile)

ps : $(latexfile).ps 

# make can't know all the sourcefiles.  some file may not have
# sourcefiles, e.g. eps's taken from other documents. 

$(latexfile).tar.gz : $(figures) $(latexfile).tex $(referencefile).bib
	tar -czvf $(latexfile).tar.gz $^
	
setup: $(FILES)
	a.c b.c c.c short		

ahmed.fig: aaa

short.ps : ps

tarball: $(latexfile).tar.gz

define PROGRAM_template = 
$(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) 
ALL_OBJS += $$($(1)_OBJS) 
endef 


KLMNOPQ := a.o b.o c.o

dup: $(FILES)
	$(KLMNOPQ:o=c) $(latexfile)

myfile: $(FILES)
	$(KLMNOPQ:o=c) $(latexfile)