CURSORDIR=$(PREFIX)/crystalblue/cursors
BUILDDIR=../blue_cursors

#Define here the animation cursor directories
ANIMATED_CURSORS:= left_ptr_watch



########################################################################

#Find list of cursors
conffiles = $(wildcard *.conf)
cursorfiles:= $(foreach conffile,$(conffiles),$(BUILDDIR)/$(subst ./,,$(subst .conf,,$(conffile))))
cursornames:= $(foreach conffile,$(conffiles),$(subst ./,,$(subst .conf,,$(conffile))))
animcursorfiles:=$(foreach animationfile,$(ANIMATED_CURSORS),$(BUILDDIR)/$(animationfile))
animcursornames:=$(ANIMATED_CURSORS)



CURSORS = $(cursorfiles)
CURSORNAMES= $(cursornames)
ANIMATIONS= $(animcursorfiles)
ANIMATIONNAMES=$(animcursornames)




.PHONY: all


all: $(CURSORS) $(ANIMATIONS)
	make all -C nonanim
	if test -d classic;then make all -C classic; fi

install: all
	#Create necessary directories

	if test ! -d $(PREFIX) ;then mkdir $(PREFIX); fi
	if test ! -d $(PREFIX)/default ;then mkdir $(PREFIX)/default;fi
	if test ! -d $(PREFIX)/crystalblue ;then mkdir $(PREFIX)/crystalblue; fi
	if test ! -d $(PREFIX)/crystalblue/cursors ;then mkdir $(PREFIX)/crystalblue/cursors; fi
	#Copy the cursors

	cp -Rf $(BUILDDIR)/* $(CURSORDIR)

	#Copy the configuration file
	cp -f  index.theme $(PREFIX)/crystalblue/

	#Create some symlinks
	ln -sf hand $(CURSORDIR)/hand1
	ln -sf hand $(CURSORDIR)/hand2






	ln -sf hand1 $(CURSORDIR)/9d800788f1b08800ae810202380a0822 #hand1
	ln -sf hand2 $(CURSORDIR)/e29285e634086352946a0e7090d73106 #hand2
	ln -sf move $(CURSORDIR)/4498f0e0c1937ffe01fd06f973665830 # left_ptr (move_cursor)
	ln -sf copy $(CURSORDIR)/6407b0e94181790501fd1e167b474872 # copy
	ln -sf link $(CURSORDIR)/640fb0e74195791501fd1ed57b41487f # link


	ln -sf left_ptr_watch $(CURSORDIR)/3ecb610c1bf2410f44200f48c40d3599 # left_ptr_watch
	ln -sf question_arrow $(CURSORDIR)/d9ce0ab605698f320427677b458ad60b # question_arrow

	#Other apps' symlinks
	ln -sf left_ptr_watch $(CURSORDIR)/08e8e1c95fe2fc01f976f1e063a24ccd #mozilla's left_ptr_watch
	ln -sf copy $(CURSORDIR)/1081e37283d90000800003c07f3ef6bf #nautilus copy
	ln -sf move $(CURSORDIR)/9081237383d90e509aa00f00170e968f #nautilus move
	ln -sf link $(CURSORDIR)/3085a0e285430894940527032f8b26df #nautilus link

	ln -sf right_ptr $(CURSORDIR)/arrow
	ln -sf right_ptr $(CURSORDIR)/draft_large
	ln -sf right_ptr $(CURSORDIR)/draft_small
	ln -sf cross $(CURSORDIR)/plus
	ln -sf left_ptr $(CURSORDIR)/top_left_arrow

	make install -C nonanim
	if test -d classic;then make install -C classic; fi

#Normal Cursors
define CURSOR_template
$(BUILDDIR)/$(1):  $(1).conf
	xcursorgen $(1).conf $(BUILDDIR)/$(1)
endef

$(foreach cursor,$(CURSORNAMES),$(eval $(call CURSOR_template,$(cursor))))


#Animated Cursors
define ANIMCURSOR_template
$(BUILDDIR)/$(1):  $(1)/$(1).conf $(1)/*.png
	xcursorgen $(1)/$(1).conf $(BUILDDIR)/$(1)
endef

$(foreach anim,$(ANIMATIONNAMES),$(eval $(call ANIMCURSOR_template,$(anim))))

