CC=@CC@
CXX=@CXX@
CFLAGS=@CFLAGS@
CFLAGS2=@CFLAGS2@
CFLAGS3=@CFLAGS3@
CFLAGS4=@CFLAGS4@
PREFIX_PATH=@PREFIX_PATH@
DEBUG=@DEBUG@
MIGEMO=@MIGEMO@
INSTALL=@INSTALL@
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@

RLIB=ruby-1.8.4/libruby-static.a
ONIG=onig-4.0.1/.libs/libonig.a

TARGETS=mfiler mattr mkeycode mhitanykey

all: $(TARGETS)
	rm -f install

OBJ=bin/main.o bin/command.o bin/cmdline.o bin/dirwnd.o bin/menu.o bin/file.o bin/help.o mlib/mlib.a

mfiler: $(RLIB) $(ONIG) $(OBJ) config.h
	$(CXX) -o mfiler $(OBJ) $(RLIB) $(ONIG) $(CFLAGS2) $(MIGEMO)

mattr: mattr.cpp
	$(CXX) -o mattr mattr.cpp $(CFLAGS3)

mhitanykey: mhitanykey.c mlib/mlib.a
	$(CC) -o mhitanykey mhitanykey.c mlib/mlib.a $(CFLAGS3)

mkeycode: mkeycode.cpp
	$(CXX) -o mkeycode mkeycode.cpp $(CFLAGS4)

mlib/mlib.a:
	cd mlib && make

$(RLIB): 
	cd ruby-1.8.4 && ./configure && make

$(ONIG):
	cd onig-4.0.1 && ./configure && make

bin/main.o: main.cpp common.h menu.h dirwnd.h config.h
	$(CXX) -c main.cpp $(CFLAGS) $(DEBUG)
	mv main.o bin/

bin/command.o: command.cpp common.h menu.h dirwnd.h config.h
	$(CXX) -c command.cpp $(CFLAGS) $(DEBUG)
	mv command.o bin/
      
bin/dirwnd.o: dirwnd.cpp common.h menu.h dirwnd.h config.h
	$(CXX) -c dirwnd.cpp $(CFLAGS) $(DEBUG)
	mv dirwnd.o bin/
      
bin/cmdline.o: cmdline.cpp common.h menu.h dirwnd.h config.h
	$(CXX) -c cmdline.cpp $(CFLAGS) $(DEBUG)
	mv cmdline.o bin/
      
bin/menu.o: menu.cpp common.h menu.h dirwnd.h config.h
	$(CXX) -c menu.cpp $(CFLAGS) $(DEBUG)
	mv menu.o bin/
      
bin/file.o: file.cpp common.h dirwnd.h menu.h config.h
	$(CXX) -c file.cpp $(CFLAGS) $(DEBUG)
	mv file.o bin/

bin/help.o: help.cpp common.h config.h
	$(CXX) -c help.cpp $(CFLAGS) $(DEBUG)
	mv help.o bin/

clean:
	rm -f bin/* mfiler mattr mkeycode mhitanykey mfiler.exe mattr.exe mkeycode.exe mhitanykey.exe
	cd mlib && make clean

distclean:
	rm -f bin/* mfiler mattr mkeycode mhitanykey mfiler.exe mattr.exe mkeycode.exe mhitanykey.exe
	rm -f Makefile config.cache config.h config.log config.status
	cd mlib && make clean

install:
	mkdir -p $(bindir)
	mkdir -p $(prefix)/etc
	mkdir -p $(prefix)/share/migemo-dic/cp932
	mkdir -p $(prefix)/share/migemo-dic/euc-jp
	mkdir -p $(prefix)/share/migemo-dic/utf-8
	$(INSTALL) -m 755 mfiler $(bindir)
	$(INSTALL) -m 755 mattr $(bindir)
	$(INSTALL) -m 755 mcompile $(bindir)
	$(INSTALL) -m 755 mgrep $(bindir)
	$(INSTALL) -m 755 mkeycode $(bindir)
	$(INSTALL) -m 755 mhitanykey $(bindir)
	$(INSTALL) -m 644 .mfiler "$(PREFIX_PATH)/etc/mfiler"
	$(INSTALL) -m 644 .mfcompl "$(PREFIX_PATH)/etc/mfcompl"
	$(INSTALL) -m 644 migemo-dic/cp932/han2zen.dat "$(PREFIX_PATH)/share/migemo-dic/cp932"
	$(INSTALL) -m 644 migemo-dic/cp932/hira2kata.dat "$(PREFIX_PATH)/share/migemo-dic/cp932"
	$(INSTALL) -m 644 migemo-dic/cp932/migemo-dict "$(PREFIX_PATH)/share/migemo-dic/cp932"
	$(INSTALL) -m 644 migemo-dic/cp932/roma2hira.dat "$(PREFIX_PATH)/share/migemo-dic/cp932"
	$(INSTALL) -m 644 migemo-dic/euc-jp/han2zen.dat "$(PREFIX_PATH)/share/migemo-dic/euc-jp"
	$(INSTALL) -m 644 migemo-dic/euc-jp/hira2kata.dat "$(PREFIX_PATH)/share/migemo-dic/euc-jp"
	$(INSTALL) -m 644 migemo-dic/euc-jp/migemo-dict "$(PREFIX_PATH)/share/migemo-dic/euc-jp"
	$(INSTALL) -m 644 migemo-dic/euc-jp/roma2hira.dat "$(PREFIX_PATH)/share/migemo-dic/euc-jp"
	$(INSTALL) -m 644 migemo-dic/utf-8/han2zen.dat "$(PREFIX_PATH)/share/migemo-dic/utf-8"
	$(INSTALL) -m 644 migemo-dic/utf-8/hira2kata.dat "$(PREFIX_PATH)/share/migemo-dic/utf-8"
	$(INSTALL) -m 644 migemo-dic/utf-8/migemo-dict "$(PREFIX_PATH)/share/migemo-dic/utf-8"
	$(INSTALL) -m 644 migemo-dic/utf-8/roma2hira.dat "$(PREFIX_PATH)/share/migemo-dic/utf-8"

