Selaa lähdekoodia

makepanda: various fixes for emscripten compilation

rdb 6 vuotta sitten
vanhempi
sitoutus
9e96633405
2 muutettua tiedostoa jossa 57 lisäystä ja 51 poistoa
  1. 47 49
      makepanda/makepanda.py
  2. 10 2
      makepanda/makepandacore.py

+ 47 - 49
makepanda/makepanda.py

@@ -886,7 +886,6 @@ if (COMPILER=="GCC"):
         SmartPkgEnable("SWRESAMPLE","libswresample", "libswresample", ("libswresample/swresample.h"), target_pkg = "FFMPEG", thirdparty_dir = "ffmpeg")
         SmartPkgEnable("SWRESAMPLE","libswresample", "libswresample", ("libswresample/swresample.h"), target_pkg = "FFMPEG", thirdparty_dir = "ffmpeg")
         SmartPkgEnable("FFTW",      "",          ("fftw3"), ("fftw.h"))
         SmartPkgEnable("FFTW",      "",          ("fftw3"), ("fftw.h"))
         SmartPkgEnable("FMODEX",    "",          ("fmodex"), ("fmodex", "fmodex/fmod.h"))
         SmartPkgEnable("FMODEX",    "",          ("fmodex"), ("fmodex", "fmodex/fmod.h"))
-        SmartPkgEnable("GL",        "gl",        ("GL"), ("GL/gl.h"), framework = "OpenGL")
         SmartPkgEnable("NVIDIACG",  "",          ("Cg"), "Cg/cg.h", framework = "Cg")
         SmartPkgEnable("NVIDIACG",  "",          ("Cg"), "Cg/cg.h", framework = "Cg")
         SmartPkgEnable("ODE",       "",          ("ode"), "ode/ode.h", tool = "ode-config")
         SmartPkgEnable("ODE",       "",          ("ode"), "ode/ode.h", tool = "ode-config")
         SmartPkgEnable("SQUISH",    "",          ("squish"), "squish.h")
         SmartPkgEnable("SQUISH",    "",          ("squish"), "squish.h")
@@ -905,13 +904,27 @@ if (COMPILER=="GCC"):
             SmartPkgEnable("FREETYPE", "freetype2", ("freetype"), ("freetype2", "freetype2/freetype/freetype.h"))
             SmartPkgEnable("FREETYPE", "freetype2", ("freetype"), ("freetype2", "freetype2/freetype/freetype.h"))
             SmartPkgEnable("HARFBUZZ", "harfbuzz",  ("harfbuzz"), ("harfbuzz", "harfbuzz/hb-ft.h"))
             SmartPkgEnable("HARFBUZZ", "harfbuzz",  ("harfbuzz"), ("harfbuzz", "harfbuzz/hb-ft.h"))
             SmartPkgEnable("PNG",      "libpng",    ("png"), "png.h", tool = "libpng-config")
             SmartPkgEnable("PNG",      "libpng",    ("png"), "png.h", tool = "libpng-config")
+            SmartPkgEnable("GL",       "gl",        ("GL"), ("GL/gl.h"), framework = "OpenGL")
             SmartPkgEnable("GLES",     "glesv1_cm", ("GLESv1_CM"), ("GLES/gl.h"), framework = "OpenGLES")
             SmartPkgEnable("GLES",     "glesv1_cm", ("GLESv1_CM"), ("GLES/gl.h"), framework = "OpenGLES")
             SmartPkgEnable("GLES2",    "glesv2",    ("GLESv2"), ("GLES2/gl2.h")) #framework = "OpenGLES"?
             SmartPkgEnable("GLES2",    "glesv2",    ("GLESv2"), ("GLES2/gl2.h")) #framework = "OpenGLES"?
             SmartPkgEnable("EGL",      "egl",       ("EGL"), ("EGL/egl.h"))
             SmartPkgEnable("EGL",      "egl",       ("EGL"), ("EGL/egl.h"))
         else:
         else:
             PkgDisable("EIGEN")
             PkgDisable("EIGEN")
             PkgDisable("X11")
             PkgDisable("X11")
+            PkgDisable("GL")
             PkgDisable("GLES")
             PkgDisable("GLES")
+            PkgDisable("TINYDISPLAY")
+            for pkg, empkg in {
+                'VORBIS': 'VORBIS',
+                'BULLET': 'BULLET',
+                'ZLIB': 'ZLIB',
+                'FREETYPE': 'FREETYPE',
+                'HARFBUZZ': 'HARFBUZZ',
+                'PNG': 'LIBPNG',
+            }.items():
+                if not PkgSkip(pkg):
+                    LinkFlag(pkg, '-s USE_' + empkg + '=1')
+                    CompileFlag(pkg, '-s USE_' + empkg + '=1')
 
 
         if not PkgSkip("FFMPEG"):
         if not PkgSkip("FFMPEG"):
             if GetTarget() == "darwin":
             if GetTarget() == "darwin":
@@ -1335,6 +1348,8 @@ def CompileCxx(obj,src,opts):
             if (opt=="ALWAYS") or (opt in opts): cmd += ' -F' + BracketNameWithQuotes(dir)
             if (opt=="ALWAYS") or (opt in opts): cmd += ' -F' + BracketNameWithQuotes(dir)
         for (opt,var,val) in DEFSYMBOLS:
         for (opt,var,val) in DEFSYMBOLS:
             if (opt=="ALWAYS") or (opt in opts): cmd += ' -D' + var + '=' + val
             if (opt=="ALWAYS") or (opt in opts): cmd += ' -D' + var + '=' + val
+        for (opt,flag) in COMPILEFLAGS:
+            if (opt=="ALWAYS") or (opt in opts): cmd += ' ' + flag
         for x in ipath: cmd += ' -I' + x
         for x in ipath: cmd += ' -I' + x
 
 
         if not GetLinkAllStatic() and 'NOHIDDEN' not in opts:
         if not GetLinkAllStatic() and 'NOHIDDEN' not in opts:
@@ -1413,18 +1428,10 @@ def CompileCxx(obj,src,opts):
         elif GetTarget() == 'emscripten':
         elif GetTarget() == 'emscripten':
             cmd += " -s WARN_ON_UNDEFINED_SYMBOLS=1 -s NO_FILESYSTEM=1"
             cmd += " -s WARN_ON_UNDEFINED_SYMBOLS=1 -s NO_FILESYSTEM=1"
 
 
-            if 'VORBIS' in opts and not PkgSkip("VORBIS"):
-                cmd += " -s USE_VORBIS=1"
-            if 'BULLET' in opts and not PkgSkip("BULLET"):
-                cmd += " -s USE_BULLET=1"
-            if 'ZLIB' in opts and not PkgSkip("ZLIB"):
-                cmd += " -s USE_ZLIB=1"
-            if 'FREETYPE' in opts and not PkgSkip("FREETYPE"):
-                cmd += " -s USE_FREETYPE=1"
-            if 'HARFBUZZ' in opts and not PkgSkip("HARFBUZZ"):
-                cmd += " -s USE_HARFBUZZ=1"
-            if 'PNG' in opts and not PkgSkip("PNG"):
-                cmd += " -s USE_LIBPNG=1"
+            if GetOptimize() <= 1:
+                cmd += " -s ASSERTIONS=2"
+            elif GetOptimize() <= 2:
+                cmd += " -s ASSERTIONS=1"
 
 
         else:
         else:
             cmd += " -pthread"
             cmd += " -pthread"
@@ -1928,19 +1935,6 @@ def CompileLink(dll, obj, opts):
             if GetOrigExt(dll) == ".exe":
             if GetOrigExt(dll) == ".exe":
                 cmd += " --memory-init-file 0"
                 cmd += " --memory-init-file 0"
 
 
-            if 'VORBIS' in opts and not PkgSkip("VORBIS"):
-                cmd += " -s USE_VORBIS=1"
-            if 'BULLET' in opts and not PkgSkip("BULLET"):
-                cmd += " -s USE_BULLET=1"
-            if 'ZLIB' in opts and not PkgSkip("ZLIB"):
-                cmd += " -s USE_ZLIB=1"
-            if 'FREETYPE' in opts and not PkgSkip("FREETYPE"):
-                cmd += " -s USE_FREETYPE=1"
-            if 'HARFBUZZ' in opts and not PkgSkip("HARFBUZZ"):
-                cmd += " -s USE_HARFBUZZ=1"
-            if 'PNG' in opts and not PkgSkip("PNG"):
-                cmd += " -s USE_LIBPNG=1"
-
         else:
         else:
             cmd += " -pthread"
             cmd += " -pthread"
 
 
@@ -1965,6 +1959,9 @@ def CompileLink(dll, obj, opts):
             for (opt, name) in LIBNAMES:
             for (opt, name) in LIBNAMES:
                 if (opt=="ALWAYS") or (opt in opts):
                 if (opt=="ALWAYS") or (opt in opts):
                     cmd += ' ' + BracketNameWithQuotes(name)
                     cmd += ' ' + BracketNameWithQuotes(name)
+        for (opt, flag) in LINKFLAGS:
+            if (opt=="ALWAYS") or (opt in opts):
+                cmd += ' ' + flag
 
 
         if GetTarget() not in ('freebsd', 'emscripten'):
         if GetTarget() not in ('freebsd', 'emscripten'):
             cmd += " -ldl"
             cmd += " -ldl"
@@ -5223,27 +5220,6 @@ if (PkgSkip("SPEEDTREE")==0):
   elif SDK["SPEEDTREEAPI"] == 'DirectX9':
   elif SDK["SPEEDTREEAPI"] == 'DirectX9':
       TargetAdd('libpandaspeedtree.dll', opts=['DX9',  'NVIDIACG', 'CGDX9'])
       TargetAdd('libpandaspeedtree.dll', opts=['DX9',  'NVIDIACG', 'CGDX9'])
 
 
-#
-# DIRECTORY: panda/src/testbed/
-#
-
-if (not RTDIST and not RUNTIME and PkgSkip("PVIEW")==0):
-  OPTS=['DIR:panda/src/testbed']
-  TargetAdd('pview_pview.obj', opts=OPTS, input='pview.cxx')
-  TargetAdd('pview.exe', input='pview_pview.obj')
-  TargetAdd('pview.exe', input='libp3framework.dll')
-  if not PkgSkip("EGG"):
-    TargetAdd('pview.exe', input='libpandaegg.dll')
-  TargetAdd('pview.exe', input=COMMON_PANDA_LIBS)
-  TargetAdd('pview.exe', opts=['ADVAPI', 'WINSOCK2', 'WINSHELL'])
-
-  if GetTarget() == 'emscripten':
-    # Link in a graphical back-end.
-    TargetAdd('pview.exe', input='libp3webgldisplay.dll')
-    TargetAdd('pview.exe', opts=['OPENSSL', 'HARFBUZZ', 'PNG', 'VORBIS', 'ZLIB'])
-  elif GetLinkAllStatic() and not PkgSkip("GL"):
-    TargetAdd('pview.exe', input='libpandagl.dll')
-
 #
 #
 # DIRECTORY: panda/src/android/
 # DIRECTORY: panda/src/android/
 #
 #
@@ -5332,6 +5308,27 @@ if (not RUNTIME and (GetTarget() in ('windows', 'darwin') or PkgSkip("X11")==0)
   TargetAdd('libp3tinydisplay.dll', input='p3tinydisplay_ztriangle_table.obj')
   TargetAdd('libp3tinydisplay.dll', input='p3tinydisplay_ztriangle_table.obj')
   TargetAdd('libp3tinydisplay.dll', input=COMMON_PANDA_LIBS)
   TargetAdd('libp3tinydisplay.dll', input=COMMON_PANDA_LIBS)
 
 
+#
+# DIRECTORY: panda/src/testbed/
+#
+
+if (not RTDIST and not RUNTIME and PkgSkip("PVIEW")==0):
+  OPTS=['DIR:panda/src/testbed']
+  TargetAdd('pview_pview.obj', opts=OPTS, input='pview.cxx')
+  TargetAdd('pview.exe', input='pview_pview.obj')
+  TargetAdd('pview.exe', input='libp3framework.dll')
+  if not PkgSkip("EGG"):
+    TargetAdd('pview.exe', input='libpandaegg.dll')
+  TargetAdd('pview.exe', input=COMMON_PANDA_LIBS)
+  TargetAdd('pview.exe', opts=['ADVAPI', 'WINSOCK2', 'WINSHELL'])
+
+  #  TargetAdd('pview.exe', input='libp3webgldisplay.dll')
+  if GetLinkAllStatic():
+    if not PkgSkip("GL"):
+      TargetAdd('pview.exe', input='libpandagl.dll')
+    if GetTarget() == "emscripten" and not PkgSkip("GLES2"):
+      TargetAdd('pview.exe', input='libp3webgldisplay.dll')
+
 #
 #
 # DIRECTORY: direct/src/directbase/
 # DIRECTORY: direct/src/directbase/
 #
 #
@@ -5445,7 +5442,8 @@ if (PkgSkip("DIRECT")==0):
   if GetTarget() == 'darwin':
   if GetTarget() == 'darwin':
     TargetAdd('libp3direct.dll', input='p3showbase_showBase_assist.obj')
     TargetAdd('libp3direct.dll', input='p3showbase_showBase_assist.obj')
   TargetAdd('libp3direct.dll', input='p3deadrec_composite1.obj')
   TargetAdd('libp3direct.dll', input='p3deadrec_composite1.obj')
-  TargetAdd('libp3direct.dll', input='p3distributed_config_distributed.obj')
+  if GetTarget() != 'emscripten':
+    TargetAdd('libp3direct.dll', input='p3distributed_config_distributed.obj')
   TargetAdd('libp3direct.dll', input='p3interval_composite1.obj')
   TargetAdd('libp3direct.dll', input='p3interval_composite1.obj')
   TargetAdd('libp3direct.dll', input='p3motiontrail_config_motiontrail.obj')
   TargetAdd('libp3direct.dll', input='p3motiontrail_config_motiontrail.obj')
   TargetAdd('libp3direct.dll', input='p3motiontrail_cMotionTrail.obj')
   TargetAdd('libp3direct.dll', input='p3motiontrail_cMotionTrail.obj')
@@ -6434,7 +6432,7 @@ if (PkgSkip("PANDATOOL")==0):
 # DIRECTORY: pandatool/src/text-stats/
 # DIRECTORY: pandatool/src/text-stats/
 #
 #
 
 
-if (PkgSkip("PANDATOOL")==0):
+if not PkgSkip("PANDATOOL") and GetTarget() != 'emscripten':
     OPTS=['DIR:pandatool/src/text-stats']
     OPTS=['DIR:pandatool/src/text-stats']
     TargetAdd('text-stats_textMonitor.obj', opts=OPTS, input='textMonitor.cxx')
     TargetAdd('text-stats_textMonitor.obj', opts=OPTS, input='textMonitor.cxx')
     TargetAdd('text-stats_textStats.obj', opts=OPTS, input='textStats.cxx')
     TargetAdd('text-stats_textStats.obj', opts=OPTS, input='textStats.cxx')

+ 10 - 2
makepanda/makepandacore.py

@@ -2844,6 +2844,8 @@ LIBDIRECTORIES = []
 FRAMEWORKDIRECTORIES = []
 FRAMEWORKDIRECTORIES = []
 LIBNAMES = []
 LIBNAMES = []
 DEFSYMBOLS = []
 DEFSYMBOLS = []
+COMPILEFLAGS = []
+LINKFLAGS = []
 
 
 def IncDirectory(opt, dir):
 def IncDirectory(opt, dir):
     INCDIRECTORIES.append((opt, dir))
     INCDIRECTORIES.append((opt, dir))
@@ -2873,6 +2875,12 @@ def LibName(opt, name):
 def DefSymbol(opt, sym, val=""):
 def DefSymbol(opt, sym, val=""):
     DEFSYMBOLS.append((opt, sym, val))
     DEFSYMBOLS.append((opt, sym, val))
 
 
+def CompileFlag(opt, flag):
+    COMPILEFLAGS.append((opt, flag))
+
+def LinkFlag(opt, flag):
+    LINKFLAGS.append((opt, flag))
+
 ########################################################################
 ########################################################################
 #
 #
 # This subroutine prepares the environment for the build.
 # This subroutine prepares the environment for the build.
@@ -3706,10 +3714,10 @@ def TargetAdd(target, dummy=0, opts=[], input=[], dep=[], ipath=None, winrc=None
         if GetLinkAllStatic() and ORIG_EXT[fullinput] == '.lib' and fullinput in TARGET_TABLE:
         if GetLinkAllStatic() and ORIG_EXT[fullinput] == '.lib' and fullinput in TARGET_TABLE:
             tdep = TARGET_TABLE[fullinput]
             tdep = TARGET_TABLE[fullinput]
             for y in tdep.inputs:
             for y in tdep.inputs:
-                if ORIG_EXT[y] == '.lib':
+                if ORIG_EXT[y] == '.lib' and y not in t.inputs:
                     t.inputs.append(y)
                     t.inputs.append(y)
 
 
-            for opt, _ in LIBNAMES + LIBDIRECTORIES + FRAMEWORKDIRECTORIES:
+            for opt, _ in LIBNAMES + LIBDIRECTORIES + FRAMEWORKDIRECTORIES + LINKFLAGS + COMPILEFLAGS:
                 if opt in tdep.opts and opt not in t.opts:
                 if opt in tdep.opts and opt not in t.opts:
                     t.opts.append(opt)
                     t.opts.append(opt)