# Makefile for language module

include ../Makefile.inc


LANGOBJS = de en_us es fr hu it ja_euc ja_sjis nl pt ru tr
LANGSRCS = $(LANGOBJS:%=%.l)

LANGCOMP = ./langcomp
#LANGCOMP = ./langcomp -w


all: $(LANGOBJS)


install: all
	mkdir -p "$(DATDEST)/languages"
ifdef RUNGROUP
	chgrp "$(RUNGROUP)" "$(DATDEST)/languages"
	chmod 770 "$(DATDEST)/languages"
else
	chmod 700 "$(DATDEST)/languages"
endif
	cp $(LANGOBJS) "$(DATDEST)/languages"
ifdef RUNGROUP
	chgrp $(RUNGROUP) "$(DATDEST)/languages/"*
	chmod 660 "$(DATDEST)/languages/"*
else
	chmod 600 "$(DATDEST)/languages/"*
endif


clean:
	rm -f $(LANGOBJS) langcomp

spotless: clean
	rm -f langstrs.h


$(LANGOBJS): %: %.l langcomp index
	$(LANGCOMP) $<

ja_jis.l: ja_euc.l jconv.pl
	perl jconv.pl -jis <ja_euc.l >$@
ja_sjis.l: ja_euc.l jconv.pl
	perl jconv.pl -sjis <ja_euc.l >$@

langcomp: langcomp.c
	$(CC) $(CFLAGS) langcomp.c -o $@


langstrs.h: index Makefile
	@perl <index >$@.new \
	-e '	print STDERR "Generating langstrs.h... ";		' \
	-e '	$$i=0; 							' \
	-e '	while (<>) {						' \
	-e '		chop;						' \
	-e '		printf "#define %-32s %d\n", $$_, $$i++;	' \
	-e '	}							' \
	-e '	print "\n#define NUM_STRINGS $$i\n";			' \
	-e '	print STDERR "$$i strings\n";				'
	@if cmp $@ $@.new >/dev/null 2>&1 ; then \
		echo "$@ unchanged" ; \
		rm -f $@.new ; \
	else \
		mv -f $@.new $@ ; \
	fi

index: en_us.l
	grep '^[A-Z]' <en_us.l >$@


syntax highlighted by Code2HTML, v. 0.9.1