Building the Shapefile library on Windows

First, get the latest source from http://download.osgeo.org/shapelib and extract it in a convenient place.

This library does not have a build system to speak of. The Makefile is so broken it's not even funny. Let's fix it. First, delete the libtool script in the shapefile source directory. Next, replace the Makefile with this:

# -*- Makefile -*-
SHPLIB_VERSION = 1.2.10
CC	?= cc
CFLAGS	?= -O2 -pipe
INSTALL	?= install -c -p -m 644
LD	?= ld
LIBTOOL	?= libtool
MKDIR	?= install -d -m 755
SED	?= sed
PREFIX	?= /usr/local
LIBNAME	= libshp
SOURCES	= shpopen.c shptree.c dbfopen.c
LA	= $(LIBNAME).la
LAI	= .libs/$(LIBNAME).lai
LO	= $(SOURCES:.c=.lo)
all: $(LA)
$(LA): $(LO)
$(LIBTOOL) --tag=CC --mode=link $(LD) $(LDFLAGS) -o $@ $^
install: $(LA) $(LAI)
$(MKDIR) $(PREFIX)/lib
$(LIBTOOL) --mode=install $(INSTALL) $(LA) $(PREFIX)/lib
$(LIBTOOL) --mode=finish $(PREFIX)/lib
$(MKDIR) $(PREFIX)/include/libshp
$(INSTALL) shapefil.h $(PREFIX)/include/libshp/shapefil.h
clean:
-rm -f $(LA) $(LAI) $(LO)
-rm -rf .libs
.SUFFIXES:
.SUFFIXES: .c .lo .la .lai
.c.lo:
$(LIBTOOL) --tag=CC --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) -DPACKAGE=\"libshp\" -DVERSION=\"$(SHPLIB_VERSION)\" -I. -c $<
.la.lai:
sed -e "s@^installed=.*@installed=yes@; s@^libdir=.*@libdir='$(PREFIX)/lib'@" <$< >$@ || (rm -f $@ ; false)

(I would have uploaded it as an attachment, but dokuwiki won't let me)

Make sure your editor didn't mangle the indentation: every indented line must begin with a single tab, no spaces.

Note that if you downloaded a different version than 1.2.10, you should change the value of SHPLIB_VERSION at the top.

Now you can simply build and install:

$ make CC=gcc PREFIX=/c/met.no all install