# Variables substituted by the autoconf configure script:

SHELL = @SHELL@

CC = @CC@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@ -I.
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
RANLIB = @RANLIB@
@SET_MAKE@
INSTALL = @INSTALL@
prefix = @prefix@

AR = ar

all: libs

SCMFILES = class.scm help.scm io-vars.scm utils.scm ctl.scm include.scm \
           math-utils.scm vector3.scm extern-funcs.scm interaction.scm \
           matrix3x3.scm simplex.scm
OBJECTS = ctl.o subplex.o
LIBNAME = libctl.a
SHAREDNAME = libctl.so
LIBCTL_VERSION = @LIBCTL_VERSION@
MAJOR_VERSION = 2

libs: $(LIBNAME) $(SHAREDNAME)

libctl.a: $(OBJECTS)
	rm -f $@
	$(AR) r $@ $(OBJECTS)
	$(RANLIB) $@

$(SHAREDNAME): $(SHAREDNAME).$(MAJOR_VERSION)
	ln -sf $(SHAREDNAME).$(MAJOR_VERSION) $(SHAREDNAME)

$(SHAREDNAME).$(MAJOR_VERSION): $(SHAREDNAME).$(LIBCTL_VERSION)
	ln -sf $(SHAREDNAME).$(LIBCTL_VERSION) $(SHAREDNAME).$(MAJOR_VERSION)

$(SHAREDNAME).$(LIBCTL_VERSION): $(OBJECTS:%.o=%.sho)
	$(CC) -o $(SHAREDNAME).$(LIBCTL_VERSION) -shared \
	 -Wl,-soname,$(SHAREDNAME).$(MAJOR_VERSION) $^ -lc

install:
	$(INSTALL) -d $(prefix)/lib
	$(INSTALL) -m 0644 $(LIBNAME) $(prefix)/lib
	$(INSTALL) -m 0644 $(SHAREDNAME).$(LIBCTL_VERSION) $(prefix)/lib
	(cd $(prefix)/lib; ln -sf $(SHAREDNAME).$(LIBCTL_VERSION) \
	 $(SHAREDNAME).$(MAJOR_VERSION); ln -sf \
	 $(SHAREDNAME).$(MAJOR_VERSION) $(SHAREDNAME))
	$(INSTALL) -d $(prefix)/include
	$(INSTALL) -m 0644 ctl.h $(prefix)/include
	$(INSTALL) -d $(prefix)/share/libctl/base
	list='$(SCMFILES)'; for scmfile in $$list; do \
		$(INSTALL) -m 0644 $$scmfile $(prefix)/share/libctl/base; \
	done
	$(INSTALL) -m 0644 main.c $(prefix)/share/libctl/base

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

%.sho: %.c
	$(CC) -fPIC -c $(CPPFLAGS) $(CFLAGS) $< -o $@

clean: 
	rm -f *.o *.sho core $(LIBNAME) $(SHAREDNAME) $(SHAREDNAME).*
