ifeq ($(strip $(RHIDESRC)),)
error You must set the environment variable RHIDESRC
endif

srcdir=$(RHIDESRC)/tvision/set
VPATH=$(srcdir)

project=editor

K_CPP=gcc -E -I $(srcdir)
key_languages=\
	azerty \
	be-latin \
	cf \
	de-latin \
	de \
	de1 \
	dk-latin \
	dvorak \
	es \
	fi-latin \
	fi \
	fr-latin \
	fr \
	gr-pc \
	gr \
	hebrew \
	it \
	no \
	pl \
	ru \
	ru1 \
	ru2 \
	sf-latin \
	sf \
	sg-latin \
	sg \
	sglatin1 \
	uk \

po_files=\
	ceditor.cc editorfo.cc editwind.cc fileedit.cc kbfun.cc loadkbin.cc \
	tvedit1.cc tvedit2.cc tvedit3.cc viewplus.cc sedhelp.cc calcu.cc \
	linelen.cc

src_files=$(po_files) makefile editor.gpr editor.mak pmacros.txt keybind.txt \
	keybind.cc keybind.h djmdr.s memmove.s kbfun.h bind2cc.cc \
	readme $(addsuffix .h,$(key_languages)) ceditor.his bufun.cc \
	setconst.h keyboard.h keyboard.c bind2cc.gpr bind2cc.mak \
	my.h readme.key lexyy.c p1-1_tab.c p1-1_tab.h edhelp.h parser.c \
	tnocastc.h

update_files=editor.gpr editor.mak bind2cc.gpr bind2cc.mak kbfun.h
cfg_files=bind2cc.gpr bind2cc.mak

subdirs=
po_subdirs=
obj_subdirs=

all install clean:

include $(RHIDESRC)/common.mak

keyfiles=us.txt $(addsuffix .txt,$(key_languages))

$(keyfiles): keybind.cc keybind.h makefile

us.txt: keybind.cc
	$(K_CPP) $< \
	  | sed -e '/^[ 	]*$$/d' -e 's/ [ ]*/ /g' -e '/^#.*$$/d' > $@

%.txt: %.h keybind.cc
	$(K_CPP) -DKEYBOARD_HEADER=\"$(notdir $<)\" $(word 2,$^) \
	  | sed -e '/^[ 	]*$$/d' -e 's/ [ ]*/ /g' -e '/^#.*$$/d' > $@

key_files: $(keyfiles)

key_doc=keybind.cc keybind.h readme.key my.h

install.cfg_files: pmacros.txt key_files
	ginstall -d $(prefix)/data
	ginstall $(keyfiles) $(prefix)/data
	ginstall $(addprefix $(srcdir)/,$(key_doc)) $(prefix)/data
	echo $(addprefix data/,$(keyfiles) $(key_doc)) > $(logfile)
	ginstall us.txt $(prefix)/data/keybind.txt
	ginstall $< $(prefix)/data/pmacros.txt
	echo $(addprefix data/,keybind.txt pmacros.txt) >> $(logfile)

$(srcdir)/keybind.txt:
	touch $@

ifneq ($(obj_dir),$(srcdir))
$(obj_dir)/keybind.txt: $(srcdir)/keybind.txt
	cp $< $@
else
$(obj_dir)/keybind.txt:
endif

kbfun.h: bind2cc.exe $(obj_dir)/keybind.txt
	$< kbfun.hh
	update kbfun.hh kbfun.h

bind2cc.exe:
	$(MAKE) -f bind2cc.mak $(FLAGS_TO_PASS) bind2cc.exe
