瀏覽代碼

Mac OSX Resource files with makepnada

rdb 16 年之前
父節點
當前提交
6e4b19c6ca
共有 4 個文件被更改,包括 55 次插入43 次删除
  1. 3 30
      direct/src/plugin_npapi/make_osx_bundle.py
  2. 19 0
      direct/src/plugin_npapi/nppanda3d.r
  3. 29 11
      makepanda/makepanda.py
  4. 4 2
      makepanda/makepandacore.py

+ 3 - 30
direct/src/plugin_npapi/make_osx_bundle.py

@@ -45,29 +45,7 @@ InfoPlist = """<?xml version="1.0" encoding="UTF-8"?>
 	</dict>
 </dict>
 </plist>
-"""
-
-# The contents of the source nppanda3d.r file.  Apparently Firefox
-# ignores the Info.plist file, above, and looks only in the .rsrc file
-# within the bundle, which is compiled from the following source file.
-ResourceFile = """
-#include <Carbon/Carbon.r>
-
-resource 'STR#' (126) {
-	{ "Runs 3-D games and interactive applets", 
-          "Panda3D Game Engine Plug-In" }
-};
-
-resource 'STR#' (127) {
-	{ "Panda3D applet" }
-};
-
-resource 'STR#' (128) {
-	{ "application/x-panda3d", "p3d" }
-};
-
-"""
-        
+"""        
 
 import getopt
 import sys
@@ -104,15 +82,10 @@ def makeBundle(startDir):
     exeFilename.makeDir()
     resourceFilename = Filename(bundleFilename, 'Contents/Resources/nppanda3d.rsrc')
     resourceFilename.makeDir()
-
-    # Generate the resource file.
-    tfile = Filename.temporary('', 'rsrc')
-    f = open(tfile.toOsSpecific(), 'w')
-    f.write(ResourceFile)
-    f.close()
     
+    # Compile the .r file to an .rsrc file.
     os.system('/Developer/Tools/Rez -useDF -o %s %s' % (
-        resourceFilename.toOsSpecific(), tfile.toOsSpecific()))
+        resourceFilename.toOsSpecific(), Filename(fStartDir, "nppanda3d.r").toOsSpecific()))
     tfile.unlink()
 
     if not resourceFilename.exists():

+ 19 - 0
direct/src/plugin_npapi/nppanda3d.r

@@ -0,0 +1,19 @@
+/* Apparently Firefox ignores the Info.plist file,
+   and looks only in the .rsrc file within the bundle,
+   which is compiled from the following source file. */
+
+#include <Carbon/Carbon.r>
+
+resource 'STR#' (126) {
+	{ "Runs 3-D games and interactive applets", 
+          "Panda3D Game Engine Plug-In" }
+};
+
+resource 'STR#' (127) {
+	{ "Panda3D applet" }
+};
+
+resource 'STR#' (128) {
+	{ "application/x-panda3d", "p3d" }
+};
+

+ 29 - 11
makepanda/makepanda.py

@@ -838,15 +838,15 @@ def CompileEggPZ(eggpz, src, opts):
 
 ##########################################################################################
 #
-# CompileRC
+# CompileResource
 #
 ##########################################################################################
 
-def CompileRC(target, src, opts):
+def CompileResource(target, src, opts):
     ipath = GetListOption(opts, "DIR:")
     if (COMPILER=="MSVC"):
-        cmd = "rc "
-        cmd += "/Fo" + BracketNameWithQuotes(target)
+        cmd = "rc"
+        cmd += " /Fo" + BracketNameWithQuotes(target)
         for x in ipath: cmd = cmd + " /I" + x
         for (opt,dir) in INCDIRECTORIES:
             if (opt=="ALWAYS") or (opts.count(opt)): cmd = cmd + " /I" + BracketNameWithQuotes(dir)
@@ -856,6 +856,22 @@ def CompileRC(target, src, opts):
 
         oscmd(cmd)
 
+    elif (sys.platform == "darwin"):
+        cmd = "/Developer/Tools/Rez -useDF"
+        cmd += " -o " + BracketNameWithQuotes(target)
+        for x in ipath: cmd = cmd + " -i " + x
+        for (opt,dir) in INCDIRECTORIES:
+            if (opt=="ALWAYS") or (opts.count(opt)): cmd = cmd + " -i " + BracketNameWithQuotes(dir)
+        for (opt,var,val) in DEFSYMBOLS:
+            if (opt=="ALWAYS") or (opts.count(opt)):
+                if (val == ""):
+                    cmd = cmd + " -d " + var
+                else:
+                    cmd = cmd + " -d " + var + " = " + val
+        
+        cmd += " " + BracketNameWithQuotes(src)
+        oscmd(cmd)
+
 ##########################################################################################
 #
 # RunGenPyCode
@@ -919,8 +935,8 @@ def CompileAnything(target, inputs, opts):
         return CompileIgate(target, inputs, opts)
     elif (origsuffix==".pz"):
         return CompileEggPZ(target, infile, opts)
-    elif (origsuffix==".res"):
-        return CompileRC(target, infile, opts)
+    elif (origsuffix in [".res", ".rsrc"]):
+        return CompileResource(target, infile, opts)
     elif (origsuffix==".obj"):
         if (infile.endswith(".cxx") or infile.endswith(".c") or infile.endswith(".mm")):
             return CompileCxx(target, infile, opts)
@@ -930,8 +946,8 @@ def CompileAnything(target, inputs, opts):
             return CompileFlex(target, infile, opts)
         elif (infile.endswith(".in")):
             return CompileImod(target, inputs, opts)
-        elif (infile.endswith(".rc")):
-            return CompileRC(target, infile, opts)
+        elif (infile.endswith(".rc") or infile.endswith(".r")):
+            return CompileResource(target, infile, opts)
     exit("Don't know how to compile: "+target)
 
 ##########################################################################################
@@ -2956,15 +2972,17 @@ if (PkgSkip("PLUGIN")==0 and PkgSkip("TINYXML")==0):
 #
 
 if (PkgSkip("PLUGIN")==0 and PkgSkip("TINYXML")==0 and PkgSkip("NPAPI")==0):
-  if sys.platform.startswith("win"):
-    OPTS=['DIR:direct/src/plugin_npapi']
+  OPTS=['DIR:direct/src/plugin_npapi']
+  if (sys.platform.startswith("win")):
     TargetAdd('nppanda3d.res', opts=OPTS, input='nppanda3d.rc')
+  elif (sys.platform=="darwin"):
+    TargetAdd('nppanda3d.rsrc', opts=OPTS, input='nppanda3d.r')
   
   OPTS=['DIR:direct/src/plugin_npapi', 'NPAPI', 'TINYXML']
   TargetAdd('plugin_npapi_nppanda3d_composite1.obj', opts=OPTS, input='nppanda3d_composite1.cxx')
   TargetAdd('nppanda3d.dll', input='plugin_common.obj')
   TargetAdd('nppanda3d.dll', input='plugin_npapi_nppanda3d_composite1.obj')
-  if sys.platform.startswith("win"):
+  if (sys.platform.startswith("win")):
     TargetAdd('nppanda3d.dll', input='nppanda3d.res')
     TargetAdd('nppanda3d.dll', input='nppanda3d.def', ipath=OPTS)
   TargetAdd('nppanda3d.dll', opts=['NPAPI', 'TINYXML', 'OPENSSL', 'WINUSER', 'WINSHELL'])

+ 4 - 2
makepanda/makepandacore.py

@@ -12,7 +12,7 @@
 import sys,os,time,stat,string,re,getopt,cPickle,fnmatch,threading,Queue,signal,shutil,platform
 from distutils import sysconfig
 
-SUFFIX_INC=[".cxx",".c",".h",".I",".yxx",".lxx",".mm"]
+SUFFIX_INC=[".cxx",".c",".h",".I",".yxx",".lxx",".mm",".rc",".r"]
 SUFFIX_DLL=[".dll",".dlo",".dle",".dli",".dlm",".mll",".exe",".pyd"]
 SUFFIX_LIB=[".lib",".ilb"]
 STARTTIME=time.time()
@@ -563,7 +563,7 @@ def DeleteBuildFiles(dir):
     for entry in os.listdir(dir):
         if (entry != ".") and (entry != ".."):
             subdir = dir + "/" + entry
-            if (os.path.isfile(subdir) and os.path.splitext(subdir)[-1] in [".h", ".I", ".c", ".cxx", ".cpp", ".pp", ".moved"]):
+            if (os.path.isfile(subdir) and os.path.splitext(subdir)[-1] in SUFFIX_INC+[".pp", ".moved"]):
                 os.remove(subdir)
             elif (os.path.isdir(subdir)):
                 DeleteBuildFiles(subdir)
@@ -1207,6 +1207,7 @@ def CalcLocation(fn, ipath):
         if (fn.endswith(".in")):  return OUTPUTDIR+"/pandac/input/"+fn
     elif (sys.platform == "darwin"):
         if (fn.endswith(".mm")):  return CxxFindSource(fn, ipath)
+        if (fn.endswith(".r")):   return CxxFindSource(fn, ipath)
         if (fn.endswith(".obj")): return OUTPUTDIR+"/tmp/"+fn[:-4]+".o"
         if (fn.endswith(".dll")): return OUTPUTDIR+"/lib/"+fn[:-4]+".dylib"
         if (fn.endswith(".pyd")): return OUTPUTDIR+"/lib/"+fn[:-4]+".dylib"
@@ -1214,6 +1215,7 @@ def CalcLocation(fn, ipath):
         if (fn.endswith(".lib")): return OUTPUTDIR+"/lib/"+fn[:-4]+".a"
         if (fn.endswith(".ilb")): return OUTPUTDIR+"/tmp/"+fn[:-4]+".a"
         if (fn.endswith(".dat")): return OUTPUTDIR+"/tmp/"+fn
+        if (fn.endswith(".rsrc")):return OUTPUTDIR+"/tmp/"+fn
         if (fn.endswith(".in")):  return OUTPUTDIR+"/pandac/input/"+fn
     else:
         if (fn.endswith(".obj")): return OUTPUTDIR+"/tmp/"+fn[:-4]+".o"