# -*- Makefile -*-
include Makefile.config

.PHONY: install

INLIBDEST_DIRS = c resize_fat xf86misc
HAVEINST_DIRS = share/po standalone/po standalone/interactive_http standalone/menu
DIRS = $(INLIBDEST_DIRS) $(HAVEINST_DIRS) harddrake printer ../tools/serial_probe standalone/menu
NAME = libDrakX
XSETUPLEVEL=40
XSETUPLEVEL_HARDDRAKE=00
PREFIX = 
LIBDIR = $(PREFIX)/usr/lib
MENUDIR= $(LIBDEST)/menu
DATADIR = $(PREFIX)/usr/share
ICONSDIR= $(DATADIR)/icons
BINDEST = $(PREFIX)/usr/bin
SBINDEST = $(PREFIX)/usr/sbin
ETCDEST = $(PREFIX)/etc/gtk
LIBDEST = $(LIBDIR)/$(NAME)
PIXDIR = $(DATADIR)/$(NAME)/pixmaps
INITDIR =  $(PREFIX)/etc/rc.d/init.d
.PHONY: $(DIRS)

all: ../tools/rpcinfo-flushed $(DIRS)

$(DIRS):
	install -d auto
	[ ! -e $@/Makefile ] || $(MAKE) -C $@

install:
	perl -pi -e "s/\"VER\"(; # version)/\"$(VERSION)\"\1/" standalone.pm
	mkdir -p $(BINDEST) $(ETCDEST) $(SBINDEST) $(DATADIR)/{applications,harddrake,pixmaps,icons/{large,mini},autostart} $(PIXDIR) $(INITDIR) $(MENUDIR)
	install -d $(INLIBDEST_DIRS:%=$(LIBDEST)/%)
	install $(STANDALONEPMS) standalone/convert $(SBINDEST)
	install -s ../tools/rpcinfo-flushed ../tools/serial_probe/serial_probe $(SBINDEST)
	ln -s XFdrake $(SBINDEST)/Xdrakres
	ln -s fileshareset $(SBINDEST)/filesharelist
	mv -f $(SBINDEST)/lsnetdrake $(BINDEST)
	mv -f $(SBINDEST)/drakbug $(BINDEST)
	mv -f $(SBINDEST)/drakhelp $(BINDEST)
	mv -f $(SBINDEST)/localedrake $(BINDEST)

	install -m 644 *.pm $(LIBDEST)
	for i in $(PMS_DIRS); do install -d $(LIBDEST)/$$i ; install -m 644 $$i/*.pm $(LIBDEST)/$$i/;done
	install -m 644 pixmaps/*.* $(PIXDIR)
	install -m 644 share/*.rc $(DATADIR)/$(NAME)

	install -d $(PREFIX)/etc/security
	echo 'RESTRICT=yes' > $(PREFIX)/etc/security/fileshare.conf

	install -D standalone/finish-install.xsetup $(PREFIX)/etc/X11/xsetup.d/$(XSETUPLEVEL)finish-install.xsetup
	install -D standalone/notify-x11-free-driver-switch.xsetup $(PREFIX)/etc/X11/xsetup.d/$(XSETUPLEVEL_HARDDRAKE)notify-x11-free-driver-switch.xsetup
	install -d $(PREFIX)/etc/sysconfig
	echo 'FINISH_INSTALL=yes' > $(PREFIX)/etc/sysconfig/finish-install

	for i in $(HAVEINST_DIRS); do \
		$(MAKE) -C $$i install PREFIX=$(PREFIX) SUDO= DATADIR=$(DATADIR) ; \
	done

	find auto -follow -name .exists -o -name "*.bs" | xargs rm -f
	cp -rfL auto standalone/icons $(LIBDEST)
	mv $(LIBDEST)/icons/harddrake2/menu/harddrake-menu32.png $(ICONSDIR)/harddrake.png
	mv $(LIBDEST)/icons/harddrake2/menu/harddrake-menu48.png $(ICONSDIR)/large/harddrake.png
	mv $(LIBDEST)/icons/harddrake2/menu/harddrake-menu16.png $(ICONSDIR)/mini/harddrake.png
	mv $(LIBDEST)/icons/localedrake-32.png $(ICONSDIR)/localedrake.png
	mv $(LIBDEST)/icons/localedrake-48.png $(ICONSDIR)/large/localedrake.png
	mv $(LIBDEST)/icons/localedrake-16.png $(ICONSDIR)/mini/localedrake.png
	rmdir $(LIBDEST)/icons/harddrake2/menu
	install -m 644 standalone/menu/*.desktop $(DATADIR)/applications
	mv $(LIBDEST)/icons/harddrake2/ $(DATADIR)/pixmaps/
	mv $(SBINDEST)/convert $(DATADIR)/harddrake
	mv $(SBINDEST)/service_harddrake $(DATADIR)/harddrake/
	mv $(SBINDEST)/notify-x11-free-driver-switch $(DATADIR)/harddrake/
	ln -s {XFdrake,$(SBINDEST)/drakx11}
	ln -s {diskdrake,$(SBINDEST)/drakdisk}
	ln -s {drakclock,$(SBINDEST)/clock.pl}
	ln -s {harddrake2,$(SBINDEST)/drakhardware}
	ln -s {keyboarddrake,$(SBINDEST)/drakkeyboard}
	ln -s {localedrake,$(BINDEST)/draklocale}
	ln -s {logdrake,$(SBINDEST)/draklog}
	ln -s {mousedrake,$(SBINDEST)/drakmouse}
	ln -s {scannerdrake,$(SBINDEST)/drakscanner}