2013-04-17 21:41:41 +02:00
#!/usr/bin/python
2014-09-16 21:40:07 +02:00
##
## @author Edouard DUPIN
##
## @copyright 2012, Edouard DUPIN, all right reserved
##
## @license APACHE v2.0 (see license file)
##
2013-04-17 21:41:41 +02:00
# for path inspection:
2013-04-18 01:46:47 +02:00
import sys
2013-04-17 21:41:41 +02:00
import os
2013-04-18 01:46:47 +02:00
import inspect
2013-04-17 21:41:41 +02:00
import fnmatch
2013-04-21 22:17:47 +02:00
import lutinDebug as debug
import lutinEnv
2013-04-22 21:37:13 +02:00
import lutinModule
2013-04-24 21:30:46 +02:00
import lutinMultiprocess
2013-05-24 21:25:03 +02:00
import lutinArg
2013-12-23 22:22:24 +01:00
myLutinArg = lutinArg . LutinArg ( )
myLutinArg . add ( lutinArg . ArgDefine ( " h " , " help " , desc = " display this help " ) )
myLutinArg . add_section ( " option " , " Can be set one time in all case " )
myLutinArg . add ( lutinArg . ArgDefine ( " v " , " verbose " , list = [ [ " 0 " , " None " ] , [ " 1 " , " error " ] , [ " 2 " , " warning " ] , [ " 3 " , " info " ] , [ " 4 " , " debug " ] , [ " 5 " , " verbose " ] ] , desc = " display makefile debug level (verbose) default =2 " ) )
myLutinArg . add ( lutinArg . ArgDefine ( " C " , " color " , desc = " display makefile output in color " ) )
myLutinArg . add ( lutinArg . ArgDefine ( " f " , " force " , desc = " Force the rebuild without checking the dependency " ) )
myLutinArg . add ( lutinArg . ArgDefine ( " P " , " pretty " , desc = " print the debug has pretty display " ) )
myLutinArg . add ( lutinArg . ArgDefine ( " j " , " jobs " , haveParam = True , desc = " Specifies the number of jobs (commands) to run simultaneously " ) )
myLutinArg . add ( lutinArg . ArgDefine ( " s " , " force-strip " , desc = " Force the stripping of the compile elements " ) )
2013-05-24 21:25:03 +02:00
2013-12-23 22:22:24 +01:00
myLutinArg . add_section ( " properties " , " keep in the sequency of the cible " )
2014-09-16 21:40:07 +02:00
myLutinArg . add ( lutinArg . ArgDefine ( " t " , " target " , haveParam = True , desc = " Select a target (by default the platform is the computer that compile this) To know list : ' lutin.py --list-target ' " ) )
2013-12-23 22:22:24 +01:00
myLutinArg . add ( lutinArg . ArgDefine ( " c " , " compilator " , list = [ [ " clang " , " " ] , [ " gcc " , " " ] ] , desc = " Compile with clang or Gcc mode (by default gcc will be used) " ) )
myLutinArg . add ( lutinArg . ArgDefine ( " m " , " mode " , list = [ [ " debug " , " " ] , [ " release " , " " ] ] , desc = " Compile in release or debug mode (default release) " ) )
2014-09-15 22:37:53 +02:00
myLutinArg . add ( lutinArg . ArgDefine ( " a " , " arch " , list = [ [ " auto " , " Automatic choice " ] , [ " arm " , " Arm processer " ] , [ " x86 " , " Generic PC : AMD/Intel " ] , [ " ppc " , " Power PC " ] ] , desc = " Architecture to compile " ) )
myLutinArg . add ( lutinArg . ArgDefine ( " b " , " bus " , list = [ [ " auto " , " Automatic choice " ] , [ " 32 " , " 32 bits " ] , [ " 64 " , " 64 bits " ] ] , desc = " Adressing size (Bus size) " ) )
2013-12-23 22:22:24 +01:00
myLutinArg . add ( lutinArg . ArgDefine ( " p " , " package " , desc = " Disable the package generation (usefull when just compile for test on linux ...) " ) )
2014-11-25 22:07:48 +01:00
myLutinArg . add ( lutinArg . ArgDefine ( " g " , " gcov " , desc = " Enable code coverage intrusion in code " ) )
2014-04-22 23:33:07 +02:00
myLutinArg . add ( lutinArg . ArgDefine ( " " , " simulation " , desc = " simulater mode (availlable only for IOS) " ) )
2014-08-07 21:00:31 +02:00
myLutinArg . add ( lutinArg . ArgDefine ( " " , " list-target " , desc = " list all availlables targets ==> for auto completion " ) )
myLutinArg . add ( lutinArg . ArgDefine ( " " , " list-module " , desc = " list all availlables module ==> for auto completion " ) )
2013-05-24 21:25:03 +02:00
2013-12-23 22:22:24 +01:00
myLutinArg . add_section ( " cible " , " generate in order set " )
localArgument = myLutinArg . parse ( )
2013-04-17 21:41:41 +02:00
"""
2013-12-23 22:22:24 +01:00
display the help of this makefile
2013-04-17 21:41:41 +02:00
"""
2013-04-19 22:06:05 +02:00
def usage ( ) :
2013-05-24 21:25:03 +02:00
# generic argument displayed :
2013-12-23 22:22:24 +01:00
myLutinArg . display ( )
2015-01-12 23:47:53 +01:00
print " All target can finish with ' -clean ' ' -dump ' ... "
2013-04-22 21:37:13 +02:00
print " all "
2013-12-23 22:22:24 +01:00
print " build all (only for the current selected board) (bynary and packages) "
2013-04-22 21:37:13 +02:00
print " clean "
2013-12-23 22:22:24 +01:00
print " clean all (same as previous) "
2013-04-22 21:37:13 +02:00
print " dump "
print " Dump all the module dependency and properties "
2013-12-23 22:22:24 +01:00
listOfAllModule = lutinModule . list_all_module_with_desc ( )
2013-04-22 21:37:13 +02:00
for mod in listOfAllModule :
2015-01-12 23:47:53 +01:00
print " " + mod [ 0 ]
2013-12-23 22:22:24 +01:00
if mod [ 1 ] != " " :
print " " + mod [ 1 ]
2013-07-11 11:21:25 +02:00
print " ex: " + sys . argv [ 0 ] + " all --target=Android all -t Windows -m debug all "
2013-04-18 01:46:47 +02:00
exit ( 0 )
2013-04-17 21:41:41 +02:00
2013-07-09 15:00:07 +02:00
# preparse the argument to get the verbose element for debug mode
2013-04-19 22:06:05 +02:00
def parseGenericArg ( argument , active ) :
2013-12-23 22:22:24 +01:00
if argument . get_option_nName ( ) == " help " :
2013-04-19 22:06:05 +02:00
#display help
2013-04-22 21:37:13 +02:00
if active == False :
usage ( )
2013-04-19 22:06:05 +02:00
return True
2014-08-07 21:00:31 +02:00
if argument . get_option_nName ( ) == " list-module " :
if active == False :
listOfModule = lutinModule . list_all_module ( )
retValue = " "
for moduleName in listOfModule :
if retValue != " " :
retValue + = " "
retValue + = moduleName
print retValue
exit ( 0 )
return True
if argument . get_option_nName ( ) == " list-target " :
if active == False :
listOfTarget = lutinTarget . list_all_target ( )
retValue = " "
for targetName in listOfTarget :
if retValue != " " :
retValue + = " "
retValue + = targetName
print retValue
exit ( 0 )
return True
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " jobs " :
2013-04-19 22:06:05 +02:00
if active == True :
2013-12-23 22:22:24 +01:00
lutinMultiprocess . set_core_number ( int ( argument . get_arg ( ) ) )
2013-04-19 22:06:05 +02:00
return True
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " verbose " :
2013-04-19 22:06:05 +02:00
if active == True :
2013-12-23 22:22:24 +01:00
debug . set_level ( int ( argument . get_arg ( ) ) )
2013-04-19 22:06:05 +02:00
return True
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " color " :
2013-04-19 22:06:05 +02:00
if active == True :
2013-12-23 22:22:24 +01:00
debug . enable_color ( )
2013-04-19 22:06:05 +02:00
return True
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " force " :
2013-04-19 22:06:05 +02:00
if active == True :
2013-12-23 22:22:24 +01:00
lutinEnv . set_force_mode ( True )
2013-04-19 22:06:05 +02:00
return True
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " pretty " :
2013-07-09 15:00:07 +02:00
if active == True :
2013-12-23 22:22:24 +01:00
lutinEnv . set_print_pretty_mode ( True )
2013-07-09 15:00:07 +02:00
return True
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " force-strip " :
2013-08-27 21:11:03 +02:00
if active == True :
2013-12-23 22:22:24 +01:00
lutinEnv . set_force_strip_mode ( True )
2013-08-27 21:11:03 +02:00
return True
2013-04-19 22:06:05 +02:00
return False
# parse default unique argument:
if __name__ == " __main__ " :
2013-05-24 21:25:03 +02:00
for argument in localArgument :
2013-04-19 22:06:05 +02:00
parseGenericArg ( argument , True )
# now import other standard module (must be done here and not before ...
2013-04-22 21:37:13 +02:00
import lutinTarget
2015-02-06 23:32:12 +01:00
import lutinSystem
2013-04-22 21:37:13 +02:00
import lutinHost
2013-04-21 22:17:47 +02:00
import lutinTools
2013-04-18 22:09:45 +02:00
2013-04-17 21:41:41 +02:00
"""
2013-04-18 01:46:47 +02:00
Run everything that is needed in the system
2013-04-17 21:41:41 +02:00
"""
2013-04-18 01:46:47 +02:00
def Start ( ) :
2013-04-22 21:37:13 +02:00
#available target : Linux / MacOs / Windows / Android ...
targetName = lutinHost . OS
2014-09-16 21:40:07 +02:00
config = {
" compilator " : " gcc " ,
" mode " : " release " ,
" bus-size " : " auto " ,
" arch " : " auto " ,
" generate-package " : True ,
" simulation " : False ,
2014-11-25 22:07:48 +01:00
" gcov " : False
2014-09-16 21:40:07 +02:00
}
2013-04-22 21:37:13 +02:00
# load the default target :
target = None
2013-04-19 22:06:05 +02:00
actionDone = False
2013-04-18 01:46:47 +02:00
# parse all argument
2013-05-24 21:25:03 +02:00
for argument in localArgument :
2013-04-19 22:06:05 +02:00
if True == parseGenericArg ( argument , False ) :
2013-10-15 21:31:41 +02:00
continue
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " package " :
2014-09-16 21:40:07 +02:00
config [ " generate-package " ] = False
2014-04-22 23:33:07 +02:00
elif argument . get_option_nName ( ) == " simulation " :
2014-09-16 21:40:07 +02:00
config [ " simulation " ] = True
2014-11-25 22:07:48 +01:00
elif argument . get_option_nName ( ) == " gcov " :
config [ " gcov " ] = True
2014-09-15 22:37:53 +02:00
elif argument . get_option_nName ( ) == " bus " :
2014-09-16 21:40:07 +02:00
config [ " bus-size " ] = argument . get_arg ( )
2014-09-15 22:37:53 +02:00
elif argument . get_option_nName ( ) == " arch " :
2014-09-16 21:40:07 +02:00
config [ " arch " ] = argument . get_arg ( )
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " compilator " :
2014-09-17 00:18:28 +02:00
if config [ " compilator " ] != argument . get_arg ( ) :
2013-12-23 22:22:24 +01:00
debug . debug ( " change compilator ==> " + argument . get_arg ( ) )
2014-09-17 00:18:28 +02:00
config [ " compilator " ] = argument . get_arg ( )
2013-05-24 21:25:03 +02:00
#remove previous target
target = None
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " target " :
2013-04-22 21:37:13 +02:00
# No check input ==> this will be verify automaticly chen the target will be loaded
2013-12-23 22:22:24 +01:00
if targetName != argument . get_arg ( ) :
targetName = argument . get_arg ( )
2014-09-16 21:40:07 +02:00
debug . debug ( " change target ==> ' " + targetName + " ' & reset mode : gcc&release " )
2013-04-22 21:37:13 +02:00
#reset properties by defauult:
2014-09-16 21:40:07 +02:00
config = {
" compilator " : " gcc " ,
" mode " : " release " ,
" bus-size " : " auto " ,
" arch " : " auto " ,
" generate-package " : True ,
" simulation " : False ,
2014-11-25 22:07:48 +01:00
" gcov " : False
2014-09-16 21:40:07 +02:00
}
2013-04-22 21:37:13 +02:00
#remove previous target
target = None
2013-12-23 22:22:24 +01:00
elif argument . get_option_nName ( ) == " mode " :
2014-09-16 21:40:07 +02:00
if config [ " mode " ] != argument . get_arg ( ) :
config [ " mode " ] = argument . get_arg ( )
debug . debug ( " change mode ==> " + config [ " mode " ] )
2013-05-24 21:25:03 +02:00
#remove previous target
target = None
2013-04-19 22:06:05 +02:00
else :
2013-12-23 22:22:24 +01:00
if argument . get_option_nName ( ) != " " :
debug . warning ( " Can not understand argument : ' " + argument . get_option_nName ( ) + " ' " )
2013-05-24 22:02:09 +02:00
usage ( )
else :
#load the target if needed :
if target == None :
2014-09-16 21:40:07 +02:00
target = lutinTarget . load_target ( targetName , config )
2013-12-23 22:22:24 +01:00
target . build ( argument . get_arg ( ) )
2013-05-24 22:02:09 +02:00
actionDone = True
2013-04-19 22:06:05 +02:00
# if no action done : we do "all" ...
if actionDone == False :
2013-04-22 21:37:13 +02:00
#load the target if needed :
if target == None :
2014-09-16 21:40:07 +02:00
target = lutinTarget . load_target ( targetName , config )
2013-12-23 22:22:24 +01:00
target . build ( " all " )
2013-04-24 21:30:46 +02:00
# stop all started threads
2013-12-23 22:22:24 +01:00
lutinMultiprocess . un_init ( )
2013-04-17 21:41:41 +02:00
"""
2013-04-18 01:46:47 +02:00
When the user use with make . py we initialise ourself
2013-04-17 21:41:41 +02:00
"""
2013-04-18 01:46:47 +02:00
if __name__ == ' __main__ ' :
debug . verbose ( " Use Make as a make stadard " )
2013-12-23 22:22:24 +01:00
sys . path . append ( lutinTools . get_run_folder ( ) )
2013-04-21 22:17:47 +02:00
debug . verbose ( " try to impoert module ' lutinBase.py ' " )
2013-09-02 21:23:38 +02:00
if os . path . exists ( " lutinBase.py " ) == True :
__import__ ( " lutinBase " )
else :
debug . debug ( " missing file lutinBase.py ==> loading subPath... " ) ;
# Import all sub path without out and archive
for folder in os . listdir ( " . " ) :
if os . path . isdir ( folder ) == True :
if folder . lower ( ) != " android " \
and folder . lower ( ) != " archive " \
and folder . lower ( ) != " out " :
debug . debug ( " Automatic load path: ' " + folder + " ' " )
2013-12-23 22:22:24 +01:00
lutinModule . import_path ( folder )
2015-02-06 23:32:12 +01:00
lutinSystem . import_path ( folder )
2014-09-16 21:40:07 +02:00
lutinTarget . import_path ( folder )
2015-02-06 23:32:12 +01:00
#lutinSystem.display()
2013-04-18 01:46:47 +02:00
Start ( )
2013-04-17 21:41:41 +02:00