Commits

Dean Giberson committed 13e64d9 Merge with conflicts

Merge branch 'master' into animblend

Conflicts:
blender/source/blender/nodes/CMakeLists.txt

  • Participants
  • Parent commits 2f2113f, 611aa04
  • Branches animblend

Comments (0)

Files changed (496)

File blender/CMakeLists.txt

 option(WITH_RAYOPTIMIZATION	"Enable use of SIMD (SSE) optimizations for the raytracer" ON)
 if(UNIX AND NOT APPLE)
 	option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
+	option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
 endif()
 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
 endif()
 
 # auto enable llvm for cycles_osl
-if(WITH_CYCLES_OSL AND NOT WIN32)
+if(WITH_CYCLES_OSL)
 	set(WITH_LLVM ON CACHE BOOL "ON" FORCE)
 endif()
 
 #Platform specifics
 
 if(UNIX AND NOT APPLE)
-
-	# set lib directory if it exists
-	if(CMAKE_SYSTEM_NAME MATCHES "Linux")
-		if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
-			set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/linux64)
-		else()
-			set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/linux)
+	macro(find_package_wrapper)
+		STRING(TOUPPER ${ARGV0} _NAME_UPPER)
+		if(${WITH_STATIC_LIBS})
+			set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
+			set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
 		endif()
-
-		if(NOT EXISTS ${LIBDIR})
-			unset(LIBDIR)
+		find_package(${ARGV})
+		if(${WITH_STATIC_LIBS})
+			set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
+			unset(_cmake_find_library_suffixes_back)
 		endif()
-	endif()
+	endmacro()
 
-	find_package(JPEG REQUIRED)
-	find_package(PNG REQUIRED)
-	find_package(ZLIB REQUIRED)
-	find_package(Freetype REQUIRED)
+	find_package_wrapper(JPEG REQUIRED)
+	find_package_wrapper(PNG REQUIRED)
+	find_package_wrapper(ZLIB REQUIRED)
+	find_package_wrapper(Freetype REQUIRED)
 
 	if(WITH_PYTHON)
 		# No way to set py32. remove for now.
 
 		# Use our own instead, since wothout py is such a rare case,
 		# require this package
+		# XXX Linking errors with debian static python :/
+#		find_package_wrapper(PythonLibsUnix REQUIRED)
 		find_package(PythonLibsUnix REQUIRED)
 	endif()
 
-
 	if(WITH_IMAGE_OPENEXR)
-		find_package(OpenEXR)  # our own module
+		find_package_wrapper(OpenEXR)  # our own module
 		if(NOT OPENEXR_FOUND)
 			set(WITH_IMAGE_OPENEXR OFF)
 		endif()
 	endif()
 
 	if(WITH_IMAGE_OPENJPEG)
-		find_package(OpenJPEG)
+		find_package_wrapper(OpenJPEG)
 		if(NOT OPENJPEG_FOUND)
 			set(WITH_IMAGE_OPENJPEG OFF)
 		endif()
 	endif()
 
 	if(WITH_IMAGE_TIFF)
+		# XXX Linking errors with debian static tiff :/
+#		find_package_wrapper(TIFF)
 		find_package(TIFF)
 		if(NOT TIFF_FOUND)
 			set(WITH_IMAGE_TIFF OFF)
 
 	# Audio IO
 	if(WITH_OPENAL)
-		find_package(OpenAL)
+		find_package_wrapper(OpenAL)
 		if(NOT OPENAL_FOUND)
 			set(WITH_OPENAL OFF)
 		endif()
 	endif()
 
 	if(WITH_SDL)
-		find_package(SDL)
+		find_package_wrapper(SDL)
 		mark_as_advanced(
 			SDLMAIN_LIBRARY
 			SDL_INCLUDE_DIR
 	endif()
 
 	if(WITH_JACK)
-		find_package(Jack)
+		find_package_wrapper(Jack)
 		if(NOT JACK_FOUND)
 			set(WITH_JACK OFF)
 		endif()
 
 	# Codecs
 	if(WITH_CODEC_SNDFILE)
-		find_package(SndFile)
+		find_package_wrapper(SndFile)
 		if(NOT SNDFILE_FOUND)
 			set(WITH_CODEC_SNDFILE OFF)
 		endif()
 	endif()
 
 	if(WITH_CODEC_FFMPEG)
-		# use lib dir if available and nothing else specified
-		if(LIBDIR AND NOT FFMPEG)
-			set(FFMPEG ${LIBDIR}/ffmpeg CACHE PATH "FFMPEG Directory")
-			# XXX, some distros might need 'theoraenc theoradec' too
-			set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale dirac_encoder mp3lame ogg orc-0.4 schroedinger-1.0 theora vorbis vorbisenc vpx x264 xvidcore faad asound CACHE STRING "FFMPEG Libraries")
-		else()
-			set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
-			set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
-		endif()
+		set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
+		set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
 
 		mark_as_advanced(FFMPEG)
 
 	endif()
 
 	if(WITH_FFTW3)
-		find_package(Fftw3)
+		find_package_wrapper(Fftw3)
 		if(NOT FFTW3_FOUND)
 			set(WITH_FFTW3 OFF)
 		endif()
 	endif()
 
 	if(WITH_OPENCOLLADA)
-		find_package(OpenCOLLADA)
+		find_package_wrapper(OpenCOLLADA)
 		if(OPENCOLLADA_FOUND)
-			find_package(XML2)
-			find_package(PCRE)
+			find_package_wrapper(XML2)
+			find_package_wrapper(PCRE)
 		else()
 			set(WITH_OPENCOLLADA OFF)
 		endif()
 	endif()
 
 	if(WITH_MEM_JEMALLOC)
-		find_package(JeMalloc)
+		find_package_wrapper(JeMalloc)
 		if(NOT JEMALLOC_FOUND)
 			set(WITH_MEM_JEMALLOC OFF)
 		endif()
 	endif()
 
 	if (WITH_INPUT_NDOF)
-		find_package(Spacenav)
+		find_package_wrapper(Spacenav)
 		if(NOT SPACENAV_FOUND)
 			set(WITH_INPUT_NDOF OFF)
 		endif()
 	if(WITH_BOOST)
 		# uses in build instructions to override include and library variables
 		if(NOT BOOST_CUSTOM)
-			# use lib dir if available and nothing else specified
-			if(LIBDIR AND NOT BOOST_ROOT)
-				set(BOOST_ROOT ${LIBDIR}/boost)
+			# XXX No more lib dir, is this multithread stuff still needed?
+			if(${WITH_STATIC_LIBS})
+				set(Boost_USE_STATIC_LIBS ON)
+			endif()
+			if(NOT BOOST_ROOT)
 				set(Boost_USE_MULTITHREADED OFF)
 			else()
 				set(Boost_USE_MULTITHREADED ON)
 			endif()
-			set(__boost_packages filesystem regex system thread)
+			set(__boost_packages filesystem regex system thread date_time)
 			if (WITH_INTERNATIONAL)
 				list(APPEND __boost_packages locale)
 			endif()
 			find_package(Boost 1.34 COMPONENTS ${__boost_packages})
+			if(Boost_USE_STATIC_LIBS AND Boost_USE_ICU)
+				find_package(IcuLinux)
+			endif()
 			mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
 		endif()
 
 	endif()
 
 	if(WITH_OPENIMAGEIO)
-		# use lib dir if available and nothing else specified
-		if(LIBDIR AND NOT OPENIMAGEIO_ROOT_DIR)
-			set(OPENIMAGEIO_ROOT_DIR ${LIBDIR}/oiio)
-		endif()
-
-		find_package(OpenImageIO)
+		find_package_wrapper(OpenImageIO)
 
 		set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
 		set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
 	endif()
 
 	if(WITH_OPENCOLORIO)
-		# use lib dir if available and nothing else specified
-		if(LIBDIR AND NOT OPENCOLORIO_ROOT_DIR)
-			set(OPENCOLORIO_ROOT_DIR ${LIBDIR}/ocio)
-		endif()
-
-		find_package(OpenColorIO)
+		find_package_wrapper(OpenColorIO)
 
 		set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
 		set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
 		endif()
 	endif()
 
+	# XXX Maybe most of this section should go into an llvm module?
 	if(WITH_LLVM)
-		set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH	"Path to the LLVM installation")
-		set(LLVM_VERSION "3.0" CACHE STRING	"Version of LLVM to use")
+		# Set llvm version if not specified
+		if(NOT LLVM_VERSION)
+			set(LLVM_VERSION "3.0")
+		endif()
 		set(LLVM_STATIC YES)
-		if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
-			set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
+		if(LLVM_DIRECTORY)
+			FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
+			if(NOT LLVM_CONFIG)
+				FIND_PROGRAM(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
+			endif()
 		else()
-			set(LLVM_CONFIG llvm-config)
+			FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION})
+			if(NOT LLVM_CONFIG)
+				FIND_PROGRAM(LLVM_CONFIG llvm-config)
+			endif()
 		endif()
 		execute_process(COMMAND ${LLVM_CONFIG} --version
 		                OUTPUT_VARIABLE LLVM_VERSION
 		message(STATUS "LLVM version  = ${LLVM_VERSION}")
 		message(STATUS "LLVM dir      = ${LLVM_DIRECTORY}")
 		message(STATUS "LLVM lib dir  = ${LLVM_LIB_DIR}")
+		set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
+		set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
 
 		if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
 			if(LLVM_STATIC)
 		else()
 			message(FATAL_ERROR "LLVM not found.")
 		endif()
+
+		# Fix for conflict with Mesa llvmpipe
+		set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/source/creator/blender.map")
 	endif()
 
 	if(WITH_CYCLES_OSL)
 		endif()
 	endif()
 
-	set(PLATFORM_LINKFLAGS "-pthread")
+	set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -pthread")
 
 	# lfs on glibc, all compilers should use
 	add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
 		endif()
 	endif()
 
+	if(WITH_LLVM)
+		set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH	"Path to the LLVM installation")
+		file(GLOB LLVM_LIBRARY ${LLVM_DIRECTORY}/lib/*.lib)
+		set(LLVM_STATIC YES)
+	endif()
+
+
 	if(MSVC)
-		set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
+		set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi)
 
 		add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
 
 		if(WITH_IMAGE_OPENEXR)
 			set_lib_path(OPENEXR "openexr")
 			set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
+			set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
 			set(OPENEXR_LIBPATH ${OPENEXR}/lib)
 			set(OPENEXR_LIBRARIES
 				${OPENEXR_LIBPATH}/Iex.lib
 				${OPENEXR_LIBPATH}/Imath.lib
 				${OPENEXR_LIBPATH}/IlmThread.lib
 			)
-			set(OPENEXR_INCLUDE_DIRS
-				${OPENEXR_INCLUDE_DIR}
-				${OPENEXR_INCLUDE_DIR}/IlmImf
-				${OPENEXR_INCLUDE_DIR}/Iex
-				${OPENEXR_INCLUDE_DIR}/Imath
-			)
 		endif()
 
 		if(WITH_IMAGE_TIFF)
 		if(WITH_OPENIMAGEIO)
 			set(OPENIMAGEIO ${LIBDIR}/openimageio)
 			set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
-			set(OPENIMAGEIO_LIBRARIES OpenImageIO)
+			set(OPENIMAGEIO_LIBRARIES optimized OpenImageIO debug OpenImageIO_d)
 			set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
 			set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
 		endif()
 
 	if(WITH_PYTHON)
 		if(NOT WITH_PYTHON_MODULE)
-			# we use precompiled libraries for py 3.2 and up by default
+			# we use precompiled libraries for py 3.3 and up by default
 
 			# normally cached but not since we include them with blender
-			set(PYTHON_VERSION 3.2)
-			set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
+			set(PYTHON_VERSION 3.3)
+			set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
 			# set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
-			set(PYTHON_LIBRARY python${PYTHON_VERSION})
+			set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
 			set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
 			# set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
 		else()
 	if(WITH_BOOST)
 		set(BOOST ${LIBDIR}/boost)
 		set(BOOST_INCLUDE_DIR ${BOOST}/include)
-		set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt)
+		set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
 		if (WITH_INTERNATIONAL)
 			list(APPEND BOOST_LIBRARIES boost_locale-mt)
 			set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale needs it !
 		message(FATAL_ERROR "Cycles reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
 	endif()
 
-	if(WITH_CYCLES_OSL AND NOT WIN32)
+	if(WITH_CYCLES_OSL)
 		if(NOT WITH_LLVM)
 			message(FATAL_ERROR "Cycles OSL reqires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
 		endif()

File blender/GNUmakefile

 
 test_style_osl:
 	# run our own checks on C/C++ style
-	PYTHONIOENCODING=utf_8 python3 $(BLENDER_DIR)/source/tools/check_style_c.py $(BLENDER_DIR)/intern/cycles/kernel/osl
+	PYTHONIOENCODING=utf_8 python3 $(BLENDER_DIR)/source/tools/check_style_c.py $(BLENDER_DIR)/intern/cycles/kernel/shaders
 
 
 test_style_osl_qtc:
 	# run our own checks on C/C++ style
 	USE_QTC_TASK=1 \
-	PYTHONIOENCODING=utf_8 python3 $(BLENDER_DIR)/source/tools/check_style_c.py $(BLENDER_DIR)/intern/cycles/kernel/osl > \
+	PYTHONIOENCODING=utf_8 python3 $(BLENDER_DIR)/source/tools/check_style_c.py $(BLENDER_DIR)/intern/cycles/kernel/shaders > \
 	test_style.tasks
 	@echo "written: test_style.tasks"
 
 	$(BLENDER_DIR)/check_spelling_c.tasks
 
 check_spelling_osl:
-	cd $(BUILD_DIR) ; PYTHONIOENCODING=utf_8 python3 $(BLENDER_DIR)/source/tools/spell_check_source.py $(BLENDER_DIR)/intern/cycles/kernel/osl
+	cd $(BUILD_DIR) ; PYTHONIOENCODING=utf_8 python3 $(BLENDER_DIR)/source/tools/spell_check_source.py $(BLENDER_DIR)/intern/cycles/kernel/shaders
 
 # -----------------------------------------------------------------------------
 # Utilities

File blender/SConstruct

         else:
             env.Append(LINKFLAGS=['-Xlinker','-weak_framework','-Xlinker','Jackmp'])
 
+    if env['WITH_BF_CYCLES_OSL'] == 1:	
+        OSX_OSL_LIBPATH = Dir(env.subst(env['BF_OSL_LIBPATH'])).abspath
+        # we need 2 variants of passing the oslexec with the force_load option, string and list type atm
+        env.Append(LINKFLAGS=['-L'+OSX_OSL_LIBPATH,'-loslcomp','-force_load '+ OSX_OSL_LIBPATH +'/liboslexec.a','-loslquery'])
+        env.Append(BF_PROGRAM_LINKFLAGS=['-Xlinker','-force_load','-Xlinker',OSX_OSL_LIBPATH +'/liboslexec.a'])
+
 if env['WITH_BF_OPENMP'] == 1:
         if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
                 env['CCFLAGS'].append('/openmp')
 
 Export('env')
 
-BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
+VariantDir(B.root_build_dir+'/source', 'source', duplicate=0)
 SConscript(B.root_build_dir+'/source/SConscript')
-BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
+VariantDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
 SConscript(B.root_build_dir+'/intern/SConscript')
-BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
+VariantDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
 SConscript(B.root_build_dir+'/extern/SConscript')
 
 # now that we have read all SConscripts, we know what
                     cubin_file = os.path.join(kernel_build_dir, "kernel_%s.cubin" % arch)
                     scriptinstall.append(env.Install(dir=dir,source=cubin_file))
 
+            # osl shaders
+            if env['WITH_BF_CYCLES_OSL']:
+                dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'shader')
+
+                osl_source_dir = Dir('./intern/cycles/kernel/shaders').srcnode().path
+                oso_build_dir = os.path.join(B.root_build_dir, 'intern/cycles/kernel/shaders')
+
+                headers='node_color.h node_fresnel.h node_texture.h oslutil.h stdosl.h'.split()
+                source=['intern/cycles/kernel/shaders/'+s for s in headers]
+                scriptinstall.append(env.Install(dir=dir,source=source))
+
+                for f in os.listdir(osl_source_dir):
+                    if f.endswith('.osl'):
+                        oso_file = os.path.join(oso_build_dir, f.replace('.osl', '.oso'))
+                        scriptinstall.append(env.Install(dir=dir,source=oso_file))
+
     if env['WITH_BF_OCIO']:
         colormanagement = os.path.join('release', 'datafiles', 'colormanagement')
 
         dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb.dll')
     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
 
-    if env['WITH_BF_OIIO'] and env['OURPLATFORM'] != 'win32-mingw':
-        dllsources.append('${LCGDIR}/openimageio/bin/OpenImageIO.dll')
-
     if env['WITH_BF_OCIO']:
         if not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
             dllsources.append('${LCGDIR}/opencolorio/bin/OpenColorIO.dll')

File blender/build_files/build_environment/install_deps.sh

 
 DISTRO=""
 SRC="$HOME/src/blender-deps"
+INST="/opt/lib"
 CWD=$PWD
 
+# OSL is horror for manual building even
+# i would want it to be setteled for manual build first,
+# and only then do it automatically
+BUILD_OSL=false
+
+# Try to link everything statically. Use this to produce protable versions of blender.
+ALL_STATIC=false
+
 THREADS=`cat /proc/cpuinfo | grep cores | uniq | sed -e "s/.*: *\(.*\)/\\1/"`
+if [ -z "$THREADS" ]; then
+  THREADS=1
+fi
+
+COMMON_INFO="Source code of dependencies needed to be compiled will be downloaded and extracted into '$SRC'.
+Built libs of dependencies needed to be compiled will be installed into '$INST'.
+Please edit \$SRC and/or \$INST variables at the begining of this script if you want to use other paths!
+
+Number of threads for building: $THREADS.
+Building OSL: $BUILD_OSL (edit \$BUILD_OSL var to change this).
+All static linking: $ALL_STATIC (edit \$ALL_STATIC var to change this)."
+
 
 PYTHON_VERSION="3.3.0"
-BOOST_VERSION="1_51_0"
-OIIO_VERSION="1.1.0"
+PYTHON_VERSION_MIN="3.3"
+PYTHON_SOURCE="http://python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.bz2"
+
+BOOST_VERSION="1.51.0"
+_boost_version_nodots=`echo "$BOOST_VERSION" | sed -r 's/\./_/g'`
+BOOST_SOURCE="http://sourceforge.net/projects/boost/files/boost/$BOOST_VERSION/boost_$_boost_version_nodots.tar.bz2/download"
+BOOST_VERSION_MIN="1.49"
+
 OCIO_VERSION="1.0.7"
+OCIO_SOURCE="https://github.com/imageworks/OpenColorIO/tarball/v$OCIO_VERSION"
+OCIO_VERSION_MIN="1.0"
+
+OIIO_VERSION="1.1.1"
+OIIO_SOURCE="https://github.com/OpenImageIO/oiio/tarball/Release-$OIIO_VERSION"
+OIIO_VERSION_MIN="1.1"
+
+LLVM_VERSION="3.1"
+LLVM_VERSION_MIN="3.0"
+LLVM_VERSION_FOUND=""
+LLVM_SOURCE="http://llvm.org/releases/$LLVM_VERSION/llvm-$LLVM_VERSION.src.tar.gz"
+LLVM_CLANG_SOURCE="http://llvm.org/releases/$LLVM_VERSION/clang-$LLVM_VERSION.src.tar.gz"
+
+# OSL needs to be compiled for now!
+OSL_VERSION="1.2.0"
+OSL_SOURCE="https://github.com/mont29/OpenShadingLanguage/archive/blender-fixes.tar.gz"
+
 FFMPEG_VERSION="1.0"
+FFMPEG_SOURCE="http://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2"
+FFMPEG_VERSION_MIN="0.7.6"
 _ffmpeg_list_sep=";"
 
-# XXX Looks like ubuntu has libxvidcore4-dev, while debian has libxvidcore-dev...
-HASXVID=false
-XVIDDEV=""
-HASVPX=false
-HASMP3LAME=false
-HASX264=false
-HASOPENJPEG=false
-HASSCHRO=false
+# FFMPEG optional libs.
+VORBIS_USE=false
+VORBIS_DEV=""
+SCHRO_USE=false
+SCRHO_DEV=""
+THEORA_USE=false
+THEORA_DEV=""
+XVID_USE=false
+XVID_DEV=""
+X264_USE=false
+X264_DEV=""
+X264_VERSION_MIN=0.118
+VPX_USE=false
+VPX_VERSION_MIN=0.9.7
+VPX_DEV=""
+MP3LAME_USE=false
+MP3LAME_DEV=""
+OPENJPEG_USE=false
+OPENJPEG_DEV=""
 
 # Switch to english language, else some things (like check_package_DEB()) won't work!
 LANG_BACK=$LANG
   echo "${@}"
 }
 
-# Return 1 if $1 >= $2, else 0.
+# Return 0 if $1 = $2 (i.e. 1.01.0 = 1.1, but 1.1.1 != 1.1), else 1.
+# $1 and $2 should be version numbers made of numbers only.
+version_eq() {
+  backIFS=$IFS
+  IFS='.'
+
+  # Split both version numbers into their numeric elements.
+  arr1=( $1 )
+  arr2=( $2 )
+
+  ret=1
+
+  count1=${#arr1[@]}
+  count2=${#arr2[@]}
+  if [ $count2 -ge $count1 ]; then
+    _t=$count1
+    count1=$count2
+    count2=$_t
+    arr1=( $2 )
+    arr2=( $1 )
+  fi
+
+  ret=0
+  for (( i=0; $i < $count2; i++ ))
+  do
+    if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
+      ret=1
+      break
+    fi
+  done
+
+  for (( i=$count2; $i < $count1; i++ ))
+  do
+    if [ $(( 10#${arr1[$i]} )) -ne 0 ]; then
+      ret=1
+      break
+    fi
+  done
+
+  IFS=$backIFS
+  return $ret
+}
+
+# Return 0 if $1 >= $2, else 1.
 # $1 and $2 should be version numbers made of numbers only.
 version_ge() {
-  if [ $(echo -e "$1\n$2" | sort --version-sort | head --lines=1) = "$1" ]; then
-    return 0
-  else
+  version_eq $1 $2
+  if [ $? -eq 1 -a $(echo -e "$1\n$2" | sort --version-sort | head --lines=1) = "$1" ]; then
     return 1
+  else
+    return 0
   fi
 }
 
-# Return 1 if $1 is into $2 (e.g. 3.3.2 is into 3.3, but not 3.3.0 or 3.3.5)
+# Return 0 if $1 is into $2 (e.g. 3.3.2 is into 3.3, but not 3.3.0 or 3.3.5), else 1.
 # $1 and $2 should be version numbers made of numbers only.
 # $1 should be at least as long as $2!
 version_match() {
   arr1=( $1 )
   arr2=( $2 )
 
-  ret=0
+  ret=1
 
   count1=${#arr1[@]}
   count2=${#arr2[@]}
   if [ $count1 -ge $count2 ]; then
-    ret=1
+    ret=0
     for (( i=0; $i < $count2; i++ ))
     do
       if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
-        ret=0
+        ret=1
         break
       fi
     done
 }
 
 prepare_opt() {
-  INFO "Ensuring /opt/lib exists and writable by us"
-  sudo mkdir -p /opt/lib
-  sudo chown $USER /opt/lib
-  sudo chmod 775 /opt/lib
+  INFO "Ensuring $INST exists and is writable by us"
+  sudo mkdir -p $INST
+  sudo chown $USER $INST
+  sudo chmod 775 $INST
+}
+
+# Check whether the current package needs to be recompiled, based on a dummy file containing a magic number in its name...
+magic_compile_check() {
+  if [ -f $INST/.$1-magiccheck-$2 ]; then
+    return 0
+  else
+    return 1
+  fi
+}
+
+magic_compile_set() {
+  rm -f $INST/.$1-magiccheck-*
+  touch $INST/.$1-magiccheck-$2
 }
 
 compile_Python() {
-  if [ ! -d /opt/lib/python-$PYTHON_VERSION ]; then
+  # To be changed each time we make edits that would modify the compiled result!
+  py_magic=0
+
+  _src=$SRC/Python-$PYTHON_VERSION
+  _inst=$INST/python-$PYTHON_VERSION
+
+  # Clean install if needed!
+  magic_compile_check python-$PYTHON_VERSION $py_magic
+  if [ $? -eq 1 ]; then
+    rm -rf $_inst
+  fi
+
+  if [ ! -d $_inst ]; then
     INFO "Building Python-$PYTHON_VERSION"
 
     prepare_opt
 
-    if [ ! -d $SRC/Python-$PYTHON_VERSION ]; then
+    if [ ! -d $_src ]; then
       mkdir -p $SRC
-      wget -c http://python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.bz2 -P $SRC
+      wget -c $PYTHON_SOURCE -O $_src.tar.bz2
 
       INFO "Unpacking Python-$PYTHON_VERSION"
-      tar -C $SRC -xf $SRC/Python-$PYTHON_VERSION.tar.bz2
+      tar -C $SRC -xf $_src.tar.bz2
     fi
 
-    cd $SRC/Python-$PYTHON_VERSION
+    cd $_src
 
-    ./configure --prefix=/opt/lib/python-$PYTHON_VERSION --enable-ipv6 \
+    ./configure --prefix=$_inst --enable-ipv6 \
         --enable-loadable-sqlite-extensions --with-dbmliborder=bdb \
         --with-computed-gotos --with-pymalloc
 
-    make -j$THREADS
-    make install
+    make -j$THREADS && make install
     make clean
 
-    rm -f /opt/lib/python-3.3
-    ln -s python-$PYTHON_VERSION /opt/lib/python-3.3
+    if [ -d $_inst ]; then
+      rm -f $INST/python-3.3
+      ln -s python-$PYTHON_VERSION $INST/python-3.3
+    else
+      ERROR "Python--$PYTHON_VERSION failed to compile, exiting"
+      exit 1
+    fi
+
+    magic_compile_set python-$PYTHON_VERSION $py_magic
 
     cd $CWD
+  else
+    INFO "Own Python-$PYTHON_VERSION is up to date, nothing to do!"
+    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
   fi
 }
 
 compile_Boost() {
-  INFO "Building boost"
+  # To be changed each time we make edits that would modify the compiled result!
+  boost_magic=7
 
-  version_dots=`echo "$BOOST_VERSION" | sed -r 's/_/./g'`
+  _src=$SRC/boost-$BOOST_VERSION
+  _inst=$INST/boost-$BOOST_VERSION
 
-  if [ ! -d /opt/lib/boost-$version_dots ]; then
-    INFO "Building Boost-$version_dots"
+  # Clean install if needed!
+  magic_compile_check boost-$BOOST_VERSION $boost_magic
+  if [ $? -eq 1 ]; then
+    rm -rf $_inst
+  fi
+
+  if [ ! -d $_inst ]; then
+    INFO "Building Boost-$BOOST_VERSION"
 
     prepare_opt
 
-    if [ ! -d $SRC/boost_$BOOST_VERSION ]; then
-      INFO "Downloading Boost-$version_dots"
+    if [ ! -d $_src ]; then
+      INFO "Downloading Boost-$BOOST_VERSION"
       mkdir -p $SRC
-      wget -c http://sourceforge.net/projects/boost/files/boost/$version_dots/boost_$BOOST_VERSION.tar.bz2/download \
-        -O $SRC/boost_$BOOST_VERSION.tar.bz2
-      tar -C $SRC -xf $SRC/boost_$BOOST_VERSION.tar.bz2
+      wget -c $BOOST_SOURCE -O $_src.tar.bz2
+      tar -C $SRC --transform "s,(.*/?)boost_1_[^/]+(.*),\1boost-$BOOST_VERSION\2,x" -xf $_src.tar.bz2
     fi
 
-    cd $SRC/boost_$BOOST_VERSION
-    ./bootstrap.sh --with-libraries=system,filesystem,thread,regex,locale,date-time --prefix=/opt/lib/boost-$version_dots
-    ./b2 install
+    cd $_src
+    if [ ! -f $_src/b2 ]; then
+      ./bootstrap.sh
+    fi
+    ./b2 -j$THREADS -a --with-system --with-filesystem --with-thread --with-regex --with-locale --with-date_time \
+         --prefix=$_inst --disable-icu boost.locale.icu=off install
     ./b2 --clean
 
-    rm -f /opt/lib/boost
-    ln -s boost-$version_dots /opt/lib/boost
+    if [ -d $_inst ]; then
+      rm -f $INST/boost
+      ln -s boost-$BOOST_VERSION $INST/boost
+    else
+      ERROR "Boost-$BOOST_VERSION failed to compile, exiting"
+      exit 1
+    fi
+
+    magic_compile_set boost-$BOOST_VERSION $boost_magic
 
     cd $CWD
+  else
+    INFO "Own Boost-$BOOST_VERSION is up to date, nothing to do!"
+    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
   fi
 }
 
 compile_OCIO() {
-  if [ ! -d /opt/lib/ocio-$OCIO_VERSION ]; then
+  # To be changed each time we make edits that would modify the compiled result!
+  ocio_magic=1
+
+  _src=$SRC/OpenColorIO-$OCIO_VERSION
+  _inst=$INST/ocio-$OCIO_VERSION
+
+  # Clean install if needed!
+  magic_compile_check ocio-$OCIO_VERSION $ocio_magic
+  if [ $? -eq 1 ]; then
+    rm -rf $_inst
+  fi
+
+  if [ ! -d $_inst ]; then
     INFO "Building OpenColorIO-$OCIO_VERSION"
 
     prepare_opt
 
-    if [ ! -d $SRC/OpenColorIO-$OCIO_VERSION ]; then
-        INFO "Downloading OpenColorIO-$OCIO_VERSION"
-        mkdir -p $SRC
-        wget -c http://github.com/imageworks/OpenColorIO/tarball/v$OCIO_VERSION \
-          -O $SRC/OpenColorIO-$OCIO_VERSION.tar.gz
+    if [ ! -d $_src ]; then
+      INFO "Downloading OpenColorIO-$OCIO_VERSION"
+      mkdir -p $SRC
+      wget -c $OCIO_SOURCE -O $_src.tar.gz
 
-        INFO "Unpacking OpenColorIO-$OCIO_VERSION"
-        tar -C "$SRC" -xf $SRC/OpenColorIO-$OCIO_VERSION.tar.gz
-        mv $SRC/imageworks-OpenColorIO* $SRC/OpenColorIO-$OCIO_VERSION
+      INFO "Unpacking OpenColorIO-$OCIO_VERSION"
+      tar -C $SRC --transform "s,(.*/?)imageworks-OpenColorIO[^/]*(.*),\1OpenColorIO-$OCIO_VERSION\2,x" \
+          -xf $_src.tar.gz
     fi
 
-    cd $SRC/OpenColorIO-$OCIO_VERSION
+    cd $_src
+    # Always refresh the whole build!
+    if [ -d build ]; then
+      rm -rf build
+    fi    
     mkdir build
     cd build
 
     fi
 
     cmake -D CMAKE_BUILD_TYPE=Release \
-        -D CMAKE_PREFIX_PATH=/opt/lib/ocio-$OCIO_VERSION \
-        -D CMAKE_INSTALL_PREFIX=/opt/lib/ocio-$OCIO_VERSION \
-        -D CMAKE_CXX_FLAGS="$cflags" \
-        -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" \
-        ..
+          -D CMAKE_PREFIX_PATH=$_inst \
+          -D CMAKE_INSTALL_PREFIX=$_inst \
+          -D CMAKE_CXX_FLAGS="$cflags" \
+          -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" \
+          -D OCIO_BUILD_APPS=OFF \
+          -D OCIO_BUILD_PYGLUE=OFF \
+          ..
 
-    make -j$THREADS
-    make install
+    make -j$THREADS && make install
 
-    # Force linking against sttaic libs
-    rm -f /opt/lib/ocio-$OCIO_VERSION/lib/*.so*
+    # Force linking against static libs
+    rm -f $_inst/lib/*.so*
 
     # Additional depencencies
-    cp ext/dist/lib/libtinyxml.a /opt/lib/ocio-$OCIO_VERSION/lib
-    cp ext/dist/lib/libyaml-cpp.a /opt/lib/ocio-$OCIO_VERSION/lib
+    cp ext/dist/lib/libtinyxml.a $_inst/lib
+    cp ext/dist/lib/libyaml-cpp.a $_inst/lib
 
     make clean
 
-    rm -f /opt/lib/ocio
-    ln -s ocio-$OCIO_VERSION /opt/lib/ocio
+    if [ -d $_inst ]; then
+      rm -f $INST/ocio
+      ln -s ocio-$OCIO_VERSION $INST/ocio
+    else
+      ERROR "OpenColorIO-$OCIO_VERSION failed to compile, exiting"
+      exit 1
+    fi
+
+    magic_compile_set ocio-$OCIO_VERSION $ocio_magic
 
     cd $CWD
+  else
+    INFO "Own OpenColorIO-$OCIO_VERSION is up to date, nothing to do!"
+    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
   fi
 }
 
 compile_OIIO() {
-  if [ ! -d /opt/lib/oiio-$OIIO_VERSION ]; then
+  # To be changed each time we make edits that would modify the compiled result!
+  oiio_magic=6
+
+  _src=$SRC/OpenImageIO-$OIIO_VERSION
+  _inst=$INST/oiio-$OIIO_VERSION
+
+  # Clean install if needed!
+  magic_compile_check oiio-$OIIO_VERSION $oiio_magic
+  if [ $? -eq 1 ]; then
+    rm -rf $_inst
+  fi
+
+  if [ ! -d $_inst ]; then
     INFO "Building OpenImageIO-$OIIO_VERSION"
 
     prepare_opt
 
-    if [ ! -d $SRC/OpenImageIO-$OIIO_VERSION ]; then
-      wget -c https://github.com/OpenImageIO/oiio/tarball/Release-$OIIO_VERSION \
-          -O "$SRC/OpenImageIO-$OIIO_VERSION.tar.gz"
+    if [ ! -d $_src ]; then
+      wget -c $OIIO_SOURCE -O "$_src.tar.gz"
 
       INFO "Unpacking OpenImageIO-$OIIO_VERSION"
-      tar -C $SRC -xf $SRC/OpenImageIO-$OIIO_VERSION.tar.gz
-      mv $SRC/OpenImageIO-oiio* $SRC/OpenImageIO-$OIIO_VERSION
+      tar -C $SRC --transform "s,(.*/?)OpenImageIO-oiio[^/]*(.*),\1OpenImageIO-$OIIO_VERSION\2,x" \
+          -xf $_src.tar.gz
+
+      cd $_src
+
+      # XXX Ugly patching hack!
+      cat << EOF | patch -p1
+diff --git a/src/libutil/SHA1.cpp b/src/libutil/SHA1.cpp
+index b9e6c8b..c761185 100644
+--- a/src/libutil/SHA1.cpp
++++ b/src/libutil/SHA1.cpp
+@@ -8,9 +8,9 @@
+ 
+ // If compiling with MFC, you might want to add #include "StdAfx.h"
+ 
++#include "SHA1.h"
+ #include "hash.h"
+ #include "dassert.h"
+-#include "SHA1.h"
+ 
+ #ifdef SHA1_UTILITY_FUNCTIONS
+ #define SHA1_MAX_FILE_BUFFER 8000
+EOF
+
+      cd $CWD
+
     fi
 
-    cd $SRC/OpenImageIO-$OIIO_VERSION
+    cd $_src
+    # Always refresh the whole build!
+    if [ -d build ]; then
+      rm -rf build
+    fi    
     mkdir build
     cd build
 
-    if [ -d /opt/lib/boost ]; then
-      boost_root="/opt/lib/boost"
-    else
-      boost_root="/usr"
+    cmake_d="-D CMAKE_BUILD_TYPE=Release"
+    cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
+    cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
+    cmake_d="$cmake_d -D BUILDSTATIC=ON"
+    cmake_d="$cmake_d -D LINKSTATIC=ON"
+
+    if [ -d $INST/boost ]; then
+      cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
+      if $ALL_STATIC; then
+        cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"        
+      fi
     fi
 
+    # Looks like we do not need ocio in oiio for now...
+#    if [ -d $INST/ocio ]; then
+#      cmake_d="$cmake_d -D OCIO_PATH=$INST/ocio"
+#    fi
+
     if file /bin/cp | grep -q '32-bit'; then
       cflags="-fPIC -m32 -march=i686"
     else
       cflags="-fPIC"
     fi
 
-    cmake -D CMAKE_BUILD_TYPE=Release \
-        -D CMAKE_PREFIX_PATH=/opt/lib/oiio-$OIIO_VERSION \
-        -D CMAKE_INSTALL_PREFIX=/opt/lib/oiio-$OIIO_VERSION \
-        -D BUILDSTATIC=ON \
-        -D CMAKE_CXX_FLAGS="$cflags" \
-        -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" \
-        -D BOOST_ROOT="$boost_root" \
-        ../src
-
-    make -j$THREADS
-    make install
+    cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ../src
+
+    make -j$THREADS && make install
+    make clean
+
+    if [ -d $_inst ]; then
+      rm -f $INST/oiio
+      ln -s oiio-$OIIO_VERSION $INST/oiio
+    else
+      ERROR "OpenImageIO-$OIIO_VERSION failed to compile, exiting"
+      exit 1
+    fi
+
+    magic_compile_set oiio-$OIIO_VERSION $oiio_magic
+
+    cd $CWD
+  else
+    INFO "Own OpenImageIO-$OIIO_VERSION is up to date, nothing to do!"
+    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
+  fi
+}
+
+compile_LLVM() {
+  # To be changed each time we make edits that would modify the compiled result!
+  llvm_magic=1
+
+  _src=$SRC/LLVM-$LLVM_VERSION
+  _inst=$INST/llvm-$LLVM_VERSION
+  _src_clang=$SRC/CLANG-$LLVM_VERSION
+
+  # Clean install if needed!
+  magic_compile_check llvm-$LLVM_VERSION $llvm_magic
+  if [ $? -eq 1 ]; then
+    rm -rf $_inst
+    rm -rf $_inst_clang
+  fi
+
+  if [ ! -d $_inst ]; then
+    INFO "Building LLVM-$LLVM_VERSION (CLANG included!)"
+
+    prepare_opt
+
+    if [ ! -d $_src -o true ]; then
+      wget -c $LLVM_SOURCE -O "$_src.tar.gz"
+      wget -c $LLVM_CLANG_SOURCE -O "$_src_clang.tar.gz"
+
+      INFO "Unpacking LLVM-$LLVM_VERSION"
+      tar -C $SRC --transform "s,([^/]*/?)llvm-[^/]*(.*),\1LLVM-$LLVM_VERSION\2,x" \
+          -xf $_src.tar.gz
+      INFO "Unpacking CLANG-$LLVM_VERSION to $_src/tools/clang"
+      tar -C $_src/tools \
+          --transform "s,([^/]*/?)clang-[^/]*(.*),\1clang\2,x" \
+          -xf $_src_clang.tar.gz
+
+      cd $_src
+
+      # XXX Ugly patching hack!
+      cat << EOF | patch -p1
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -13,7 +13,7 @@
+ set(LLVM_VERSION_MAJOR 3)
+ set(LLVM_VERSION_MINOR 1)
+ 
+-set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}svn")
++set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}")
+ 
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+ 
+EOF
+
+      cd $CWD
+
+    fi
+
+    cd $_src
+
+    # Always refresh the whole build!
+    if [ -d build ]; then
+      rm -rf build
+    fi    
+    mkdir build
+    cd build
+
+    cmake_d="-D CMAKE_BUILD_TYPE=Release"
+    cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
+    cmake_d="$cmake_d -D LLVM_ENABLE_FFI=ON"
+
+    if [ -d $_FFI_INCLUDE_DIR ]; then
+      cmake_d="$cmake_d -D FFI_INCLUDE_DIR=$_FFI_INCLUDE_DIR"
+    fi
+
+    cmake $cmake_d ..
+
+    make -j$THREADS && make install
+    make clean
+
+    if [ -d $_inst ]; then
+      rm -f $INST/llvm
+      ln -s llvm-$LLVM_VERSION $INST/llvm
+    else
+      ERROR "LLVM-$LLVM_VERSION failed to compile, exiting"
+      exit 1
+    fi
+
+    magic_compile_set llvm-$LLVM_VERSION $llvm_magic
+
+    cd $CWD
+  else
+    INFO "Own LLVM-$LLVM_VERSION (CLANG included) is up to date, nothing to do!"
+    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
+  fi
+}
+
+compile_OSL() {
+  # To be changed each time we make edits that would modify the compiled result!
+  osl_magic=7
+
+  _src=$SRC/OpenShadingLanguage-$OSL_VERSION
+  _inst=$INST/osl-$OSL_VERSION
+
+  # Clean install if needed!
+  magic_compile_check osl-$OSL_VERSION $osl_magic
+  if [ $? -eq 1 ]; then
+    rm -rf $_inst
+  fi
+
+  if [ ! -d $_inst ]; then
+    INFO "Building OpenShadingLanguage-$OSL_VERSION"
+
+    prepare_opt
+
+    if [ ! -d $_src ]; then
+      # XXX Using git on my own repo for now, looks like archives are not updated immediately... :/
+#      wget -c $OSL_SOURCE -O "$_src.tar.gz"
+
+#      INFO "Unpacking OpenShadingLanguage-$OSL_VERSION"
+#      tar -C $SRC --transform "s,(.*/?)OpenShadingLanguage-[^/]*(.*),\1OpenShadingLanguage-$OSL_VERSION\2,x" \
+#          -xf $_src.tar.gz
+      git clone https://github.com/mont29/OpenShadingLanguage.git $_src
+      cd $_src
+      git checkout blender-fixes
+      cd $CWD
+    fi
+
+    cd $_src
+    # XXX For now, always update from latest repo...
+    git pull origin
+
+    # Always refresh the whole build!
+    if [ -d build ]; then
+      rm -rf build
+    fi    
+    mkdir build
+    cd build
+
+    cmake_d="-D CMAKE_BUILD_TYPE=Release"
+    cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
+    cmake_d="$cmake_d -D BUILDSTATIC=ON"
+    cmake_d="$cmake_d -D BUILD_TESTING=OFF"
+
+    if [ -d $INST/boost ]; then
+      cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
+      if $ALL_STATIC; then
+        cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"        
+      fi
+    fi
+
+    if [ -d $INST/oiio ]; then
+      cmake_d="$cmake_d -D OPENIMAGEIOHOME=$INST/oiio"
+    fi
+
+    if [ ! -z $LLVM_VERSION_FOUND ]; then
+      cmake_d="$cmake_d -D LLVM_VERSION=$LLVM_VERSION_FOUND"
+      if [ -d $INST/llvm ]; then
+        cmake_d="$cmake_d -D LLVM_DIRECTORY=$INST/llvm"
+        cmake_d="$cmake_d -D LLVM_STATIC=ON"
+      fi
+    fi
+
+    cmake $cmake_d ../src
+
+    make -j$THREADS && make install
     make clean
 
-    rm -f /opt/lib/oiio
-    ln -s oiio-$OIIO_VERSION /opt/lib/oiio
+    if [ -d $_inst ]; then
+      rm -f $INST/osl
+      ln -s osl-$OSL_VERSION $INST/osl
+    else
+      ERROR "OpenShadingLanguage-$OSL_VERSION failed to compile, exiting"
+      exit 1
+    fi
+
+    magic_compile_set osl-$OSL_VERSION $osl_magic
 
     cd $CWD
+  else
+    INFO "Own OpenShadingLanguage-$OSL_VERSION is up to date, nothing to do!"
+    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
   fi
 }
 
 compile_FFmpeg() {
-  if [ ! -d /opt/lib/ffmpeg-$FFMPEG_VERSION ]; then
-    INFO "Building FFmpeg-$FFMPEG_VERSION"
+  # To be changed each time we make edits that would modify the compiled result!
+  ffmpeg_magic=3
+
+  _src=$SRC/ffmpeg-$FFMPEG_VERSION
+  _inst=$INST/ffmpeg-$FFMPEG_VERSION
+
+  # Clean install if needed!
+  magic_compile_check ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
+  if [ $? -eq 1 ]; then
+    rm -rf $_inst
+  fi
+
+  if [ ! -d $_inst ]; then
+    INFO "Building ffmpeg-$FFMPEG_VERSION"
 
     prepare_opt
 
-    if [ ! -d $SRC/ffmpeg-$FFMPEG_VERSION ]; then
-      INFO "Downloading FFmpeg-$FFMPEG_VERSION"
-      wget -c http://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2 -P $SRC
+    if [ ! -d $_src ]; then
+      INFO "Downloading ffmpeg-$FFMPEG_VERSION"
+      wget -c $FFMPEG_SOURCE -O "$_src.tar.bz2"
 
-      INFO "Unpacking FFmpeg-$FFMPEG_VERSION"
-      tar -C $SRC -xf $SRC/ffmpeg-$FFMPEG_VERSION.tar.bz2
+      INFO "Unpacking ffmpeg-$FFMPEG_VERSION"
+      tar -C $SRC -xf $_src.tar.bz2
     fi
 
-    cd $SRC/ffmpeg-$FFMPEG_VERSION
+    cd $_src
 
     extra=""
 
-    if $HASXVID; then
-      extra="$extra --enable-libxvid"
+    if $VORBIS_USE; then
+      extra="$extra --enable-libvorbis"
     fi
 
-    if $HASVPX; then
-      extra="$extra --enable-libvpx"
+    if $THEORA_USE; then
+      extra="$extra --enable-libtheora"
     fi
 
-    if $HASMP3LAME; then
-      extra="$extra --enable-libmp3lame"
+    # XXX At least under Debian, static schro gives problem at blender linking time... :/
+    if $SCHRO_USE && ! $ALL_STATIC; then
+      extra="$extra --enable-libschroedinger"
+    fi
+
+    if $XVID_USE; then
+      extra="$extra --enable-libxvid"
     fi
 
-    if $HASX264; then
+    if $X264_USE; then
       extra="$extra --enable-libx264"
     fi
 
-    if $HASOPENJPEG; then
-      extra="$extra --enable-libopenjpeg"
+    if $VPX_USE; then
+      extra="$extra --enable-libvpx"
     fi
 
-    if $HASSCHRO; then
-      extra="$extra --enable-libschroedinger"
+    if $MP3LAME_USE; then
+      extra="$extra --enable-libmp3lame"
     fi
 
-    ./configure --cc="gcc -Wl,--as-needed" --extra-ldflags="-pthread -static-libgcc" \
-        --prefix=/opt/lib/ffmpeg-$FFMPEG_VERSION --enable-static --enable-avfilter --disable-vdpau \
-        --disable-bzlib --disable-libgsm --disable-libspeex --enable-libtheora \
-        --enable-libvorbis --enable-pthreads --enable-zlib --enable-stripping --enable-runtime-cpudetect \
+    if $OPENJPEG_USE; then
+      extra="$extra --enable-libopenjpeg"
+    fi
+
+    ./configure --cc="gcc -Wl,--as-needed" \
+        --extra-ldflags="-pthread -static-libgcc" \
+        --prefix=$_inst --enable-static \
+        --disable-ffplay --disable-ffserver --disable-doc \
+        --enable-gray \