Overhaul of makepanda's thirdparty package handling. It now supports searching the system for thirdparty packages, and makes great use of pkg-config.

This commit is contained in:
rdb 2009-09-20 19:23:17 +00:00
parent a1add7d090
commit f4cf3bfdd4
2 changed files with 206 additions and 104 deletions

View File

@ -30,7 +30,6 @@ from installpanda import *
########################################################################
COMPILER=0
THIRDPARTYLIBS=0
VC90CRTVERSION=""
INSTALLER=0
GENMAN=0
@ -46,7 +45,7 @@ PkgListSet(MAYAVERSIONS + MAXVERSIONS + DXVERSIONS + [
"PYTHON","ZLIB","PNG","JPEG","TIFF","VRPN","TINYXML",
"FMODEX","OPENAL","NVIDIACG","OPENSSL","FREETYPE",
"FFTW","ARTOOLKIT","SQUISH","ODE","DIRECTCAM","NPAPI",
"OPENCV","FFMPEG","FCOLLADA","PANDATOOL"
"OPENCV","FFMPEG","FCOLLADA","GTK2","PANDATOOL"
])
CheckPandaSourceTree()
@ -237,33 +236,9 @@ SdkAutoDisableMax()
if (sys.platform == "win32"):
SetupVisualStudioEnviron()
COMPILER="MSVC"
if (platform.architecture()[0] == "64bit"):
THIRDPARTYLIBS="thirdparty/win-libs-vc9-x64/"
else:
THIRDPARTYLIBS="thirdparty/win-libs-vc9/"
if not os.path.isdir(THIRDPARTYLIBS):
THIRDPARTYLIBS="thirdparty/win-libs-vc9/"
VC90CRTVERSION = GetVC90CRTVersion(THIRDPARTYLIBS+"extras/bin/Microsoft.VC90.CRT.manifest")
else:
CheckLinkerLibraryPath()
COMPILER="LINUX"
if (sys.platform == "darwin"):
THIRDPARTYLIBS="thirdparty/darwin-libs-a/"
elif (sys.platform.startswith("linux")):
if (platform.architecture()[0] == "64bit"):
THIRDPARTYLIBS="thirdparty/linux-libs-x64/"
else:
THIRDPARTYLIBS="thirdparty/linux-libs-a/"
elif (sys.platform.startswith("freebsd")):
if (platform.architecture()[0] == "64bit"):
THIRDPARTYLIBS="thirdparty/freebsd-libs-x64/"
else:
THIRDPARTYLIBS="thirdparty/freebsd-libs-a/"
else:
exit("Unknown platform")
VC90CRTVERSION = 0
builtdir = os.path.join(os.path.abspath(GetOutputDir()))
AddToPathEnv("PYTHONPATH", builtdir)
@ -397,18 +372,7 @@ if (COMPILER=="LINUX"):
IncDirectory("FREETYPE", "/usr/X11R6/include")
IncDirectory("FREETYPE", "/usr/X11/include/freetype2")
IncDirectory("GLUT", "/usr/X11R6/include")
if (PkgSkip("PNG")==0): LibName("PNG", "-lpng")
if (PkgSkip("FREETYPE")==0): LibName("FREETYPE", "-lfreetype")
elif (LocateBinary("pkg-config")):
PkgConfigEnable("GTK2", "gtk+-2.0")
PkgConfigEnable("FREETYPE", "freetype2")
PkgConfigEnable("PNG", "libpng")
else:
exit("Failed to locate pkg-config binary!")
if (LocateBinary("wx-config")):
PkgConfigEnable("WX", "", tool = "wx-config")
if (platform.uname()[1]=="pcbsd"):
IncDirectory("ALWAYS", "/usr/PCBSD/local/include")
LibDirectory("ALWAYS", "/usr/PCBSD/local/lib")
@ -416,21 +380,38 @@ if (COMPILER=="LINUX"):
if (os.path.exists("/usr/lib64")):
IncDirectory("GTK2", "/usr/lib64/glib-2.0/include")
IncDirectory("GTK2", "/usr/lib64/gtk-2.0/include")
if (sys.platform == "darwin"):
pkgs = ["VRPN", "FFTW", "FMODEX", "ARTOOLKIT", "ODE", "OPENCV", "FCOLLADA", "SQUISH", "FFMPEG", "PNG", "JPEG", "TIFF", "TINYXML", "NPAPI"]
else:
pkgs = ["VRPN", "FFTW", "FMODEX", "ARTOOLKIT", "ODE", "OPENCV", "FCOLLADA", "SQUISH", "NVIDIACG", "FFMPEG", "OPENAL", "TINYXML", "NPAPI"]
for pkg in pkgs:
if (PkgSkip(pkg)==0):
if (os.path.isdir(THIRDPARTYLIBS + pkg.lower())):
IncDirectory(pkg, THIRDPARTYLIBS + pkg.lower() + "/include")
LibDirectory(pkg, THIRDPARTYLIBS + pkg.lower() + "/lib")
else:
WARNINGS.append("I cannot locate SDK for " + pkg + " in thirdparty directory.")
WARNINGS.append("I have automatically added this command-line option: --no-"+pkg.lower())
PkgDisable(pkg)
ffmpeg_libs = ("libavutil", "libavcodec", "libavformat", "libswscale")
# Name pkg-config libs, include(dir)s
PkgEnable("ARTOOLKIT", "", ("AR"), "AR/ar.h")
PkgEnable("FCOLLADA", "", ("FCollada"), "FCollada.h")
PkgEnable("FFMPEG", ffmpeg_libs, ffmpeg_libs, ffmpeg_libs)
PkgEnable("FFTW", "", ("fftw", "rfftw"), ("fftw.h", "rfftw.h"))
PkgEnable("FMODEX", "", ("fmodex"), ("fmodex", "fmodex/fmod.h"))
PkgEnable("FREETYPE", "freetype2", ("freetype"), "freetype2/freetype/freetype.h")
PkgEnable("GLUT", "gl", ("GL"), ("GL/gl.h", "GL/glu.h"), framework = "OpenGL")
PkgEnable("GTK2", "gtk+-2.0")
PkgEnable("JPEG", "", ("jpeg"), "jpeglib.h")
PkgEnable("NVIDIACG", "", ("Cg"), "Cg/cg.h", framework = "Cg")
PkgEnable("ODE", "", ("ode"), "ode/ode.h")
PkgEnable("OPENAL", "openal", ("openal"), "AL/al.h", framework = "OpenAL")
PkgEnable("OPENCV", "", ("cv", "highgui", "cvaux", "ml", "cxcore"), ("opencv", "opencv/cv.h"))
PkgEnable("OPENSSL", "openssl", ("ssl", "crypto"), ("openssl/ssl.h", "openssl/crypto.h"))
PkgEnable("PNG", "libpng", ("png"), "png.h")
PkgEnable("SQUISH", "", ("squish"), "squish.h")
PkgEnable("TIFF", "", ("tiff"), "tiff.h")
PkgEnable("TINYXML", "", ("tinyxml"), "tinyxml.h")
PkgEnable("VRPN", "", ("vrpn", "quat"), ("quat.h", "vrpn_Types.h"))
PkgEnable("ZLIB", "", ("z"), "zlib.h")
PkgEnable("PYTHON", "", SDK["PYTHONVERSION"], (SDK["PYTHONVERSION"], SDK["PYTHONVERSION"] + "/Python.h"), tool = SDK["PYTHONVERSION"] + "-config", framework = "Python")
if (RUNTIME):
PkgEnable("NPAPI", "", (), ("xulrunner-*/stable", "xulrunner-*/stable/npapi.h"))
PkgEnable("WX", tool = "wx-config")
if (sys.platform != "darwin"):
PkgEnable("X11", "x11", "X11", "Xlib.h")
PkgEnable("XF86DGA", "xxf86dga", "Xxf86dga", "X11/extensions/xf86dga.h")
for pkg in MAYAVERSIONS:
if (PkgSkip(pkg)==0 and (pkg in SDK)):
# On OSX, the dir *can* be named 'MacOS' instead of 'lib'.
@ -442,55 +423,15 @@ if (COMPILER=="LINUX"):
IncDirectory(pkg, SDK[pkg] + "/include")
DefSymbol(pkg, "MAYAVERSION", pkg)
if (sys.platform == "darwin"):
if (PkgSkip("PYTHON")==0): LibName("PYTHON", "-framework Python")
if (PkgSkip("NVIDIACG")==0): LibName("NVIDIACG", "-framework Cg")
if (PkgSkip("OPENAL")==0): LibName("OPENAL", "-framework OpenAL")
if (PkgSkip("OPENSSL")==0): LibName("OPENSSL", "-lcrypto")
if (PkgSkip("TIFF")==0): LibName("TIFF", "-lpandatiff")
else:
if (PkgSkip("PYTHON")==0): LibName("PYTHON", "-l" + SDK["PYTHONVERSION"])
if (PkgSkip("NVIDIACG")==0): LibName("CGGL", "-lCgGL")
if (PkgSkip("NVIDIACG")==0): LibName("NVIDIACG", "-lCg")
if (PkgSkip("OPENAL")==0): LibName("OPENAL", "-lopenal")
if (PkgSkip("TIFF")==0): LibName("TIFF", "-ltiff")
if (PkgSkip("SQUISH")==0): LibName("SQUISH", "-lsquish")
if (PkgSkip("FCOLLADA")==0): LibName("FCOLLADA", "-lFCollada")
if (PkgSkip("FMODEX")==0): LibName("FMODEX", "-lfmodex")
if (PkgSkip("FFMPEG")==0): LibName("FFMPEG", "-lavutil")
if (PkgSkip("FFMPEG")==0): LibName("FFMPEG", "-lavformat")
if (PkgSkip("FFMPEG")==0): LibName("FFMPEG", "-lavcodec")
if (PkgSkip("FFMPEG")==0): LibName("FFMPEG", "-lavformat")
if (PkgSkip("FFMPEG")==0): LibName("FFMPEG", "-lavutil")
if (PkgSkip("FFMPEG")==0): LibName("FFMPEG", "-lswscale")
if (PkgSkip("OPENSSL")==0): LibName("OPENSSL", "-lssl")
if (PkgSkip("ZLIB")==0): LibName("ZLIB", "-lz")
if (PkgSkip("JPEG")==0): LibName("JPEG", "-ljpeg")
if (PkgSkip("VRPN")==0): LibName("VRPN", "-lvrpn")
if (PkgSkip("VRPN")==0): LibName("VRPN", "-lquat")
if (PkgSkip("FFTW")==0): LibName("FFTW", "-lrfftw")
if (PkgSkip("FFTW")==0): LibName("FFTW", "-lfftw")
if (PkgSkip("ARTOOLKIT")==0): LibName("ARTOOLKIT", "-lAR")
if (PkgSkip("ODE")==0): LibName("ODE", "-lode")
if (PkgSkip("OPENCV")==0): LibName("OPENCV", "-lcv")
if (PkgSkip("OPENCV")==0): LibName("OPENCV", "-lhighgui")
if (PkgSkip("OPENCV")==0): LibName("OPENCV", "-lcvaux")
if (PkgSkip("OPENCV")==0): LibName("OPENCV", "-lml")
if (PkgSkip("OPENCV")==0): LibName("OPENCV", "-lcxcore")
if (PkgSkip("TINYXML")==0): LibName("TINYXML", "-ltinyxml")
LibName("X11", "-lX11")
LibName("XF86DGA", "-lXxf86dga")
if (sys.platform == "darwin"):
LibName("ALWAYS", "-framework AppKit")
if (PkgSkip("OPENCV")==0): LibName("OPENCV", "-framework QuickTime")
LibName("AGL", "-framework AGL")
LibName("CARBON", "-framework Carbon")
LibName("COCOA", "-framework Cocoa")
LibName("GLUT", "-framework OpenGL")
# Fix for a bug in OSX:
LibName("GLUT", "-dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
else:
LibName("GLUT", "-lGL")
LibName("GLUT", "-lGLU")
for pkg in MAYAVERSIONS:
@ -558,8 +499,6 @@ def printStatus(header,warnings):
print ""
sys.stdout.flush()
printStatus("Makepanda Initial Status Report", WARNINGS)
########################################################################
##
## BracketNameWithQuotes

View File

@ -9,7 +9,7 @@
##
########################################################################
import sys,os,time,stat,string,re,getopt,cPickle,fnmatch,threading,Queue,signal,shutil,platform
import sys,os,time,stat,string,re,getopt,cPickle,fnmatch,threading,Queue,signal,shutil,platform,glob
from distutils import sysconfig
SUFFIX_INC=[".cxx",".c",".h",".I",".yxx",".lxx",".mm",".rc",".r",".plist"]
@ -55,6 +55,37 @@ for (ver,key) in MAYAVERSIONINFO:
for (ver,key1,key2,subdir) in MAXVERSIONINFO:
MAXVERSIONS.append(ver)
########################################################################
##
## Thirdparty libraries paths
##
########################################################################
if (sys.platform == "win32"):
if (platform.architecture()[0] == "64bit"):
THIRDPARTYLIBS="thirdparty/win-libs-vc9-x64/"
else:
THIRDPARTYLIBS="thirdparty/win-libs-vc9/"
if not os.path.isdir(THIRDPARTYLIBS):
THIRDPARTYLIBS="thirdparty/win-libs-vc9/"
VC90CRTVERSION = GetVC90CRTVersion(THIRDPARTYLIBS+"extras/bin/Microsoft.VC90.CRT.manifest")
else:
if (sys.platform == "darwin"):
THIRDPARTYLIBS="thirdparty/darwin-libs-a/"
elif (sys.platform.startswith("linux")):
if (platform.architecture()[0] == "64bit"):
THIRDPARTYLIBS="thirdparty/linux-libs-x64/"
else:
THIRDPARTYLIBS="thirdparty/linux-libs-a/"
elif (sys.platform.startswith("freebsd")):
if (platform.architecture()[0] == "64bit"):
THIRDPARTYLIBS="thirdparty/freebsd-libs-x64/"
else:
THIRDPARTYLIBS="thirdparty/freebsd-libs-a/"
else:
exit("Unknown platform: %s" % sys.platform)
VC90CRTVERSION = 0
########################################################################
##
## The exit routine will normally
@ -324,7 +355,7 @@ def NeedsBuild(files,others):
else:
oldothers = BUILTFROMCACHE[key][0]
if (oldothers != others and VERBOSE):
print "%sCAUTION:%s file dependencies changed: %s%s%s" % (GetColor("red"), GetColor(), GetColor("green"), str(files), GetColor())
print "%sWARNING:%s file dependencies changed: %s%s%s" % (GetColor("red"), GetColor(), GetColor("green"), str(files), GetColor())
return 1
########################################################################
@ -728,15 +759,15 @@ def SetVerbose(verbose):
##
########################################################################
PKG_LIST_ALL=0
PKG_LIST_OMIT=0
PKG_LIST_ALL=[]
PKG_LIST_OMIT={}
def PkgListSet(pkgs):
global PKG_LIST_ALL
global PKG_LIST_OMIT
PKG_LIST_ALL=pkgs
PKG_LIST_OMIT={}
PkgDisableAll()
PkgEnableAll()
def PkgListGet():
return PKG_LIST_ALL
@ -762,10 +793,7 @@ def PkgSelected(pkglist, pkg):
if (pkglist.count(pkg)==0): return 0
if (PKG_LIST_OMIT[pkg]): return 0
return 1
if os.path.isfile("dtool/src/prc/prc_parameters.h.moved"):
os.rename("dtool/src/prc/prc_parameters.h.moved", "dtool/src/prc/prc_parameters.h")
if os.path.isfile("direct/src/plugin/p3d_plugin_config.h.moved"):
os.rename("direct/src/plugin/p3d_plugin_config.h.moved", "direct/src/plugin/p3d_plugin_config.h")
########################################################################
##
## These functions are for libraries which use pkg-config.
@ -867,6 +895,141 @@ def PkgConfigEnable(opt, pkgname, tool = "pkg-config"):
for i, j in PkgConfigGetDefSymbols(pkgname, tool).items():
DefSymbol(opt, i, j)
LD_CACHE = None
STATIC_CACHE = None
def GetLdCache():
# Returns a list of cached libraries, not prefixed by lib and not suffixed by .so* or .a!
global LD_CACHE
if (LD_CACHE == None):
if (LocateBinary("ldconfig") != None):
LD_CACHE = []
handle = os.popen(LocateBinary("ldconfig") + " -NXp")
result = handle.read().strip().split("\n")
for line in result:
lib = line.strip().split(" ", 1)[0]
lib = lib.split(".so", 1)[0][3:]
LD_CACHE.append(lib)
else:
for l in glob.glob("/lib/*.so*") + glob.glob("/usr/lib/*.so*") + glob.glob("/usr/local/lib/*.so*") + glob.glob("/usr/PCBSD/local/lib/*.so*"):
lib = os.path.basename(l).split(".so", 1)[0][3:]
LD_CACHE.append(lib)
# Now check for static libraries - they aren't found by ldconfig.
for l in glob.glob("/lib/*.a") + glob.glob("/usr/lib/*.a") + glob.glob("/usr/local/lib/*.a") + glob.glob("/usr/PCBSD/local/lib/*.a"):
lib = os.path.basename(l).split(".a", 1)[0][3:]
LD_CACHE.append(lib)
return LD_CACHE
def PkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None, framework = None, tool = "pkg-config"):
global PKG_LIST_ALL
if (LocateBinary("pkg-config")==None):
exit("Failed to locate pkg-config binary!")
if (pkgconfig == ""):
pkgconfig = None
if (framework == ""):
framework = None
if (libs == None or libs == ""):
libs = ()
elif (isinstance(libs, str)):
libs = (libs, )
if (incs == None or incs == ""):
incs = ()
elif (isinstance(incs, str)):
incs = (incs, )
if (defs == None or defs == "" or len(defs) == 0):
defs = {}
elif (isinstance(incs, str)):
defs = {defs : ""}
elif (isinstance(incs, list) or isinstance(incs, tuple) or isinstance(incs, set)):
olddefs = defs
defs = {}
for d in olddefs:
defs[d] = ""
if (os.path.isdir(THIRDPARTYLIBS + pkg.lower())):
IncDirectory(pkg, THIRDPARTYLIBS + pkg.lower() + "/include")
LibDirectory(pkg, THIRDPARTYLIBS + pkg.lower() + "/lib")
for l in libs:
libname = l
if (l.startswith("lib")):
libname = l[3:]
# This is for backward compatibility - in the thirdparty dir, we kept some libs with "panda" prefix, like libpandatiff.
if (len(glob.glob(THIRDPARTYLIBS + pkg.lower() + "/lib/libpanda%.*" % libname)) > 0 and
len(glob.glob(THIRDPARTYLIBS + pkg.lower() + "/lib/lib%.*" % libname)) == 0):
libname = "panda" + libname
LibName(pkg, libname)
for d, v in defs.values():
DefSymbol(pkg, d, v)
elif (sys.platform == "darwin" and framework != None):
if (os.path.isdir("/Library/Frameworks/%s.framework" % framework) or
os.path.isdir("/System/Library/Frameworks/%s.framework" % framework) or
os.path.isdir("/Developer/Library/Frameworks/%s.framework" % framework) or
os.path.isdir("/Users/%s/System/Library/Frameworks/%s.framework" % (getpass.getuser(), framework))):
LibName(pkg, "-framework " + framework)
for d, v in defs.values():
DefSymbol(pkg, d, v)
elif (pkg in PkgListGet()):
print "%sWARNING:%s Could not locate framework %s, excluding from build" % (GetColor("red"), GetColor(), framework)
PkgDisable(pkg)
else:
print "%ERROR:%s Could not locate framework %s, aborting build" % (GetColor("red"), GetColor(), framework)
exit()
elif (pkgconfig != None):
if (isinstance(pkgconfig, str)):
if (PkgConfigHavePkg(pkgconfig, tool)):
return PkgConfigEnable(pkg, pkgconfig, tool)
else:
have_all_pkgs = True
for pc in pkgconfig:
if (PkgConfigHavePkg(pc, tool)):
PkgConfigEnable(pkg, pc, tool)
else:
have_all_pkgs = False
if (have_all_pkgs):
return
elif (pkgconfig != None and libs == None):
if (pkg in PkgListGet()):
print "%sWARNING:%s Could not locate package %s, excluding from build" % (GetColor("red"), GetColor(), pkgconfig)
PkgDisable(pkg)
else:
print "%ERROR:%s Could not locate package %s, aborting build" % (GetColor("red"), GetColor(), pkgconfig)
exit()
else:
# Okay, our pkg-config attempts failed. Let's try locating the libs by ourselves.
have_pkg = True
for l in libs:
if (l in GetLdCache()):
LibName(pkg, "-l" + l)
else:
if (VERBOSE):
print GetColor("cyan") + "Couldn't find library lib" + l + GetColor()
have_pkg = False
for i in incs:
incdir = None
if (len(glob.glob("/usr/include/" + i)) > 0):
incdir = sorted(glob.glob("/usr/include/" + i))[-1]
elif (len(glob.glob("/usr/local/include/" + i)) > 0):
incdir = sorted(glob.glob("/usr/local/include/" + i))[-1]
elif (platform.uname()[1]=="pcbsd" and len(glob.glob("/usr/PCBSD/local/include/" + i)) > 0):
incdir = sorted(glob.glob("/usr/PCBSD/local/include/" + i))[-1]
else:
if (VERBOSE and i.endswith(".h")):
print GetColor("cyan") + "Couldn't find header file " + i + GetColor()
have_pkg = False
# Note: It's possible to specify a file instead of a dir, for the sake of checking if it exists.
if (incdir != None and os.path.isdir(incdir)):
IncDirectory(pkg, incdir)
if (not have_pkg):
if (pkg in PkgListGet()):
print "%sWARNING:%s Could not locate thirdparty package %s, excluding from build" % (GetColor("red"), GetColor(), pkg.lower())
PkgDisable(pkg)
else:
print "%ERROR:%s Could not locate thirdparty package %s, aborting build" % (GetColor("red"), GetColor(), pkg.lower())
exit()
########################################################################
##
## SDK Location