PRG = libkcc.a
SHLIB = libkcc.so.0.2.0
CC = gcc
CFLAGS = -g -O2 -Wall

PREFIX = /usr/local

LIBDIR = $(PREFIX)/lib
INCDIR = $(PREFIX)/include

SRC_C = compare.c getstr.c guess.c showcode.c
SRC_1 = check.c
SRC_2 = filter.c   buffer.c dec.c euc.c jis.c out.c outchar.c setfunc.c sjis.c

SRCS = $(SRC_C) $(SRC_1) $(SRC_2)

HDRS = filter.h   kcc.h      setfunc.h

OBJS = $(SRCS:.c=.o)
OBJ_C = $(SRC_C:.c=.o)
OBJ_1 = $(SRC_1:.c=.o)
OBJ_2 = $(SRC_2:.c=.o)

.c.o:
	$(CC) $(CFLAGS) -c $<

all: $(PRG)

$(PRG): $(OBJS)
	ar crv $(PRG) $(OBJS)

shared:
	$(CC) -shared $(OBJS) -Wl,-soname,libkcc.so.0 -o $(SHLIB) \
	-Wl,--rpath,$(LIBDIR)

install:
	cp kcc.h $(INCDIR)/
	cp $(PRG) $(LIBDIR)/
	cp $(SHLIB) $(LIBDIR)/
	cd $(LIBDIR)
	ln -s $(SHLIB) libkcc.so
	ldconfig

clean:
	rm -f *.o $(PRG) test test_check test_filter *~

test_check: test_check.o $(OBJ_C) $(OBJ_1)
	$(CC) $(CFLAGS) -o test_check test_check.o $(OBJ_C) $(OBJ_1)

test_filter: test_filter.o $(OBJ_C) $(OBJ_2)
	$(CC) $(CFLAGS) -o test_filter test_filter.o $(OBJ_C) $(OBJ_2)

test:	test.o $(PRG)
	$(CC) $(CFLAGS) -o test test.o $(PRG)
