prepare.py 2.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/usr/bin/env python

############################################################################
# prepare.py
# Copyright (C) 2016  Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
############################################################################

import fnmatch
import os
import re
import sys
from distutils.spawn import find_executable
from logging import error, warning, info
from subprocess import Popen
from android import AndroidPreparator
33
from ios import IOSPreparator
34 35 36 37 38 39 40 41 42 43 44
sys.dont_write_bytecode = True
sys.path.insert(0, 'submodules/cmake-builder')
try:
    import prepare
except Exception as e:
    error(
        "Could not find prepare module: {}, probably missing submodules/cmake-builder? Try running:\n"
        "git submodule sync && git submodule update --init --recursive".format(e))
    exit(1)

def main():
45 46 47 48 49 50 51 52 53 54 55 56 57
    amakefile = ""
    imakefile = ""
    atarget = ""
    itarget = ""
    if not '-DENABLE_ANDROID=OFF' in sys.argv and not '-DENABLE_ANDROID=NO' in sys.argv:
        android = AndroidPreparator()
        if android.check_environment() != 0:
            android.show_environment_errors()
            return 1
        android.parse_args()
        android.run()
        amakefile = "include Makefile.android"
        atarget = "generate-android-sdk"
58

59 60 61
    if not '-DENABLE_IOS=OFF' in sys.argv and not '-DENABLE_IOS=NO' in sys.argv:
        ios = IOSPreparator()
        if ios.check_environment() != 0:
62 63
            ios.show_environment_errors()
            return 1
64 65 66 67
        ios.parse_args()
        ios.run()
        imakefile = "include Makefile.ios"
        itarget = "generate-ios-sdk"
68

69 70
    if not '-c' in sys.argv:
        makefile = """
71 72 73
.PHONY: all
.NOTPARALLEL: all

74 75
VERSION=$(shell git --git-dir=submodules/linphone/.git --work-tree=submodules/linphone describe)

76 77
{amakefile}
{imakefile}
78

79
all: {atarget} {itarget} sdk
80 81

sdk:
82
\tzip -r liblinphone-xamarin-sdk-$(VERSION).zip Xamarin README.md
83
""".format(amakefile=amakefile, imakefile=imakefile, atarget=atarget, itarget=itarget)
84 85 86 87 88 89
        f = open('Makefile', 'w')
        f.write(makefile)
        f.close()
    else:
        if os.path.isfile('Makefile'):
            os.remove('Makefile')
90 91 92
    return 0

if __name__ == "__main__":
93
    sys.exit(main())