Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-09-21 07:16:26 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-09-21 07:16:26 +0400
commite7abdd7d56256b57d9e33326af253188ed9d96dc (patch)
tree0e8aeb686bc3ad434c1c3ba528c2eed3b6512dfa /source
parent6c655aa2a762e440ba3f64ce8520c6ce41268d3e (diff)
Better unix filesystem integration as documented here
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/Unix_FHS for scons WITH_BF_FHS enabled an alternative layout eg. scons WITH_BF_FHS=1 BF_INSTALLDIR="/usr/local" for CMake just run "make install" after make (CMAKE_INSTALL_PREFIX is used for the base path) Currently only scripts use both the system and user path correctly, other areas of blender have their own path code inline with lots of ifdefs, needs to be carefully updated.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_util.h9
-rw-r--r--source/blender/blenlib/intern/util.c169
-rw-r--r--source/blender/python/intern/bpy_interface.c99
-rw-r--r--source/creator/CMakeLists.txt31
-rw-r--r--source/creator/SConscript5
-rw-r--r--source/creator/creator.c24
-rw-r--r--source/gameengine/PyDoc/SConscript7
7 files changed, 215 insertions, 129 deletions
diff --git a/source/blender/blenlib/BLI_util.h b/source/blender/blenlib/BLI_util.h
index f9a84e071e7..1ce7a8cdb77 100644
--- a/source/blender/blenlib/BLI_util.h
+++ b/source/blender/blenlib/BLI_util.h
@@ -42,7 +42,14 @@ struct ListBase;
struct direntry;
char *BLI_gethome(void);
-char *BLI_gethome_folder(char *folder_name);
+char *BLI_gethome_folder(char *folder_name, int flag);
+
+/* BLI_gethome_folder flag */
+#define BLI_GETHOME_LOCAL 1<<1 /* relative location for portable binaries */
+#define BLI_GETHOME_SYSTEM 1<<2 /* system location, or set from the BLENDERPATH env variable (UNIX only) */
+#define BLI_GETHOME_USER 1<<3 /* home folder ~/.blender */
+#define BLI_GETHOME_ALL (BLI_GETHOME_SYSTEM|BLI_GETHOME_LOCAL|BLI_GETHOME_USER)
+
void BLI_setenv(const char *env, const char *val);
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c
index c7bb7a54457..b1539d22909 100644
--- a/source/blender/blenlib/intern/util.c
+++ b/source/blender/blenlib/intern/util.c
@@ -856,98 +856,123 @@ char *BLI_gethome(void) {
#endif
}
-/* this function returns the path to a blender folder, if it exists,
- * trying in this order:
- *
- * path_to_executable/release/folder_name (in svn)
- * ./release/folder_name (in svn)
- * $HOME/.blender/folder_name
- * path_to_executable/.blender/folder_name
- *
- * returns NULL if none is found. */
+/* this function returns the path to a blender folder, if it exists
+ * utility functions for BLI_gethome_folder */
+
+/* #define PATH_DEBUG */ /* for testing paths that are checked */
+
+static int test_data_path(char *targetpath, char *path_base, char *path_sep, char *folder_name)
+{
+ char tmppath[FILE_MAXDIR];
+
+ if(path_sep) BLI_join_dirfile(tmppath, path_base, path_sep);
+ else BLI_strncpy(tmppath, path_base, sizeof(tmppath));
+
+ BLI_make_file_string("/", targetpath, tmppath, folder_name);
+
+ if (BLI_exists(targetpath)) {
+#ifdef PATH_DEBUG
+ printf("\tpath found: %s\n", targetpath);
+#endif
+ return 1;
+ }
+ else {
+#ifdef PATH_DEBUG
+ printf("\tpath missing: %s\n", targetpath);
+#endif
+ targetpath[0] = '\0';
+ return 0;
+ }
+}
-char *BLI_gethome_folder(char *folder_name)
+static int gethome_path_local(char *targetpath, char *folder_name)
{
extern char bprogname[]; /* argv[0] from creator.c */
- static char homedir[FILE_MAXDIR] = "";
- static char fulldir[FILE_MAXDIR] = "";
- char tmpdir[FILE_MAXDIR];
char bprogdir[FILE_MAXDIR];
+ char cwd[FILE_MAXDIR];
char *s;
int i;
-
+
+#ifdef PATH_DEBUG
+ printf("gethome_path_local...\n");
+#endif
+
+ /* try release/folder_name (binary relative) */
/* use argv[0] (bprogname) to get the path to the executable */
s = BLI_last_slash(bprogname);
-
i = s - bprogname + 1;
BLI_strncpy(bprogdir, bprogname, i);
+
+ /* try ./.blender/folder_name */
+ if(test_data_path(targetpath, bprogdir, ".blender", folder_name))
+ return 1;
+
+ if(test_data_path(targetpath, bprogdir, "release", folder_name))
+ return 1;
+
+ /* try release/folder_name (CWD relative) */
+ if(test_data_path(targetpath, BLI_getwdN(cwd), "release", folder_name))
+ return 1;
+
+ return 0;
+}
- /* try path_to_executable/release/folder_name (in svn) */
- if (folder_name) {
- BLI_snprintf(tmpdir, sizeof(tmpdir), "release/%s", folder_name);
- BLI_make_file_string("/", fulldir, bprogdir, tmpdir);
- if (BLI_exists(fulldir)) return fulldir;
- else fulldir[0] = '\0';
- }
+static int gethome_path_user(char *targetpath, char *folder_name)
+{
+ char *home_path= BLI_gethome();
- /* try ./release/folder_name (in svn) */
- if(folder_name) {
- BLI_snprintf(fulldir, sizeof(fulldir), "./release/%s", folder_name);
- if (BLI_exists(fulldir)) return fulldir;
- else fulldir[0] = '\0';
- }
+#ifdef PATH_DEBUG
+ printf("gethome_path_user...\n");
+#endif
+
+ /* try $HOME/folder_name */
+ return test_data_path(targetpath, home_path, ".blender", folder_name);
+}
- /* BLI_gethome() can return NULL if env vars are not set */
- s = BLI_gethome();
+static int gethome_path_system(char *targetpath, char *folder_name)
+{
+ extern char blender_path[]; /* unix prefix eg. /usr/share/blender/2.5 creator.c */
+
+ if(!blender_path[0])
+ return 0;
+
+#ifdef PATH_DEBUG
+ printf("gethome_path_system...\n");
+#endif
+
+ /* try $BLENDERPATH/folder_name */
+ return test_data_path(targetpath, blender_path, NULL, folder_name);
+}
- if(!s) { /* bail if no $HOME */
- printf("$HOME is NOT set\n");
- return NULL;
+char *BLI_gethome_folder(char *folder_name, int flag)
+{
+ static char fulldir[FILE_MAXDIR] = "";
+
+ /* first check if this is a redistributable bundle */
+ if(flag & BLI_GETHOME_LOCAL) {
+ if (gethome_path_local(fulldir, folder_name))
+ return fulldir;
}
- if(strstr(s, ".blender"))
- BLI_strncpy(homedir, s, FILE_MAXDIR);
- else
- BLI_make_file_string("/", homedir, s, ".blender");
-
- /* if $HOME/.blender/folder_name exists, return it */
- if(BLI_exists(homedir)) {
- if (folder_name) {
- BLI_make_file_string("/", fulldir, homedir, folder_name);
- if(BLI_exists(fulldir))
- return fulldir;
- }
- else
- return homedir;
- }
- else
- homedir[0] = '\0';
-
- /* using tmpdir to preserve homedir (if) found above:
- * the ideal is to have a home dir with folder_name dir inside
- * it, but if that isn't available, it's possible to
- * have a 'broken' home dir somewhere and a folder_name dir in the
- * svn sources */
- BLI_make_file_string("/", tmpdir, bprogdir, ".blender");
-
- if(BLI_exists(tmpdir)) {
- if(folder_name) {
- BLI_make_file_string("/", fulldir, tmpdir, folder_name);
- if(BLI_exists(fulldir)) {
- BLI_strncpy(homedir, tmpdir, FILE_MAXDIR);
- return fulldir;
- }
- else {
- homedir[0] = '\0';
- fulldir[0] = '\0';
- }
- }
- else return homedir;
+ /* then check if the OS has blender data files installed in a global location */
+ if(flag & BLI_GETHOME_SYSTEM) {
+ if (gethome_path_system(fulldir, folder_name))
+ return fulldir;
}
-
+
+ /* now check the users home dir for data files */
+ if(flag & BLI_GETHOME_USER) {
+ if (gethome_path_user(fulldir, folder_name))
+ return fulldir;
+ }
+
return NULL;
}
+#ifdef PATH_DEBUG
+#undef PATH_DEBUG
+#endif
+
void BLI_setenv(const char *env, const char*val)
{
/* SGI or free windows */
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index a850809b4a5..fd8cfc47f55 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -232,26 +232,10 @@ static PyObject *CreateGlobalDictionary( bContext *C )
return dict;
}
-/* Use this so we can include our own python bundle */
-#if 0
-wchar_t* Py_GetPath(void)
-{
- int i;
- static wchar_t py_path[FILE_MAXDIR] = L"";
- char *dirname= BLI_gethome_folder("python");
- if(dirname) {
- i= mbstowcs(py_path, dirname, FILE_MAXDIR);
- printf("py path %s, %d\n", dirname, i);
- }
- return py_path;
-}
-#endif
-
-
/* must be called before Py_Initialize */
void BPY_start_python_path(void)
{
- char *py_path_bundle= BLI_gethome_folder("python");
+ char *py_path_bundle= BLI_gethome_folder("python", BLI_GETHOME_ALL);
if(py_path_bundle==NULL)
return;
@@ -589,7 +573,8 @@ void BPY_run_ui_scripts(bContext *C, int reload)
char *dirname;
char path[FILE_MAX];
char *dirs[] = {"ui", "io", NULL};
- int a, err;
+ int path_flags[] = {BLI_GETHOME_LOCAL|BLI_GETHOME_SYSTEM, BLI_GETHOME_USER}; /* SYSTEM / NON-SYSTEM */
+ int a, err, flag_iter;
PyGILState_STATE gilstate;
PyObject *sys_path;
@@ -599,56 +584,60 @@ void BPY_run_ui_scripts(bContext *C, int reload)
sys_path= PySys_GetObject("path"); /* borrow */
PyList_Insert(sys_path, 0, Py_None); /* place holder, resizes the list */
- for(a=0; dirs[a]; a++) {
- dirname= BLI_gethome_folder(dirs[a]);
+ /* Scan system scripts first, then local/user */
+ for(flag_iter=0; flag_iter < sizeof(path_flags)/sizeof(int); flag_iter++) {
+
+ for(a=0; dirs[a]; a++) {
+ dirname= BLI_gethome_folder(dirs[a], path_flags[flag_iter]);
- if(!dirname)
- continue;
+ if(!dirname)
+ continue;
- dir = opendir(dirname);
+ dir = opendir(dirname);
- if(!dir)
- continue;
-
- /* set the first dir in the sys.path for fast importing of modules */
- PyList_SetItem(sys_path, 0, PyUnicode_FromString(dirname)); /* steals the ref */
+ if(!dir)
+ continue;
- while((de = readdir(dir)) != NULL) {
- /* We could stat the file but easier just to let python
- * import it and complain if theres a problem */
- err = 0;
-
- if (de->d_name[0] == '.') {
- /* do nothing, probably .svn */
- }
- else if ((file_extension = strstr(de->d_name, ".py"))) {
- /* normal py files? */
- if(file_extension && file_extension[3] == '\0') {
- de->d_name[(file_extension - de->d_name)] = '\0';
- err= bpy_import_module(de->d_name, reload);
+ /* set the first dir in the sys.path for fast importing of modules */
+ PyList_SetItem(sys_path, 0, PyUnicode_FromString(dirname)); /* steals the ref */
+
+ while((de = readdir(dir)) != NULL) {
+ /* We could stat the file but easier just to let python
+ * import it and complain if theres a problem */
+ err = 0;
+
+ if (de->d_name[0] == '.') {
+ /* do nothing, probably .svn */
+ }
+ else if ((file_extension = strstr(de->d_name, ".py"))) {
+ /* normal py files? */
+ if(file_extension && file_extension[3] == '\0') {
+ de->d_name[(file_extension - de->d_name)] = '\0';
+ err= bpy_import_module(de->d_name, reload);
+ }
}
- }
#ifndef __linux__
- else if( BLI_join_dirfile(path, dirname, de->d_name), S_ISDIR(BLI_exist(path))) {
+ else if( BLI_join_dirfile(path, dirname, de->d_name), S_ISDIR(BLI_exist(path))) {
#else
- else if(de->d_type==DT_DIR) {
- BLI_join_dirfile(path, dirname, de->d_name);
+ else if(de->d_type==DT_DIR) {
+ BLI_join_dirfile(path, dirname, de->d_name);
#endif
- /* support packages */
- BLI_join_dirfile(path, path, "__init__.py");
+ /* support packages */
+ BLI_join_dirfile(path, path, "__init__.py");
- if(BLI_exists(path)) {
- err= bpy_import_module(de->d_name, reload);
+ if(BLI_exists(path)) {
+ err= bpy_import_module(de->d_name, reload);
+ }
}
- }
- if(err==-1) {
- BPy_errors_to_report(NULL);
- fprintf(stderr, "unable to import %s/%s\n", dirname, de->d_name);
+ if(err==-1) {
+ BPy_errors_to_report(NULL);
+ fprintf(stderr, "unable to import %s/%s\n", dirname, de->d_name);
+ }
}
- }
- closedir(dir);
+ closedir(dir);
+ }
}
PyList_SetSlice(sys_path, 0, 1, NULL); /* remove the first item */
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index 1256881182b..410e0808580 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -66,6 +66,13 @@ IF(NOT WITH_SDL)
ADD_DEFINITIONS(-DDISABLE_SDL)
ENDIF(NOT WITH_SDL)
+IF(UNIX AND NOT APPLE)
+ SET(BLENDERPATH ${CMAKE_INSTALL_PREFIX}/share/blender/${BLENDER_VERSION})
+ CMAKE_POLICY(SET CMP0005 NEW)
+ # blender_path in creator.c
+ ADD_DEFINITIONS(-DBLENDERPATH="${BLENDERPATH}")
+ENDIF(UNIX AND NOT APPLE)
+
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
ADD_DEFINITIONS(-DWITH_BINRELOC)
INCLUDE_DIRECTORIES(${BINRELOC_INC})
@@ -96,6 +103,9 @@ IF(WITH_INSTALL)
ENDIF(UNIX)
IF(UNIX AND NOT APPLE)
+
+ # Local installation, "make install" can be done after this optionally
+
ADD_CUSTOM_COMMAND(
TARGET blender POST_BUILD MAIN_DEPENDENCY blender
COMMAND rm -Rf ${TARGETDIR}/.blender
@@ -152,6 +162,27 @@ IF(WITH_INSTALL)
COMMAND find ${TARGETDIR} -name .svn -prune -exec rm -rf {} "\;"
)
+
+ # Above we bundle a portable distrobution in ./bin
+ # This is an optional "make install" which installs blender on the system.
+ INSTALL(
+ PROGRAMS ${TARGETDIR}/blender
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+ )
+
+ IF(WITH_GAMEENGINE AND WITH_PLAYER)
+ INSTALL(
+ PROGRAMS ${TARGETDIR}/blenderplayer
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+ )
+ ENDIF(WITH_GAMEENGINE AND WITH_PLAYER)
+
+ INSTALL(
+ DIRECTORY ${TARGETDIR}/.blender/
+ DESTINATION ${BLENDERPATH}
+ )
+ # end "make install"
+
ENDIF(UNIX AND NOT APPLE)
IF(APPLE)
diff --git a/source/creator/SConscript b/source/creator/SConscript
index 75e7494ebb5..7b3d1493ed2 100644
--- a/source/creator/SConscript
+++ b/source/creator/SConscript
@@ -1,5 +1,6 @@
#!/usr/bin/python
Import ('env')
+import os
sources = 'creator.c'
@@ -32,4 +33,8 @@ if env['WITH_BF_PYTHON']:
else:
defs.append('DISABLE_PYTHON')
+if env['WITH_BF_FHS']: # /usr -> /usr/share/blender/2.5
+ defs.append('BLENDERPATH=\\"' + os.path.join(env['BF_INSTALLDIR'], 'share', 'blender', env['BF_VERSION']) + '\\"')
+
+
env.BlenderLib ( libname = 'bf_creator', sources = Split(sources), includes = Split(incs), defines = defs, libtype='core', priority = 0 )
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 41b27b1c915..523273de9bf 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -116,6 +116,18 @@ extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */
char bprogname[FILE_MAXDIR+FILE_MAXFILE]; /* from blenpluginapi:pluginapi.c */
char btempdir[FILE_MAXDIR+FILE_MAXFILE];
+/* unix path support.
+ * defined by the compiler. eg "/usr/share/blender/2.5" "/opt/blender/2.5" */
+#ifndef BLENDERPATH
+#define BLENDERPATH ""
+#endif
+
+#if !(defined(__APPLE__) && defined(WIN32))
+char blender_path[FILE_MAXDIR+FILE_MAXFILE] = BLENDERPATH;
+#else
+char blender_path[FILE_MAXDIR+FILE_MAXFILE] = "";
+#endif
+
/* Initialise callbacks for the modules that need them */
static void setCallbacks(void);
@@ -221,6 +233,12 @@ static void print_help(void)
printf (" \t\t passed unchanged. Access via Python's sys.argv\n");
printf ("\nEnvironment Variables:\n");
printf (" $HOME\t\t\tStore files such as .blender/ .B.blend .Bfs .Blog here.\n");
+#if !(defined(__APPLE__) && defined(WIN32))
+ printf (" $BLENDERPATH\tSystem directory to use for data files and scripts.\n");
+ printf (" \tFor this build of blender the default BLENDERPATH is...\n");
+ printf (" \t\"%s\"\n", blender_path);
+ printf (" \tseting the $BLENDERPATH will override this\n");
+#endif
#ifdef WIN32
printf (" $TEMP\t\tStore temporary files here.\n");
#else
@@ -305,6 +323,12 @@ int main(int argc, char **argv)
BLI_where_am_i(bprogname, argv[0]);
+ { /* override the hard coded blender path */
+ char *blender_path_env = getenv("BLENDERPATH");
+ if(blender_path_env)
+ BLI_strncpy(blender_path, blender_path_env, sizeof(blender_path));
+ }
+
RNA_init();
RE_engines_init();
diff --git a/source/gameengine/PyDoc/SConscript b/source/gameengine/PyDoc/SConscript
index ed9712ba273..dabe004ae6a 100644
--- a/source/gameengine/PyDoc/SConscript
+++ b/source/gameengine/PyDoc/SConscript
@@ -1,6 +1,11 @@
#!/usr/bin/python
Import ('env')
+import os
+if env['WITH_BF_FHS']:
+ BLENDERPATH = os.path.join(env['BF_INSTALLDIR'], 'share', 'blender', env['BF_VERSION'])
+else:
+ BLENDERPATH = env['BF_INSTALLDIR']
from optparse import OptionParser
import epydoc
@@ -14,7 +19,7 @@ optvalues["quiet"] = 0
optvalues["include_source_code"] = 0
optvalues["inheritance"] = "included"
optvalues["show_private"] = 0
-optvalues["target"] = env["BF_DOCDIR"]+"/BGE_API/"
+optvalues["target"] = os.path.join(BLENDERPATH, 'doc')
optvalues["url"] = "http://www.blender.org"
optvalues["top"] = "Game Engine API"
optvalues["name"] = "Blender"