CURSORDIR=$(PREFIX)/crystalgray/cursors
BUILDDIR=../gray_cursors

#Define here the animation cursor directories
ANIMATED_CURSORS:= watch 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

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)/crystalgray ;then mkdir $(PREFIX)/crystalgray; fi
	if test ! -d $(PREFIX)/crystalgray/cursors ;then mkdir $(PREFIX)/crystalgray/cursors; fi
	#Copy the cursors

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

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

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


	#QT symlinks mess :-(

	ln -sf v_double_arrow	$(CURSORDIR)/00008160000006810000408080010102 #v_double_arrow
	ln -sf h_double_arrow	$(CURSORDIR)/028006030e0e7ebffc7f7070c0600140 #h_double_arrow
	ln -sf fd_double_arrow	$(CURSORDIR)/fcf1c3c7cd4491d801f1e1c78f100000 #fd_double_arrow
	ln -sf bd_double_arrow	$(CURSORDIR)/c7088f0f3e6c8088236ef8e1e3e70000 #bd_double_arrow
	ln -sf sb_h_double_arrow   $(CURSORDIR)/14fef782d02440884392942c11205230 #sb_h_double_arrow
	ln -sf sb_v_double_arrow   $(CURSORDIR)/2870a09082c103050810ffdffffe0204 #sb_v_double_arrow



	ln -sf hand1 $(CURSORDIR)/9d800788f1b08800ae810202380a0822 #hand1
	ln -sf hand2 $(CURSORDIR)/e29285e634086352946a0e7090d73106 #hand2
	ln -sf crossed_circle $(CURSORDIR)/03b6e0fcb3499374a867c041f52298f0 # crossed_circle (dnd forbidden)
	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 cross $(CURSORDIR)/cross_reverse
	ln -sf cross $(CURSORDIR)/crosshair
	ln -sf v_double_arrow $(CURSORDIR)/double_arrow
	ln -sf right_ptr $(CURSORDIR)/draft_large
	ln -sf right_ptr $(CURSORDIR)/draft_small
	ln -sf cross $(CURSORDIR)/plus
	ln -sf cross $(CURSORDIR)/tcross
	ln -sf left_ptr $(CURSORDIR)/top_left_arrow
	ln -sf base_arrow_down $(CURSORDIR)/based_arrow_down
	ln -sf base_arrow_up $(CURSORDIR)/based_arrow_up
	ln -sf fd_double_arrow $(CURSORDIR)/ll_angle
	ln -sf bd_double_arrow $(CURSORDIR)/lr_angle

	make install -C nonanim


#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))))

