makepanda: change Android build model

We no longer copy libs to a separate libs dir to entertain Ant (which is no longer the build system of choice on Android).  Also, rather than copying the Java sources to built/src, we now compile them and put the classes in built/classes.

Furthermore, executables are really compiled as executables now (rather than as libraries) to allow building and running Panda in termux.
This commit is contained in:
rdb 2018-01-29 19:57:01 +01:00
parent 7c1dd4050b
commit e04cb17a30
2 changed files with 43 additions and 51 deletions

View File

@ -943,7 +943,7 @@ if (COMPILER=="GCC"):
if GetTarget() == 'android':
LibName("ALWAYS", '-llog')
LibName("ALWAYS", '-landroid')
LibName("ANDROID", '-landroid')
LibName("JNIGRAPHICS", '-ljnigraphics')
for pkg in MAYAVERSIONS:
@ -1704,8 +1704,11 @@ def CompileLink(dll, obj, opts):
if COMPILER == "GCC":
cxx = GetCXX()
if GetOrigExt(dll) == ".exe" and GetTarget() != 'android':
if GetOrigExt(dll) == ".exe":
cmd = cxx + ' -o ' + dll + ' -L' + GetOutputDir() + '/lib -L' + GetOutputDir() + '/tmp'
if GetTarget() == "android":
# Necessary to work around an issue with libandroid depending on vendor libraries
cmd += ' -Wl,--allow-shlib-undefined'
else:
if (GetTarget() == "darwin"):
cmd = cxx + ' -undefined dynamic_lookup'
@ -1718,6 +1721,7 @@ def CompileLink(dll, obj, opts):
cmd += ' -o ' + dll + ' -L' + GetOutputDir() + '/lib -L' + GetOutputDir() + '/tmp'
else:
cmd = cxx + ' -shared'
# Always set soname on Android to avoid a linker warning when loading the library.
if "MODULE" not in opts or GetTarget() == 'android':
cmd += " -Wl,-soname=" + os.path.basename(dll)
cmd += ' -o ' + dll + ' -L' + GetOutputDir() + '/lib -L' + GetOutputDir() + '/tmp'
@ -1774,14 +1778,7 @@ def CompileLink(dll, obj, opts):
oscmd(cmd)
if GetTarget() == 'android':
# Copy the library to built/libs/$ANDROID_ABI and strip it.
# This is the format that Android NDK projects should use.
new_path = '%s/libs/%s/%s' % (GetOutputDir(), SDK["ANDROID_ABI"], os.path.basename(dll))
CopyFile(new_path, dll)
oscmd('%s --strip-unneeded %s' % (GetStrip(), BracketNameWithQuotes(new_path)))
elif (GetOptimizeOption(opts)==4 and GetTarget() == 'linux'):
if GetOptimizeOption(opts) == 4 and GetTarget() in ('linux', 'android'):
oscmd(GetStrip() + " --strip-unneeded " + BracketNameWithQuotes(dll))
os.system("chmod +x " + BracketNameWithQuotes(dll))
@ -1890,6 +1887,25 @@ def CompileRsrc(target, src, opts):
cmd += " " + BracketNameWithQuotes(src)
oscmd(cmd)
##########################################################################################
#
# CompileJava (Android only)
#
##########################################################################################
def CompileJava(target, src, opts):
"""Compiles a .java file into a .class file."""
cmd = "ecj "
optlevel = GetOptimizeOption(opts)
if optlevel >= 4:
cmd += "-debug:none "
cmd += "-cp " + GetOutputDir() + "/classes "
cmd += "-d " + GetOutputDir() + "/classes "
cmd += BracketNameWithQuotes(src)
oscmd(cmd)
##########################################################################################
#
# FreezePy
@ -2143,6 +2159,9 @@ def CompileAnything(target, inputs, opts, progress = None):
elif (origsuffix==".rsrc"):
ProgressOutput(progress, "Building resource object", target)
return CompileRsrc(target, infile, opts)
elif (origsuffix==".class"):
ProgressOutput(progress, "Building Java class", target)
return CompileJava(target, infile, opts)
elif (origsuffix==".obj"):
if (infile.endswith(".cxx")):
ProgressOutput(progress, "Building C++ object", target)
@ -3233,15 +3252,6 @@ if (PkgSkip("CONTRIB")==0):
CopyAllHeaders('contrib/src/contribbase')
CopyAllHeaders('contrib/src/ai')
########################################################################
#
# Copy Java files, if applicable
#
########################################################################
if GetTarget() == 'android':
CopyAllJavaSources('panda/src/android')
########################################################################
#
# These definitions are syntactic shorthand. They make it easy
@ -3561,7 +3571,7 @@ TargetAdd('libpandaexpress.dll', input='p3express_composite1.obj')
TargetAdd('libpandaexpress.dll', input='p3express_composite2.obj')
TargetAdd('libpandaexpress.dll', input='p3pandabase_pandabase.obj')
TargetAdd('libpandaexpress.dll', input=COMMON_DTOOL_LIBS)
TargetAdd('libpandaexpress.dll', opts=['ADVAPI', 'WINSOCK2', 'OPENSSL', 'ZLIB', 'WINGDI', 'WINUSER'])
TargetAdd('libpandaexpress.dll', opts=['ADVAPI', 'WINSOCK2', 'OPENSSL', 'ZLIB', 'WINGDI', 'WINUSER', 'ANDROID'])
#
# DIRECTORY: panda/src/pipeline/
@ -5059,6 +5069,8 @@ if (not RTDIST and not RUNTIME and PkgSkip("PVIEW")==0 and GetTarget() != 'andro
if (not RUNTIME and GetTarget() == 'android'):
OPTS=['DIR:panda/src/android']
TargetAdd('org/panda3d/android/NativeIStream.class', opts=OPTS, input='NativeIStream.java')
TargetAdd('org/panda3d/android/PandaActivity.class', opts=OPTS, input='PandaActivity.java', dep='org/panda3d/android/NativeIStream.class')
TargetAdd('p3android_composite1.obj', opts=OPTS, input='p3android_composite1.cxx')
TargetAdd('libp3android.dll', input='p3android_composite1.obj')
@ -5070,15 +5082,15 @@ if (not RUNTIME and GetTarget() == 'android'):
if (not RTDIST and PkgSkip("PVIEW")==0):
TargetAdd('pview_pview.obj', opts=OPTS, input='pview.cxx')
TargetAdd('pview.exe', input='android_native_app_glue.obj')
TargetAdd('pview.exe', input='android_main.obj')
TargetAdd('pview.exe', input='pview_pview.obj')
TargetAdd('pview.exe', input='libp3framework.dll')
TargetAdd('libpview.dll', input='android_native_app_glue.obj')
TargetAdd('libpview.dll', input='android_main.obj')
TargetAdd('libpview.dll', input='pview_pview.obj')
TargetAdd('libpview.dll', input='libp3framework.dll')
if not PkgSkip("EGG"):
TargetAdd('pview.exe', input='libpandaegg.dll')
TargetAdd('pview.exe', input='libp3android.dll')
TargetAdd('pview.exe', input=COMMON_PANDA_LIBS)
TargetAdd('AndroidManifest.xml', opts=OPTS, input='pview_manifest.xml')
TargetAdd('libpview.dll', input='libpandaegg.dll')
TargetAdd('libpview.dll', input='libp3android.dll')
TargetAdd('libpview.dll', input=COMMON_PANDA_LIBS)
TargetAdd('libpview.dll', opts=['MODULE', 'ANDROID'])
#
# DIRECTORY: panda/src/androiddisplay/

View File

@ -1145,12 +1145,7 @@ def MakeBuildTree():
MakeDirectory(OUTPUTDIR + "/Frameworks")
elif GetTarget() == 'android':
MakeDirectory(OUTPUTDIR + "/libs")
MakeDirectory(OUTPUTDIR + "/libs/" + ANDROID_ABI)
MakeDirectory(OUTPUTDIR + "/src")
MakeDirectory(OUTPUTDIR + "/src/org")
MakeDirectory(OUTPUTDIR + "/src/org/panda3d")
MakeDirectory(OUTPUTDIR + "/src/org/panda3d/android")
MakeDirectory(OUTPUTDIR + "/classes")
########################################################################
#
@ -2892,14 +2887,6 @@ def CopyAllHeaders(dir, skip=[]):
WriteBinaryFile(dstfile, ReadBinaryFile(srcfile))
JustBuilt([dstfile], [srcfile])
def CopyAllJavaSources(dir, skip=[]):
for filename in GetDirectoryContents(dir, ["*.java"], skip):
srcfile = dir + "/" + filename
dstfile = OUTPUTDIR + "/src/org/panda3d/android/" + filename
if (NeedsBuild([dstfile], [srcfile])):
WriteBinaryFile(dstfile, ReadBinaryFile(srcfile))
JustBuilt([dstfile], [srcfile])
def CopyTree(dstdir, srcdir, omitVCS=True):
if os.path.isdir(dstdir):
source_entries = os.listdir(srcdir)
@ -3147,6 +3134,7 @@ def CalcLocation(fn, ipath):
if fn.startswith("panda3d/") and fn.endswith(".py"):
return OUTPUTDIR + "/" + fn
if (fn.endswith(".class")):return OUTPUTDIR+"/classes/"+fn
if (fn.count("/")): return fn
dllext = ""
target = GetTarget()
@ -3162,6 +3150,7 @@ def CalcLocation(fn, ipath):
if (fn.endswith(".lxx")): return CxxFindSource(fn, ipath)
if (fn.endswith(".pdef")):return CxxFindSource(fn, ipath)
if (fn.endswith(".xml")): return CxxFindSource(fn, ipath)
if (fn.endswith(".java")):return CxxFindSource(fn, ipath)
if (fn.endswith(".egg")): return OUTPUTDIR+"/models/"+fn
if (fn.endswith(".egg.pz")):return OUTPUTDIR+"/models/"+fn
if (fn.endswith(".pyd")): return OUTPUTDIR+"/panda3d/"+fn[:-4]+GetExtensionSuffix()
@ -3197,15 +3186,6 @@ def CalcLocation(fn, ipath):
if (fn.endswith(".rsrc")): return OUTPUTDIR+"/tmp/"+fn
if (fn.endswith(".plugin")):return OUTPUTDIR+"/plugins/"+fn
if (fn.endswith(".app")): return OUTPUTDIR+"/bin/"+fn
elif (target == 'android'):
# On Android, we build the libraries into built/tmp, then copy them.
if (fn.endswith(".obj")): return OUTPUTDIR+"/tmp/"+fn[:-4]+".o"
if (fn.endswith(".dll")): return OUTPUTDIR+"/tmp/"+fn[:-4]+".so"
if (fn.endswith(".mll")): return OUTPUTDIR+"/plugins/"+fn
if (fn.endswith(".plugin")):return OUTPUTDIR+"/plugins/"+fn[:-7]+dllext+".so"
if (fn.endswith(".exe")): return OUTPUTDIR+"/tmp/lib"+fn[:-4]+".so"
if (fn.endswith(".lib")): return OUTPUTDIR+"/tmp/"+fn[:-4]+".a"
if (fn.endswith(".ilb")): return OUTPUTDIR+"/tmp/"+fn[:-4]+".a"
else:
if (fn.endswith(".obj")): return OUTPUTDIR+"/tmp/"+fn[:-4]+".o"
if (fn.endswith(".dll")): return OUTPUTDIR+"/lib/"+fn[:-4]+".so"