From a4c9f5456a6a0dc134991ae35b686b000db81236 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Thu, 13 Oct 2016 20:32:45 -0400
Subject: [PATCH] add 0.25.2 changes from svn plus more recent bugfixes:
 [r16947] by eighthave: merge in Win32 UTF-8 file/path support [r16123] by
 eighthave: pad link fields with -headerpad_max_install_names so the
 Pd-extended packaging can rewrite the link paths [r16033] by eighthave:
 replace verbose() with logpost() since verbose() adds extraneous carraige
 returns to messages that have been filtered out by the log level [r15977] by
 eighthave: bumped to v0.25.2 [r15918] by eighthave: post version message
 using verbose(0) [r15472] by eighthave: updated to template/Makefile 1.0.11
 [r15186] by eighthave: replace .x%x 32-bit only canvas id with .x%lx canvas
 id which supports 32-bit and 64-bit

---
 externals/pdogg/Makefile    | 189 ++++++++++++++++++++++++++++--------
 externals/pdogg/README.txt  |  28 +++---
 externals/pdogg/oggamp~.c   |  12 +--
 externals/pdogg/oggcast~.c  |   2 +-
 externals/pdogg/oggread~.c  |   8 +-
 externals/pdogg/oggwrite~.c |   8 +-
 6 files changed, 176 insertions(+), 71 deletions(-)

diff --git a/externals/pdogg/Makefile b/externals/pdogg/Makefile
index 325eb2ee6..3aa0f360c 100644
--- a/externals/pdogg/Makefile
+++ b/externals/pdogg/Makefile
@@ -1,10 +1,16 @@
-## Pd library template version 1.0.3
+## Pd library template version 1.0.11
 # For instructions on how to use this template, see:
 #  http://puredata.info/docs/developer/MakefileTemplate
+#
+
+# the name of this library
+# must not contain any spaces or weird characters (as it's used for
+# filenames,...)
 LIBRARY_NAME = pdogg
 
 # add your .c source files, one object per file, to the SOURCES
-# variable, help files will be included automatically
+# variable, help files will be included automatically, and for GUI
+# objects, the matching .tcl file too
 SOURCES = oggamp~.c oggcast~.c oggread~.c oggwrite~.c
 
 # list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
@@ -23,7 +29,6 @@ MANUAL =
 # automatically included
 EXTRA_DIST = pdogg.c makefile.msvc HISTORY
 
-# special case: pthread lib was added below
 
 
 #------------------------------------------------------------------------------#
@@ -32,9 +37,12 @@ EXTRA_DIST = pdogg.c makefile.msvc HISTORY
 #
 #------------------------------------------------------------------------------#
 
-CFLAGS = -DPD -I"$(PD_INCLUDE)"/pd -Wall -W -g
-LDFLAGS =  
-LIBS = 
+ALL_CFLAGS = -I"$(PD_INCLUDE)"
+ALL_LDFLAGS =  
+SHARED_LDFLAGS =
+ALL_LIBS = $(shell pkg-config --libs vorbis vorbisenc vorbisfile)
+LIBS_windows = -lpthread
+
 
 #------------------------------------------------------------------------------#
 #
@@ -42,12 +50,17 @@ LIBS =
 #
 #------------------------------------------------------------------------------#
 
+# these can be set from outside without (usually) breaking the build
+CFLAGS = -Wall -W -g
+LDFLAGS =
+LIBS =
+
 # get library version from meta file
 LIBRARY_VERSION = $(shell sed -n 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' $(LIBRARY_NAME)-meta.pd)
 
-CFLAGS += -DVERSION='"$(LIBRARY_VERSION)"'
+ALL_CFLAGS += -DPD -DVERSION='"$(LIBRARY_VERSION)"'
 
-PD_INCLUDE = $(PD_PATH)/include
+PD_INCLUDE = $(PD_PATH)/include/pd
 # where to install the library, overridden below depending on platform
 prefix = /usr/local
 libdir = $(prefix)/lib
@@ -63,7 +76,7 @@ ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx)
 	         $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows)
 
 DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION)
-ORIGDIR=pd-$(LIBRARY_NAME)_$(LIBRARY_VERSION)
+ORIGDIR=pd-$(LIBRARY_NAME:~=)_$(LIBRARY_VERSION)
 
 UNAME := $(shell uname -s)
 ifeq ($(UNAME),Darwin)
@@ -71,6 +84,7 @@ ifeq ($(UNAME),Darwin)
   ifeq ($(CPU),arm) # iPhone/iPod Touch
     SOURCES += $(SOURCES_iphoneos)
     EXTENSION = pd_darwin
+    SHARED_EXTENSION = dylib
     OS = iphoneos
     PD_PATH = /Applications/Pd-extended.app/Contents/Resources
     IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
@@ -80,14 +94,16 @@ ifeq ($(UNAME),Darwin)
     ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk
     IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6
     OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer
-	CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS)
-    LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT)
-    LIBS += -lc 
+    ALL_CFLAGS := $(IPHONE_CFLAGS) $(ALL_CFLAGS)
+    ALL_LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT)
+    SHARED_LDFLAGS += -arch armv6 -dynamiclib -undefined dynamic_lookup $(ISYSROOT)
+    ALL_LIBS += -lc $(LIBS_iphoneos)
     STRIP = strip -x
     DISTBINDIR=$(DISTDIR)-$(OS)
   else # Mac OS X
     SOURCES += $(SOURCES_macosx)
     EXTENSION = pd_darwin
+    SHARED_EXTENSION = dylib
     OS = macosx
     PD_PATH = /Applications/Pd-extended.app/Contents/Resources
     OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast
@@ -98,27 +114,88 @@ ifeq ($(UNAME),Darwin)
       FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4
       SOURCES += $(SOURCES_iphoneos)
     endif
-    CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include
-    LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib
+    ALL_CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include
     # if the 'pd' binary exists, check the linking against it to aid with stripping
-    LDFLAGS += $(shell test -e $(PD_PATH)/bin/pd && echo -bundle_loader $(PD_PATH)/bin/pd)
-    LIBS += -lc `pkg-config --libs vorbis vorbisenc`
+    BUNDLE_LOADER = $(shell test ! -e $(PD_PATH)/bin/pd || echo -bundle_loader $(PD_PATH)/bin/pd)
+    ALL_LDFLAGS += $(FAT_FLAGS) -headerpad_max_install_names -bundle $(BUNDLE_LOADER) \
+	-undefined dynamic_lookup -L/sw/lib
+    SHARED_LDFLAGS += $(FAT_FLAGS) -dynamiclib -undefined dynamic_lookup \
+	-install_name @loader_path/$(SHARED_LIB) -compatibility_version 1 -current_version 1.0
+    ALL_LIBS += -lc $(LIBS_macosx)
     STRIP = strip -x
     DISTBINDIR=$(DISTDIR)-$(OS)
 # install into ~/Library/Pd on Mac OS X since /usr/local isn't used much
     pkglibdir=$(HOME)/Library/Pd
   endif
 endif
+# Tho Android uses Linux, we use this fake uname to provide an easy way to
+# setup all this things needed to cross-compile for Android using the NDK
+ifeq ($(UNAME),ANDROID)
+  CPU := arm
+  SOURCES += $(SOURCES_android)
+  EXTENSION = pd_linux
+  SHARED_EXTENSION = so
+  OS = android
+  PD_PATH = /usr
+  NDK_BASE := /usr/local/android-ndk
+  NDK_PLATFORM_VERSION := 5
+  NDK_SYSROOT=$(NDK_BASE)/platforms/android-$(NDK_PLATFORM_VERSION)/arch-arm
+  NDK_UNAME := $(shell uname -s | tr '[A-Z]' '[a-z]')
+  NDK_TOOLCHAIN_BASE=$(NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(NDK_UNAME)-x86
+  CC := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-gcc --sysroot=$(NDK_SYSROOT)
+  OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+  CFLAGS += 
+  LDFLAGS += -rdynamic -shared
+  SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared
+  LIBS += -lc $(LIBS_android)
+  STRIP := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-strip \
+	--strip-unneeded -R .note -R .comment
+  DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
+endif
 ifeq ($(UNAME),Linux)
   CPU := $(shell uname -m)
   SOURCES += $(SOURCES_linux)
   EXTENSION = pd_linux
+  SHARED_EXTENSION = so
+  OS = linux
+  PD_PATH = /usr
+  OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+  ALL_CFLAGS += -fPIC
+  ALL_LDFLAGS += -rdynamic -shared -fPIC
+  SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared
+  ALL_LIBS += -lc $(LIBS_linux)
+  STRIP = strip --strip-unneeded -R .note -R .comment
+  DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
+endif
+ifeq ($(UNAME),GNU)
+  # GNU/Hurd, should work like GNU/Linux for basically all externals
+  CPU := $(shell uname -m)
+  SOURCES += $(SOURCES_linux)
+  EXTENSION = pd_linux
+  SHARED_EXTENSION = so
+  OS = linux
+  PD_PATH = /usr
+  OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+  ALL_CFLAGS += -fPIC
+  ALL_LDFLAGS += -rdynamic -shared -fPIC
+  SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB)
+  ALL_LIBS += -lc $(LIBS_linux)
+  STRIP = strip --strip-unneeded -R .note -R .comment
+  DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
+endif
+ifeq ($(UNAME),GNU/kFreeBSD)
+  # Debian GNU/kFreeBSD, should work like GNU/Linux for basically all externals
+  CPU := $(shell uname -m)
+  SOURCES += $(SOURCES_linux)
+  EXTENSION = pd_linux
+  SHARED_EXTENSION = so
   OS = linux
   PD_PATH = /usr
   OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
-  CFLAGS += -fPIC
-  LDFLAGS += -Wl,--export-dynamic  -shared -fPIC
-  LIBS += -lc `pkg-config --libs vorbis vorbisenc`
+  ALL_CFLAGS += -fPIC
+  ALL_LDFLAGS += -rdynamic -shared -fPIC
+  SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB)
+  ALL_LIBS += -lc $(LIBS_linux)
   STRIP = strip --strip-unneeded -R .note -R .comment
   DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
 endif
@@ -126,12 +203,14 @@ ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME)))
   CPU := $(shell uname -m)
   SOURCES += $(SOURCES_cygwin)
   EXTENSION = dll
+  SHARED_EXTENSION = dll
   OS = cygwin
-  PD_PATH = $(cygpath $(PROGRAMFILES))/pd
+  PD_PATH = $(shell cygpath $$PROGRAMFILES)/pd
   OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
-  CFLAGS += 
-  LDFLAGS += -Wl,--export-dynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin"
-  LIBS += -lc -lpd -lvorbis -lvorbisenc -logg
+  ALL_CFLAGS += 
+  ALL_LDFLAGS += -rdynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin"
+  SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB)
+  ALL_LIBS += -lc -lpd $(LIBS_cygwin)
   STRIP = strip --strip-unneeded -R .note -R .comment
   DISTBINDIR=$(DISTDIR)-$(OS)
 endif
@@ -139,12 +218,16 @@ ifeq (MINGW,$(findstring MINGW,$(UNAME)))
   CPU := $(shell uname -m)
   SOURCES += $(SOURCES_windows)
   EXTENSION = dll
+  SHARED_EXTENSION = dll
   OS = windows
-  PD_PATH = $(shell cd "$(PROGRAMFILES)"/pd && pwd)
+  PD_PATH = $(shell cd "$$PROGRAMFILES/pd" && pwd)
+  # MinGW doesn't seem to include cc so force gcc
+  CC=gcc
   OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer
-  CFLAGS += -mms-bitfields
-  LDFLAGS += -s -shared -Wl,--enable-auto-import
-  LIBS += -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj" -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 -lpthread -lvorbis -lvorbisfile -lvorbisenc -logg
+  ALL_CFLAGS += -mms-bitfields
+  ALL_LDFLAGS += -s -shared -Wl,--enable-auto-import -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj"
+  SHARED_LDFLAGS += -shared
+  ALL_LIBS += -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 $(LIBS_windows)
   STRIP = strip --strip-unneeded -R .note -R .comment
   DISTBINDIR=$(DISTDIR)-$(OS)
 endif
@@ -152,42 +235,57 @@ endif
 # in case somebody manually set the HELPPATCHES above
 HELPPATCHES ?= $(SOURCES:.c=-help.pd) $(PDOBJECTS:.pd=-help.pd)
 
-CFLAGS += $(OPT_CFLAGS)
+ALL_CFLAGS := $(ALL_CFLAGS) $(CFLAGS) $(OPT_CFLAGS)
+ALL_LDFLAGS := $(LDFLAGS) $(ALL_LDFLAGS)
+ALL_LIBS := $(LIBS) $(ALL_LIBS)
 
+SHARED_SOURCE ?= $(shell test ! -e lib$(LIBRARY_NAME).c || \
+	echo lib$(LIBRARY_NAME).c )
+SHARED_HEADER ?= $(shell test ! -e $(LIBRARY_NAME).h || echo $(LIBRARY_NAME).h)
+SHARED_LIB = $(SHARED_SOURCE:.c=.$(SHARED_EXTENSION))
 
-.PHONY = install libdir_install single_install install-doc install-exec install-examples install-manual clean dist etags $(LIBRARY_NAME)
+.PHONY = install libdir_install single_install install-doc install-examples install-manual clean distclean dist etags $(LIBRARY_NAME)
 
-all: $(SOURCES:.c=.$(EXTENSION))
+all: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB)
 
 %.o: %.c
-	$(CC) $(CFLAGS) -o "$*.o" -c "$*.c"
+	$(CC) $(ALL_CFLAGS) -o "$*.o" -c "$*.c"
 
-%.$(EXTENSION): %.o
-	$(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o"  $(LIBS)
+%.$(EXTENSION): %.o $(SHARED_LIB)
+	$(CC) $(ALL_LDFLAGS) -o "$*.$(EXTENSION)" "$*.o"  $(ALL_LIBS) $(SHARED_LIB)
 	chmod a-x "$*.$(EXTENSION)"
 
 # this links everything into a single binary file
 $(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o
-	$(CC) $(LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(LIBS)
+	$(CC) $(ALL_LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(ALL_LIBS)
 	chmod a-x $(LIBRARY_NAME).$(EXTENSION)
 
+$(SHARED_LIB): $(SHARED_SOURCE:.c=.o)
+	$(CC) $(SHARED_LDFLAGS) -o $(SHARED_LIB) $(SHARED_SOURCE:.c=.o) $(LIBS)
+
 install: libdir_install
 
 # The meta and help files are explicitly installed to make sure they are
 # actually there.  Those files are not optional, then need to be there.
-libdir_install: $(SOURCES:.c=.$(EXTENSION)) install-doc install-examples install-manual
+libdir_install: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB) install-doc install-examples install-manual
 	$(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
 	$(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd \
 		$(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
 	test -z "$(strip $(SOURCES))" || (\
 		$(INSTALL_PROGRAM) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \
 		$(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION))))
+	test -z "$(strip $(SHARED_LIB))" || \
+		$(INSTALL_DATA) $(SHARED_LIB) \
+			$(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+	test -z "$(strip $(wildcard $(SOURCES:.c=.tcl)))" || \
+		$(INSTALL_DATA) $(wildcard $(SOURCES:.c=.tcl)) \
+			$(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
 	test -z "$(strip $(PDOBJECTS))" || \
 		$(INSTALL_DATA) $(PDOBJECTS) \
 			$(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
 
 # install library linked as single binary
-single_install: $(LIBRARY_NAME) install-doc install-exec
+single_install: $(LIBRARY_NAME) install-doc install-examples install-manual
 	$(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
 	$(INSTALL_PROGRAM) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
 	$(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION)
@@ -216,10 +314,11 @@ install-manual:
 
 
 clean:
-	-rm -f -- $(SOURCES:.c=.o) $(SOURCES_LIB:.c=.o)
+	-rm -f -- $(SOURCES:.c=.o) $(SOURCES_LIB:.c=.o) $(SHARED_SOURCE:.c=.o)
 	-rm -f -- $(SOURCES:.c=.$(EXTENSION))
 	-rm -f -- $(LIBRARY_NAME).o
 	-rm -f -- $(LIBRARY_NAME).$(EXTENSION)
+	-rm -f -- $(SHARED_LIB)
 
 distclean: clean
 	-rm -f -- $(DISTBINDIR).tar.gz
@@ -235,7 +334,7 @@ $(DISTBINDIR):
 
 libdir: all $(DISTBINDIR)
 	$(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd  $(DISTBINDIR)
-	$(INSTALL_DATA) $(SOURCES)  $(DISTBINDIR)
+	$(INSTALL_DATA) $(SOURCES) $(SHARED_SOURCE) $(SHARED_HEADER) $(DISTBINDIR)
 	$(INSTALL_DATA) $(HELPPATCHES) $(DISTBINDIR)
 	test -z "$(strip $(EXTRA_DIST))" || \
 		$(INSTALL_DATA) $(EXTRA_DIST)    $(DISTBINDIR)
@@ -254,6 +353,12 @@ dist: $(DISTDIR)
 	$(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd  $(DISTDIR)
 	test -z "$(strip $(ALLSOURCES))" || \
 		$(INSTALL_DATA) $(ALLSOURCES)  $(DISTDIR)
+	test -z "$(strip $(wildcard $(ALLSOURCES:.c=.tcl)))" || \
+		$(INSTALL_DATA) $(wildcard $(ALLSOURCES:.c=.tcl))  $(DISTDIR)
+	test -z "$(strip $(SHARED_HEADER))" || \
+		$(INSTALL_DATA) $(SHARED_HEADER)  $(DISTDIR)
+	test -z "$(strip $(SHARED_SOURCE))" || \
+		$(INSTALL_DATA) $(SHARED_SOURCE)  $(DISTDIR)
 	test -z "$(strip $(PDOBJECTS))" || \
 		$(INSTALL_DATA) $(PDOBJECTS)  $(DISTDIR)
 	test -z "$(strip $(HELPPATCHES))" || \
@@ -286,17 +391,25 @@ etags:
 	etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h
 
 showsetup:
+	@echo "CC: $(CC)"
 	@echo "CFLAGS: $(CFLAGS)"
 	@echo "LDFLAGS: $(LDFLAGS)"
 	@echo "LIBS: $(LIBS)"
+	@echo "ALL_CFLAGS: $(ALL_CFLAGS)"
+	@echo "ALL_LDFLAGS: $(ALL_LDFLAGS)"
+	@echo "ALL_LIBS: $(ALL_LIBS)"
 	@echo "PD_INCLUDE: $(PD_INCLUDE)"
 	@echo "PD_PATH: $(PD_PATH)"
 	@echo "objectsdir: $(objectsdir)"
 	@echo "LIBRARY_NAME: $(LIBRARY_NAME)"
 	@echo "LIBRARY_VERSION: $(LIBRARY_VERSION)"
 	@echo "SOURCES: $(SOURCES)"
+	@echo "SHARED_HEADER: $(SHARED_HEADER)"
+	@echo "SHARED_SOURCE: $(SHARED_SOURCE)"
+	@echo "SHARED_LIB: $(SHARED_LIB)"
 	@echo "PDOBJECTS: $(PDOBJECTS)"
 	@echo "ALLSOURCES: $(ALLSOURCES)"
+	@echo "ALLSOURCES TCL: $(wildcard $(ALLSOURCES:.c=.tcl))"
 	@echo "UNAME: $(UNAME)"
 	@echo "CPU: $(CPU)"
 	@echo "pkglibdir: $(pkglibdir)"
diff --git a/externals/pdogg/README.txt b/externals/pdogg/README.txt
index b2c476d7f..e2a027305 100644
--- a/externals/pdogg/README.txt
+++ b/externals/pdogg/README.txt
@@ -1,7 +1,7 @@
 Version 0.25
 copyright (c) 2002-2004 by Olaf Matthes
 
-pdogg~ is a collection of ogg/vorbis externals for pd (by Miller 
+pdogg~ is a collection of Ogg/Vorbis externals for Pd (by Miller 
 Puckette).
 
 It includes:
@@ -10,10 +10,10 @@ It includes:
 - oggread~  : reads files from disk
 - oggwrite~ : writes files to disk
 
-To use pdogg start pd with '-lib path\to\pdogg' flag. 
+To use pdogg start Pd with '-lib path\to\pdogg' flag. 
 On Win32 systems Pd 0.35 test 17 or later is necessary to get it working!
 
-To compile pdogg~ you need the ogg/vorbis library from 
+To compile pdogg~ you need the Ogg/Vorbis library from 
 http://www.vorbis.com/ and under win additionally Pthreads-win32 from
 http://sources.redhat.com/pthreads-win32/.
 You have to modify the makefile to make it point to the place where the
@@ -28,8 +28,8 @@ due to a bug or for other reasons.
 
 *****************************************************************************
 
-pdogg~ uses the ogg/vorbis library to encode audio data.
-The latest version of ogg/vorbis can be found at http://www.vorbis.com/
+pdogg~ uses the Ogg/Vorbis library to encode audio data.
+The latest version of Ogg/Vorbis can be found at http://www.vorbis.com/
 
 The original version was found at:
 http://www.akustische-kunst.de/puredata/
@@ -45,13 +45,13 @@ displayed, use [oggamp~ 1].
 
 Message "connect <host> <mountpoint> <port>" connects to an IceCast2 server.
 Note that no response about succesfull connection is send by the server. All
-messages in the pd console window about connection status depend on the ability
+messages in the Pd console window about connection status depend on the ability
 to receive data from the server.
 Use "connecturl <url>" to use url-like server adresses (like http://host:post/
 stream.ogg).
 
 Known bugs and other things:
-- pd halts for a moment when oggamp~ connects to the server. This results in a
+- Pd halts for a moment when oggamp~ connects to the server. This results in a
   short audio drop out of sound currently played back.
 - resampling not jet supported
 - playback does not stop on a buffer underrun
@@ -62,9 +62,9 @@ Known bugs and other things:
 
 oggcast~ Usage:
 
-Use message "vbr <samplerate> <channels> <quality>" to set the vorbis
+Use message "vbr <samplerate> <channels> <quality>" to set the Vorbis
 encoding parameters. Resampling is currently not supported, so 'samplerate' 
-should be the one pd is running at. 'channels' specyfies the number of channels 
+should be the one Pd is running at. 'channels' specyfies the number of channels 
 to stream. This can be set to 2 (default) or 1 which means mono stream taking
 the leftmost audio input only. 'quality' can be a value between 0.0 and 1.0 
 giving the quality of the stream. 0.4 (default) results in a stream that's 
@@ -82,16 +82,16 @@ constant bitrate stream. Values are in kbps!
 
 Message "connect <host> <mountpoint> <port>" connects to the IceCast2 server.
 Note that no response about succesfull connection is send by the server. All
-messages in the pd console window about connection status depend on the ability
+messages in the Pd console window about connection status depend on the ability
 to send data to the server.
 The mountpoint should end with '.ogg' to indiocate to the player/client that 
-it is an ogg/vorbis encoded stream.
+it is an Ogg/Vorbis encoded stream.
 
 Use "passwd <passwort>" to set your password (default is 'letmein') and 
 "disconnect" to disconnect from the server. "print" prints out the current
-vorbis encoder settings.
+Vorbis encoder settings.
 
-To set the comment tags in the ogg/vorbis header (which can be displayed by
+To set the comment tags in the Ogg/Vorbis header (which can be displayed by
 the receiving client) use message "<NAMEOFTAG> <comment>". Supported tags are:
 TITLE, ARTIST, GENRE, PERFORMER, LOCATION, COPYRIGHT, CONTACT, DESCRIPTION and
 DATE (which is automatically set to the date/time the broadcast started). To
@@ -101,7 +101,7 @@ from the patch after saving!!!
 
 Listening to it:
 
-To listen to ogg/vorbis encoded livestreams many player need an extra plug-in.
+To listen to Ogg/Vorbis encoded livestreams many player need an extra plug-in.
 Have a look at http://www.vorbis.com/ to find the appropiate plug-in for your
 player.
 To play back the stream just open lacation http://<server>:<port>/<mountpoint>.
diff --git a/externals/pdogg/oggamp~.c b/externals/pdogg/oggamp~.c
index 6809b5eb1..9ee27b8f3 100644
--- a/externals/pdogg/oggamp~.c
+++ b/externals/pdogg/oggamp~.c
@@ -634,7 +634,7 @@ static void oggamp_child_dographics(t_oggamp *x)
 		/* do graphics stuff :: create rectangle */
     if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
     {
-		sys_vgui(".x%x.c create rectangle %d %d %d %d -fill lightblue -tags %xPBAR\n",
+		sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill lightblue -tags %xPBAR\n",
                   x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-OBJHEIGHT-1,
                   x->x_obj.te_xpix + OBJWIDTH, x->x_obj.te_ypix - 1, x );
     } 
@@ -648,7 +648,7 @@ static void oggamp_child_updategraphics(t_oggamp *x)
 			/* update graphical read status */
 		char color[32];
 
-		sys_vgui(".x%x.c delete rectangle %xSTATUS\n", x->x_canvas, x); 
+		sys_vgui(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x); 
 		if(x->x_fifobytes < (x->x_fifosize / 8))
 		{
 			strcpy(color, "red");
@@ -657,7 +657,7 @@ static void oggamp_child_updategraphics(t_oggamp *x)
 		{
 			strcpy(color, "lightgreen");
 		}
-		sys_vgui(".x%x.c create rectangle %d %d %d %d -fill %s -tags %xSTATUS\n",
+		sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xSTATUS\n",
 		x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-OBJHEIGHT-1,
 		x->x_obj.te_xpix+((x->x_fifobytes*OBJWIDTH)/x->x_fifosize),
 		x->x_obj.te_ypix - 1, color, x);
@@ -667,8 +667,8 @@ static void oggamp_child_delgraphics(t_oggamp *x)
 {
     if(x->x_graphic)			/* delete graphics */
     {
-       sys_vgui(".x%x.c delete rectangle %xPBAR\n", x->x_canvas, x );
-       sys_vgui(".x%x.c delete rectangle %xSTATUS\n", x->x_canvas, x ); 
+       sys_vgui(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
+       sys_vgui(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x ); 
     }
 }
 
@@ -1056,7 +1056,7 @@ static void *oggamp_new(t_floatarg fdographics, t_floatarg fnchannels, t_floatar
     x->x_graphic = (int)fdographics;
     x->x_canvas = canvas_getcurrent(); 
     
-    post(oggamp_version);
+    logpost(NULL, 4, oggamp_version);
 	post("oggamp~: set buffer to %dk bytes", bufsize/1024);
 
 		/* start child thread */
diff --git a/externals/pdogg/oggcast~.c b/externals/pdogg/oggcast~.c
index 74888b892..e4b5a2eb0 100644
--- a/externals/pdogg/oggcast~.c
+++ b/externals/pdogg/oggcast~.c
@@ -1070,7 +1070,7 @@ static void *oggcast_new(t_floatarg fnchannels, t_floatarg fbufsize)
 	x->x_mountpoint = "puredata.ogg";
 	x->x_servertype = 1;			/* HTTP/1.0 protocol for Icecast2 */
     
-    post(oggcast_version);
+    logpost(NULL, 4, oggcast_version);
 	post("oggcast~: set buffer to %dk bytes", bufsize / 1024);
 	post("oggcast~: encoding %d channels @ %d Hz", x->x_channels, x->x_samplerate);
 
diff --git a/externals/pdogg/oggread~.c b/externals/pdogg/oggread~.c
index 2501ff407..fcb93975f 100644
--- a/externals/pdogg/oggread~.c
+++ b/externals/pdogg/oggread~.c
@@ -290,11 +290,7 @@ static void oggread_open(t_oggread *x, t_symbol *filename)
 		post("oggread~: previous file closed");
 	}
 		/* open file for reading */
-#ifdef WIN32
-	if((x->x_file = fopen(filename->s_name, "rb")) < 0)
-#else
-   if((x->x_file = fopen(filename->s_name, "r")) < 0)
-#endif
+    if((x->x_file = sys_fopen(filename->s_name, "r")) < 0)
     {
 		post("oggread~: could not open file \"%s\"", filename->s_name);
 		x->x_eos = 1;
@@ -394,7 +390,7 @@ static void *oggread_new(t_floatarg fdographics)
     x->x_outunread = 0;
 	x->x_decoded = 0;
 
-    post(oggread_version);
+    logpost(NULL, 4, oggread_version);
 
     return (x);
 }
diff --git a/externals/pdogg/oggwrite~.c b/externals/pdogg/oggwrite~.c
index 87753e373..a241ae97d 100644
--- a/externals/pdogg/oggwrite~.c
+++ b/externals/pdogg/oggwrite~.c
@@ -466,11 +466,7 @@ static void oggwrite_open(t_oggwrite *x, t_symbol *sfile)
 		x->x_recflag = 0;
     }
 
-#ifdef WIN32
-    if((x->x_fd = _open( sfile->s_name, x->x_file_open_mode, _S_IREAD|_S_IWRITE)) < 0)
-#else
-    if((x->x_fd = open( sfile->s_name, x->x_file_open_mode, S_IRWXU|S_IRWXG|S_IRWXO )) < 0)
-#endif
+    if((x->x_fd = sys_open( sfile->s_name, x->x_file_open_mode, 0666 )) < 0)
     {
        error( "oggwrite~: can not open \"%s\"", sfile->s_name); 
        x->x_fd=-1;
@@ -729,7 +725,7 @@ static void *oggwrite_new(void)
 	x->x_bcperformer = "";
 	x->x_bccontact = "";
 	x->x_bcdate = "";
-    post(oggwrite_version);
+    logpost(NULL, 4, oggwrite_version);
 	return(x);
 }
 
-- 
GitLab