% # # @file make_py.goilTemplate # # @section desc File description # # Template to generate a make file in Python using the system # developed by Pierre Molinaro # # @section copyright Copyright # # Trampoline RTOS # # Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes # Trampoline is protected by the French intellectual property law. # # This software is distributed under the GNU Public Licence V2. # Check the LICENSE file in the root directory of Trampoline # # @section infos File informations # # $Date$ # $Rev$ # $Author$ # $URL$ # # Verify a subgoal is not used in more than one goal let usedGoal := @[] foreach pb in exists POSTBUILD default( @() ) do foreach cmd in exists pb::COMMAND default ( @() ) do if exists pb::SUBGOAL then if pb::SUBGOAL == true then if exists usedGoal[pb::NAME] then error pb::SUBGOAL_S::NAME : "This subgoal is already used" else let usedGoal[pb::NAME] := pb::SUBGOAL_S::NAME end if end if end if end foreach end foreach %#! /usr/bin/env python # -*- coding: UTF-8 -*- #---------------------------------------------------------------------- #--- Python Make file for application % !CPUNAME % #--- automatically generated by goil on % !TIMESTAMP % #--- from root OIL file % !OILFILENAME % #--- #--- Compiling a Trampoline application is done in 2 stages #--- 1 - From the OIL file, a set of files is generated as long as #--- build options. Among these files are the build.py and make.py #--- files. make.py contains compilation rules when the OIL file #--- and the included OIL files are modified. make.py is only #--- written once when the goil command is typed. #--- 2 - From all the C/assembly files (OS, Application, librairies, #--- configuration, ...), the objects and the executable are #--- produced. This is done by the build.py file. #--- build.py is generated each time goil is called by make.py #---------------------------------------------------------------------- from __future__ import print_function import sys, os, subprocess, atexit, string #--- Add the location of makefile.py to the import path sys.path.append("% !OS::BUILD_S::TRAMPOLINE_BASE_PATH %/make") #--- Import the makefile system in python try: import makefile, projfile except ImportError: #it defines inline the red color, as other are defined in the makefile.py print("\033[91mThe OS->BUILD->TRAMPOLINE_BASE_PATH key is not set correctly in the oil file % !OILFILENAME %.") print("Set the correct Trampoline installation path in the oil file and run goil again:\033[0m") print("goil -t=%!TARGET% --templates=%!TEMPLATEPATH% %!OILFILENAME%") sys.exit(1) #--- To work with relative paths scriptDir = os.path.dirname (os.path.abspath (sys.argv[0])) os.chdir (scriptDir) #--- Get goal as first argument askedGoal = "all" if len (sys.argv) > 1 : askedGoal = sys.argv [1] if askedGoal == "all" or askedGoal == "clean" : goal = askedGoal else : goal = "all" #--- Get max parallel jobs as second argument maxParallelJobs = 0 # 0 means use host processor count if len (sys.argv) > 2 : maxParallelJobs = int (sys.argv [2]) #--- Instanciate a new makefile object make = makefile.Make(goal) #---------------------------------------------------------------------- #--- Various variables used after #---------------------------------------------------------------------- oilFile = "% !OILFILENAME %" oilFileDep = "build/" + oilFile + ".dep" oilCompiler = "goil" oilFlags = ["-t=% !TARGET %"% if exists TEMPLATEPATH then if TEMPLATEPATH != "" then %, "--templates=% !TEMPLATEPATH %"% end if end if %] trampoline_base_path = "% !OS::BUILD_S::TRAMPOLINE_BASE_PATH %/" #---------------------------------------------------------------------- #--- Build the source files list #---------------------------------------------------------------------- oilSourceList = [] sourceList = [] #--- Add generated files sourceList.append("% !PROJECT %/tpl_app_config.c") % if OS::SYSTEM_CALL then % sourceList.append("% !PROJECT %/tpl_dispatch_table.c") sourceList.append("% !PROJECT %/tpl_invoque.S")% else % sourceList.append("% !PROJECT %/tpl_os.c")% end if if [TRANSACTION length] > 0 then % sourceList.append("% !PROJECT %/stm_structure.c")% end if if [IOC length] > 0 then % sourceList.append("% !PROJECT %/tpl_ioc_api_config.c")% end if foreach platform in exists GENERATED_FILES default ( @() ) do if not exists platform::CFILE then let platform::CFILE := @() end if if not exists platform::ASFILE then let platform::ASFILE := @() end if foreach file in platform::CFILE do % sourceList.append("% !PROJECT+"/"+file::VALUE %")% end foreach foreach file in platform::ASFILE do % sourceList.append("% !PROJECT+"/"+file::VALUE %")% end foreach end foreach % rule = makefile.Rule (sourceList, "Compiling OIL file " + oilFile) rule.deleteTargetFileOnClean() rule.mDeleteTargetOnError = True rule.mDependences.append(oilFile) rule.enterSecondaryDependanceFile(oilFileDep, make) rule.mCommand.append("goil") rule.mCommand += oilFlags rule.mCommand.append(oilFile) make.addRule (rule) make.addGoal("all", sourceList, "Building all") if goal == "all" or goal == "clean" : make.runGoal(maxParallelJobs, maxParallelJobs == 1) #---------------------------------------------------------------------- #--- Call the seconde stage of make #---------------------------------------------------------------------- def cleanup(): if childProcess.poll () == None : childProcess.kill () #--- Register a function for killing subprocess atexit.register (cleanup) #--- Get script absolute path scriptDir = os.path.dirname (os.path.abspath (sys.argv [0])) os.chdir (scriptDir) #--- Launch build.py # is there the 'python' executable? import distutils.spawn if distutils.spawn.find_executable("python"): childProcess = subprocess.Popen (["python", "build.py", askedGoal, str(maxParallelJobs)]) else: #no python executable, maybe python3 childProcess = subprocess.Popen (["python3", "build.py", askedGoal, str(maxParallelJobs)]) #--- Wait for subprocess termination if childProcess.poll () == None : childProcess.wait () if childProcess.returncode != 0 : sys.exit (childProcess.returncode) #----------------------------------------------------------------------