[OSM-dev] [PATCH] osm2pgsql install and prefix

strk strk at keybit.net
Mon Apr 5 13:52:44 BST 2010


The attached patch adds support for specifying
a PREFIX variable on 'make' and 'make install'
and adds installation of the default.style file.

If there's any interest I might also provide an
autoconf script (for ./configure --prefix=xxxx && make install)

--strk; 

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html
-------------- next part --------------
Index: osm2pgsql.c
===================================================================
--- osm2pgsql.c	(revision 20785)
+++ osm2pgsql.c	(working copy)
@@ -523,7 +523,7 @@
     fprintf(stderr, "   -p|--prefix\t\tPrefix for table names (default planet_osm)\n");
     fprintf(stderr, "   -s|--slim\t\tStore temporary data in the database. This greatly\n");
     fprintf(stderr, "            \t\treduces the RAM usage but is much slower.\n");
-    fprintf(stderr, "   -S|--style\t\tLocation of the style file. Defaults to /usr/share/osm2pgsql/default.style\n");
+    fprintf(stderr, "   -S|--style\t\tLocation of the style file. Defaults to "DATADIR"/default.style\n");
     fprintf(stderr, "   -C|--cache\t\tOnly for slim mode: Use upto this many MB for caching nodes\n");
     fprintf(stderr, "             \t\tDefault is 800\n");
     fprintf(stderr, "   -U|--username\tPostgresql user name.\n");
@@ -645,7 +645,7 @@
     const char *port = "5432";
     const char *conninfo = NULL;
     const char *prefix = "planet_osm";
-    const char *style = "/usr/share/osm2pgsql/default.style";
+    const char *style = DATADIR"/default.style";
     const char *temparg;
     const char *output_backend = "pgsql";
     int cache = 800;
Index: Makefile
===================================================================
--- Makefile	(revision 20785)
+++ Makefile	(working copy)
@@ -2,6 +2,12 @@
 VERSION:=0.69
 SVN:=$(shell svnversion)
 
+DESTDIR = /
+PREFIX = /usr
+DATADIR = $(PREFIX)/share/osm2pgsql
+BINDIR = $(PREFIX)/bin
+
+
 CC = gcc
 CXX = g++
 
@@ -11,6 +17,7 @@
 CFLAGS += -I$(shell pg_config --includedir)
 CFLAGS += -DVERSION=\"$(VERSION)-$(SVN)\"
 CFLAGS += -DHAVE_PTHREAD
+CFLAGS += -DDATADIR=\"$(DATADIR)\"
 
 CXXFLAGS += -g -O2 -Wall -DGEOS_INLINE $(CFLAGS)
 CXXFLAGS += $(shell geos-config --cflags)
@@ -29,9 +36,8 @@
 DEPS:=$(SRCS:.c=.d)
 DEPS:=$(DEPS:.cpp=.d)
 
-DESTDIR = /
-
 APPS:=osm2pgsql
+DATA:=default.style
 
 .PHONY: all clean $(PACKAGE).spec
 
@@ -43,7 +49,10 @@
 	rm -f osm2pgsql.spec
 
 install: $(APPS)
-	install -o root -g root -m 0755 $(APPS) $(DESTDIR)/usr/bin
+	mkdir -p $(DESTDIR)$(BINDIR)
+	install -m 0755 $(APPS) $(DESTDIR)$(BINDIR)
+	mkdir -p $(DESTDIR)$(DATADIR)
+	install -m 0644 $(DATA) $(DESTDIR)$(DATADIR)
 
 %.d: %.c
 	@set -e; rm -f $@; \
@@ -54,7 +63,7 @@
 -include $(DEPS)
 
 osm2pgsql: $(OBJS)
-	$(CXX) -o $@ $^ $(LDFLAGS)
+	$(CXX) -o $@ $^ $(CFLAGS) $(LDFLAGS)
 
 $(PACKAGE).spec: $(PACKAGE).spec.in
 	sed -e "s/@PACKAGE@/$(PACKAGE)/g; s/@VERSION@/$(VERSION)/g; s/@SVN@/$(SVN)/g;" $^ > $@
Index: README.txt
===================================================================
--- README.txt	(revision 20785)
+++ README.txt	(working copy)
@@ -65,6 +65,9 @@
 
 On most Unix-like systems the program can be compiled by
 running 'make'.
+You can specify a prefix: 'make PREFIX=/usr/local'.
+Don't forget to use the same PREFIX when installing:
+'make install PREFIX=/usr/local'
 
 Operation
 =========


More information about the dev mailing list