Source

pygame / symbian / SConscript.pygame.py

Diff from to

File symbian/SConscript.pygame.py

 Import("*")
 
+from glob import glob
 from scons_symbian import *
-import glob
+import os
 
 python_includes = [ PYTHON_INCLUDE ]
-
-#music.c
-#mixer.c
-#font.c
-#imageext.c
+ 
 IGNORED = r"""
 pypm.c
 camera.c
 joystick.c
 cdrom.c""".split()
 
-pygame_sources = glob.glob( "../src/*.c" )
-pygame_sources += glob.glob( "../src/SDL_gfx/*.c" )
+pygame_sources = glob( "../src/*.c" )
+pygame_sources += glob( "../src/SDL_gfx/*.c" )
 removed = []
 for x in pygame_sources:
     for y in IGNORED:        
 
 for x in removed:    
     pygame_sources.remove(x)
-
-pygame_sources.append("common/builtins.c")
-
+    
 if USE_OPENC:
     C_LIB_INCLUDE = "OPENC"
 else:
     C_LIB_INCLUDE = ""
-    
-# Build pygame library
-SymbianProgram( "pygame", TARGETTYPE_LIB,
-                sources = pygame_sources,
+
+#: List of static modules for linking
+PYGAME_STATIC_MODULES = []
+
+def createPygameLibrary( modname, sources, ):
+    modname = "pygame_" + modname
+    uid     = 0
+    targettype = TARGETTYPE_LIB
+    if not HAVE_STATIC_MODULES:
+        targettype = TARGETTYPE_PYD
+        # Add the PyS60 prefix
+        modname    = "kf_" + modname
+        uid        = getUID()
+    # Build pygame library
+    SymbianProgram( modname, targettype,
+                sources = ["../src/" + x for x in sources],
                 defines = [ 
                    C_LIB_INCLUDE                   
                 ],
                              join( "deps", "SDL", "include"),                              
                              join( "deps", "SDL", "symbian", "inc"),
                              C_INCLUDE,                             
-                             #join( "..", "..", "tools", "debug" )
                            ],
                 package = PACKAGE_NAME,
                 libraries = C_LIBRARY + [
                      PYTHON_LIB_NAME,                     
                      "euser", "avkon", "apparc", 
-                     "cone","eikcore", "libGLES_CM",                     
+                     "cone","eikcore", "libGLES_CM", "pygame_libjpeg",                    
                      SDL_DLL_NAME,
                      ],
                 winscw_options = "-w noempty",
+                uid3 = uid,
                 )
+    m = ".".join( [modname, targettype] )
+    
+    if HAVE_STATIC_MODULES:
+        PYGAME_STATIC_MODULES.append( m )
+     
+
+def createPygameMods():
+    """ Create pygame native modules """
+    
+    # Get the mods. Python wrappers can be conveniently used here.
+    mods = [ os.path.basename( x ).replace(".py", "") for x in glob("lib/*.py") ]
+    
+    # Most of the modules have only 1 source file : <modname>.c
+    # This dict can be used to map differing or multiple source files to module. 
+    module_src_map = { 
+        "surface" : (
+            "surface.c",
+            "scale2x.c",
+            "surface_fill.c",
+            "alphablit.c",            
+        ),
+        "gfxdraw" : ( 
+            "gfxdraw.c", 
+            "SDL_gfx/SDL_gfxPrimitives.c" 
+        ),   
+        "fastevent" : (
+            "fastevents.c",
+            "fastevent.c"
+        ),
+        "transform" : (
+            "transform.c",
+            "rotozoom.c",
+            "scale2x.c"
+        )
+    }
+
+    for x in mods:
+        # Get source mapping
+        src = module_src_map.get( x, [ x + ".c"])
+        createPygameLibrary( x, src )
+    
+    # This one is special    
+    createPygameLibrary( "mixer_music", ["music.c"])        
+    
+createPygameMods()
 
 # Install pygame python libraries
-from glob import glob
-
+pylibzip = "data/pygame/libs/pygame.zip"
 def to_package(**kwargs):
     kwargs["source"] = abspath( kwargs["source"] )
-    ToPackage( package = PACKAGE_NAME, **kwargs )
+    return ToPackage( package = PACKAGE_NAME, pylibzip = pylibzip, 
+               dopycompile = ".pyc", **kwargs )
 
 pygame_lib = join( PATH_PY_LIBS, "pygame" )
 
 # Copy main pygame libs
+IGNORED_FILES = ["camera.py"]
 for x in glob( "../lib/*.py"):
-    to_package( source = x, target = pygame_lib )
+    for i in IGNORED_FILES:
+        if x.endswith( i ): break 
+    else:
+        to_package( source = x, target = pygame_lib )
 
 for x in glob( "../lib/threads/*.py"):
     to_package( source = x, target = join( pygame_lib, "threads") )
 for x in glob( "lib/*.py"): 
     to_package( source = x, target = pygame_lib )
     
-# Install default font
-to_package( source = "../lib/freesansbold.ttf", target = pygame_lib )
+def packagePyS60Stdlib(**kwargs):
+    kwargs["source"] = join( "deps/PythonForS60/module-repo/standard-modules", kwargs["source"] )
+    return to_package( **kwargs )
+
+# Add files missing from standard PyS60 installation
+packagePyS60Stdlib( source = "glob.py", target = "data/pygame/libs" )
+zippath = packagePyS60Stdlib( source = "fnmatch.py", target = "data/pygame/libs" )
+
+# Install default font into zip as well
+File2Zip( zippath, "../lib/freesansbold.ttf", "pygame/freesansbold.ttf" )
+
+# Export static library names to be used for building pygame.exe
+Export( "PYGAME_STATIC_MODULES")