diff -druN src/makefile src/makefile
--- src/makefile	2013-02-14 18:26:28.000000000 +0100
+++ src/makefile	2013-02-15 14:34:54.082756900 +0100
@@ -12,6 +12,7 @@
 gflags = -c $(includedirs) -g
 
 cflags = $(gflags) # the default setting
+cflags = -c $(includedirs) -O2 -fPIC -g
 
 ifdef optimize
 	NDEBUG = true
@@ -22,18 +27,78 @@
 	cflags = $(pflags)
 endif
 
-cc = g++
+EXENAME = coxeter
+LIBNAME = coxeter3
+ifeq ($(UNAME),Darwin)
+	EXEEXT = 
+	LIBPREFIX = lib
+	LIBEXT = .dylib
+	LIBDIR = lib
+	LINKFLAGS = -dynamiclib -Wl,-headerpad_max_install_names,-undefined,dynamic_lookup,-compatibility_version,3.0,-current_version,3.0,-install_name,$(SAGE_LOCAL)/lib/$(LIBPREFIX)$(LIBNAME)$(LIBEXT)
+	LINKLIBS = 
+else
+ifeq ($(UNAME),CYGWIN)
+	EXEEXT = .exe
+	LIBPREFIX = cyg
+	LIBEXT = .dll
+	LIBDIR = bin
+	IMPLIB = lib$(LIBNAME).dll.a
+	LINKFLAGS = -shared -Wl,--out-implib=$(IMPLIB) -Wl,--export-all-symbols
+	LINKLIBS = -lc
+else
+	EXEEXT = 
+	LIBPREFIX = lib
+	LIBEXT = .so
+	LIBDIR = lib
+	LINKFLAGS = -shared -Wl,-soname,libcoxeter3.so
+	LINKLIBS = -lc
+endif
+endif
+LIBRARY = $(LIBPREFIX)$(LIBNAME)$(LIBEXT)
 
-all: coxeter #clean
+all: coxeter executable
 
 coxeter: $(objects)
-	$(cc) -o coxeter $(objects)
+	$(CXX) $(LINKFLAGS) -o $(LIBRARY) $(objects) $(LINKLIBS)
+
+executable: $(objects)
+	$(CXX) -o $(EXENAME)$(EXEEXT) $(objects)
+
+BINDIR=$$SAGE_LOCAL/bin/
+DATADIR=$$SAGE_LOCAL/coxeter/
+INCLUDEDIR=$$SAGE_LOCAL/include/coxeter/
+LIBRARYDIR=$$SAGE_LOCAL/$(LIBDIR)
+
+install: coxeter executable
+	mkdir -p "$(DESTDIR)$(BINDIR)"
+	mkdir -p "$(DESTDIR)$(LIBRARYDIR)"
+	cp $(EXENAME)$(EXEEXT) "$(DESTDIR)$(BINDIR)"
+	cp $(LIBRARY) "$(DESTDIR)$(LIBRARYDIR)"
+	if [ $(UNAME) = "CYGWIN" ]; then                 \
+	    mkdir -p "$(DESTDIR)$$SAGE_LOCAL/lib/";      \
+	    cp $(IMPLIB) "$(DESTDIR)$$SAGE_LOCAL/lib/";  \
+	fi
+
+	mkdir -p "$(DESTDIR)$(DATADIR)"
+	cp -r coxeter_matrices headers messages "$(DESTDIR)$(DATADIR)"
+	mkdir -p "$(DESTDIR)$(INCLUDEDIR)"
+	cp -r *.h *.hpp "$(DESTDIR)$(INCLUDEDIR)"
+
+check: coxeter executable
+	$(EXENAME)$(EXEEXT) < test.input > test.output
+
+	if ! diff test.output.expected test.output > /dev/null; then \
+	   echo >&2 "Error testing coxeter on test.input:"; \
+	   diff test.output.expected test.output; \
+	   exit 1; \
+	fi
+	rm -f test.output
 
 clean:
 	rm -f $(objects)
 
 %.o:%.cpp
-	$(cc) $(cflags) $*.cpp
+	$(CXX) $(cflags) $*.cpp
 
 # dependencies --- these were generated automatically by make depend on my
 # system; they are explicitly copied for portability. Only local dependencies
@@ -43,7 +100,7 @@
 # contents of tmp in lieu of the dependencies listed here.
 
 %.d:%.cpp
-	@$(cc) -MM $*.cpp
+	@$(CXX) -MM $*.cpp
 depend: $(dependencies)
 
 affine.o: affine.cpp affine.h globals.h coxgroup.h coxtypes.h io.h list.h \
