[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] [approve] Add non-host directory exclusion to compile path rules



This patch adds a rule to the compile path that excludes non-host
platform directories.  The directory names are: "osx", "linux" and
"windows".  So, for instance, under OSX directories named "linux" and
"windows" are ignored, and so on.

This allows extensions, and in tree code, to isolate classes and
methods that are not cross platform (typically interface and device
specific code) by simply placing the files in an appropriately named
subdirectory.

This is a much simpler approach for users than having to write .cfg
file entries for each installed extension.  

This patch applies on top of the common/platform.h patch of yesterday.
It applies from the root SuperCollider tree using: 

patch -p1

The patch includes some other trivial changes to platform.h.

Regards,
Rohan

--- SuperCollider3.build/headers/common/platform.h.old	Tue Dec 28 22:27:48 2004
+++ SuperCollider3.build/headers/common/platform.h	Wed Dec 29 13:06:10 2004
@@ -1,7 +1,7 @@
 #ifndef _SC_COMMON_PLATFORM_H
 #define _SC_COMMON_PLATFORM_H
 
-///// Include files.
+///// Include /////
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -10,7 +10,7 @@
 #include <time.h>
 #include <pthread.h>
 
-#ifndef SC_WIN32
+#if defined(SC_DARWIN) || defined(SC_LINUX)
 # include <unistd.h>
 # include <dirent.h>
 # include <libgen.h>
@@ -45,7 +45,7 @@
 # include "win32_utils.h"
 #endif
 
-///// Definitions
+///// Definitions /////
 
 #ifdef SC_WIN32
 # define snprintf _snprintf
@@ -53,8 +53,6 @@
 #  define PATH_MAX _MAX_PATH
 # endif
 # define MAXPATHLEN _MAX_PATH
-# define bzero(ptr,count) memset(ptr,0,count)
-# define strcasecmp(s1,s2) stricmp((s1),(s2))
 # ifdef _DEBUG
 #  define DEBUG 1
 # else
@@ -67,7 +65,7 @@
 # endif
 #endif
 
-///// Types
+///// Types /////
 
 #ifdef SC_WIN32
   typedef __int32 int32_t;
@@ -79,7 +77,25 @@
   typedef int socklen_t;
 #endif
 
-///// Math
+///// String /////
+
+#ifdef SC_WIN32
+static inline void bzero(void *b, size_t len);
+static inline void bzero(void *b, size_t len)
+{
+  memset(b,0,len);
+}
+#endif
+
+#ifdef SC_WIN32
+static inline int strcasecmp(const char *s1, const char *s2);
+static inline int strcasecmp(const char *s1, const char *s2)
+{
+  return stricmp(s1,s2);
+}
+#endif
+
+///// Math /////
 
 static inline int isqrt(int x); 
 static inline int isqrt(int x)
@@ -120,7 +136,7 @@
 #endif
 }
 
-///// Time
+///// Time /////
 
 static inline int sc_nanosleep(const struct timespec *req, struct timespec *rem);
 static inline int sc_nanosleep(const struct timespec *req, struct timespec *rem)
@@ -152,7 +168,7 @@
 #endif
 }
 
-///// Threads
+///// Threads /////
 
 static inline bool sc_init_threads(void);
 static inline bool sc_init_threads(void)
@@ -175,7 +191,7 @@
 #endif
 }
 
-///// Networking
+///// Networking /////
 
 static inline bool sc_init_network(void);
 static inline bool sc_init_network(void)
@@ -199,7 +215,7 @@
 #endif
 }
 
-#ifndef SC_WIN32
+#if defined(SC_DARWIN) || defined(SC_LINUX)
 static inline int closesocket (int fd);
 static inline int closesocket (int fd)
 {
@@ -257,7 +273,7 @@
 #endif
 }
 
-///// Memory
+///// Memory /////
 
 static inline void *sc_host_alloc(size_t size);
 static inline void *sc_host_alloc(size_t size)
@@ -281,7 +297,25 @@
 #endif
 }
 
-///// File system
+///// File system /////
+
+// Returns true iff 'name' is a platform name string that is not the
+// name of the compiled platform.  The name strings are "osx", "linux"
+// and "windows".
+
+inline static bool sc_IsNonHostPlatformDir(const char *name);
+inline static bool sc_IsNonHostPlatformDir(const char *name)
+{
+#if defined(SC_DARWIN)
+  char a[] = "linux", b[] = "windows";
+#elif defined(SC_LINUX)
+  char a[] = "osx", b[] = "windows";
+#elif defined(SC_WIN32)
+  char a[] = "osx", b[] = "linux";
+#endif
+  return ((strcmp(name, a) == 0) || 
+	  (strcmp(name, b) == 0));
+}
 
 // According to http://www.mkssoftware.com/docs/man3/setlinebuf.3.asp
 // setlinebuf is equivalent to the setvbuf call below.
@@ -311,7 +345,7 @@
 static inline char *sc_dirname (char *path);
 static inline char *sc_dirname (char *path)
 {
-#ifndef SC_WIN32
+#if defined(SC_DARWIN) || defined(SC_LINUX)
   return dirname(path);
 #else
   return 0;
@@ -323,7 +357,7 @@
 static inline bool sc_DirectoryExists(const char *dirname);
 static inline bool sc_DirectoryExists(const char *dirname) 
 {
-#ifndef SC_WIN32
+#if defined(SC_DARWIN) || defined(SC_LINUX)
   struct stat buf;
   int err = stat(dirname, &buf);
   return (err == 0) && (buf.st_mode & S_IFDIR);
@@ -337,7 +371,7 @@
 static inline void sc_GetUserHomeDirectory(char *str, int size);
 static inline void sc_GetUserHomeDirectory(char *str, int size)
 {
-#ifndef SC_WIN32
+#if defined(SC_DARWIN) || defined(SC_LINUX)
   char *home = getenv("HOME");
   strncpy(str, home, size);
 #else
@@ -432,7 +466,7 @@
 static inline void sc_AppendToPath(char *path, const char *component);
 static inline void sc_AppendToPath(char *path, const char *component)
 {
-#ifndef SC_WIN32
+#if defined(SC_DARWIN) || defined(SC_LINUX)
   strcat(path, "/");
 #else
   strcat(path, "\\");
@@ -446,7 +480,7 @@
 static inline bool sc_FileIsLink(const char *name, char *realname, int size);
 static inline bool sc_FileIsLink(const char *name, char *realname, int size)
 {
-#ifndef SC_WIN32
+#if defined(SC_DARWIN) || defined(SC_LINUX)
   char linkname[PATH_MAX];
   bool islink = false;
   realpath(name, linkname);
--- SuperCollider3.build/source/lang/LangSource/PyrLexer.cpp.old	Wed Dec 29 13:14:10 2004
+++ SuperCollider3.build/source/lang/LangSource/PyrLexer.cpp	Wed Dec 29 12:58:55 2004
@@ -73,8 +73,6 @@
 thisProcess.interpreter.executeFile("Macintosh HD:score").size.postln;
 */
 
-#define ENABLE_LIBRARY_CONFIGURATOR 1
-
 PyrSymbol *gCompilingFileSym = 0;
 VMGlobals *gCompilingVMGlobals = 0;
 char gCompileDir[MAXPATHLEN];
@@ -1901,7 +1899,8 @@
   return ((strcmp(name, ".") == 0) || 
 	  (strcmp(name, "..") == 0) ||
 	  (strcasecmp(name, "help") == 0) ||
-	  (strcasecmp(name, "test") == 0));
+	  (strcasecmp(name, "test") == 0) ||
+	  sc_IsNonHostPlatformDir(name));
 }
 
 bool passOne_ProcessDir(char *dirname, int level);