$NetBSD$

Adding NetBSD support. Setting TARGET, CFLAGS, LDFLAGS, LIBS, etc.

--- source/mupen64plus-core/projects/unix/Makefile.orig	2013-07-04 00:27:56.000000000 +0000
+++ source/mupen64plus-core/projects/unix/Makefile
@@ -39,6 +39,10 @@ endif
 ifeq ("$(UNAME)","FreeBSD")
   OS = FREEBSD
 endif
+ifeq ("$(UNAME)","NetBSD")
+  OS = NETBSD
+  $(warning OS type "$(UNAME)" not officially supported.')
+endif
 ifeq ("$(UNAME)","OpenBSD")
   OS = FREEBSD
   CFLAGS += -DIOAPI_NO_64
@@ -106,9 +110,9 @@ endif
 # base CFLAGS, LDLIBS, and LDFLAGS
 OPTFLAGS ?= -O3 -flto
 WARNFLAGS ?= -Wall
-CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src -DM64P_PARALLEL
+CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I../../src -DM64P_PARALLEL $(shell cpuflags)
 CXXFLAGS += -fvisibility-inlines-hidden
-LDLIBS +=  -lm
+LDLIBS +=  $(shell $(PKG_CONFIG) --libs libpng freetype2 gl) -lz -lm
 
 # Since we are building a shared library, we must compile with -fPIC on some architectures
 # On 32-bit x86 systems we do not want to use -fPIC because we don't have to and it has a big performance penalty on this arch
@@ -142,7 +146,7 @@ ifeq ($(OS), LINUX)
   TARGET = libmupen64plus$(POSTFIX).so.2.0.0
   SONAME = libmupen64plus$(POSTFIX).so.2
   LDFLAGS += -Wl,-Bsymbolic -shared -Wl,-export-dynamic -Wl,-soname,$(SONAME)
-  LDLIBS += -ldl
+  LDLIBS += ${DL_LIBS}
   # only export api symbols
   LDFLAGS += -Wl,-version-script,$(SRCDIR)/api/api_export.ver
 endif
@@ -161,7 +165,7 @@ ifeq ($(OS), OSX)
 
   TARGET = libmupen64plus$(POSTFIX).dylib
   LDFLAGS += -bundle -read_only_relocs suppress
-  LDLIBS += -ldl
+  LDLIBS += ${DL_LIBS}
   ifeq ($(CPU), X86)
     ifeq ($(ARCH_DETECTED), 64BITS)
       CFLAGS += -pipe -arch x86_64 -mmacosx-version-min=$(OSX_SDK) -isysroot $(OSX_SYSROOT)/MacOSX$(OSX_SDK).sdk
@@ -173,6 +177,13 @@ ifeq ($(OS), OSX)
     endif
   endif
 endif
+ifeq ($(OS), NETBSD)
+  TARGET = libmupen64plus.so.2.0.0
+  SONAME = libmupen64plus.so.2
+  CFLAGS += -I${PREFIX}/include -I../../src/
+  LDFLAGS += -Wl,-rpath,${LIBDIR} -shared -Wl,-export-dynamic -Wl,-soname,$(SONAME)
+  LIBS += $(shell $(PKG_CONFIG) --libs freetype2 gl glu libpng) -lz -lm
+endif
 ifeq ($(OS), MINGW)
   TARGET = mupen64plus$(POSTFIX).dll
   LDFLAGS += -Wl,-Bsymbolic -shared -Wl,-export-all-symbols
@@ -206,6 +217,10 @@ ifeq ($(OS), OSX) # use system zlib on O
   ZLIB_LDLIBS += -lz
 endif
 
+ifeq ($(OS), NETBSD) # use system/pkgsrc zlib on NETBSD
+  ZLIB_LDLIBS += -lz
+endif
+
 ifeq ($(origin ZLIB_CFLAGS) $(origin ZLIB_LDLIBS), undefined undefined)
   ifeq ($(shell $(PKG_CONFIG) --modversion zlib 2>/dev/null),)
     $(error No zlib development libraries found!)
@@ -267,7 +282,7 @@ ifeq ($(OSD), 1)
       $(error No OpenGL development libraries found!)
     endif
     GL_CFLAGS += $(shell $(PKG_CONFIG) --cflags gl)
-    GL_LDLIBS +=  $(shell $(PKG_CONFIG) --libs gl)
+    GL_LDLIBS +=  $(shell $(PKG_CONFIG) --libs gl) -lz
   endif
   CFLAGS += $(GL_CFLAGS)
   LDLIBS += $(GL_LDLIBS)
@@ -302,6 +317,9 @@ else
   ifeq ($(OS),FREEBSD)
     LDCONFIG ?= PATH="$$PATH:/sbin" ldconfig -m
   endif
+  ifeq ($(OS),NETBSD)
+    LDCONFIG ?= true  # no 'ldconfig' under NetBSD
+  endif
 endif
 
 # compiler/linker flags for various compile-time options.
@@ -547,7 +565,8 @@ all: $(TARGET)
 
 install: $(TARGET)
 	$(INSTALL) -d "$(DESTDIR)$(LIBDIR)"
-	$(INSTALL) -m 0644 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(LIBDIR)"
+	$(INSTALL) -m 0755 $(INSTALL_STRIP_FLAG) $(TARGET) "$(DESTDIR)$(LIBDIR)"
+	$(INSTALL) -m 0755 $(SONAME) "$(DESTDIR)$(LIBDIR)"
 	$(INSTALL) -d "$(DESTDIR)$(SHAREDIR)"
 	$(INSTALL) -m 0644 ../../data/* "$(DESTDIR)$(SHAREDIR)"
 	$(INSTALL) -d "$(DESTDIR)$(INCDIR)"
