def run(self):
        startTime = time.time()
        #--- Source file list
        SOURCES = self.mDictionary["SOURCES"]
        #--- LIBPM
        LIBPM_DIRECTORY_PATH = self.mDictionary["LIBPM_DIRECTORY_PATH"]
        #--------------------------------------------------------------------------- System
        if self.mCrossCompilation == "":
            (SYSTEM_NAME, MODE_NAME, SYSTEM_RELEASE, SYSTEM_VERSION,
             MACHINE) = os.uname()
            if SYSTEM_NAME == "Darwin":
                MACHINE = "Intel"
            SYSTEM_MACHINE = SYSTEM_NAME + "-" + MACHINE
        else:
            SYSTEM_MACHINE = self.mCrossCompilation
    #--- GMP
        GMP_DIRECTORY_PATH = LIBPM_DIRECTORY_PATH + "/gmp"
        #--- Source directory list
        SOURCES_DIR = self.mDictionary["SOURCES_DIR"]
        #--------------------------------------------------------------------------- Include dirs
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/bdd")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/command_line_interface")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/files")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/galgas")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/galgas2")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/gmp")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/streams")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/time")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/strings")
        SOURCES_DIR.append(LIBPM_DIRECTORY_PATH + "/utilities")
        includeDirs = ["-I" + GMP_DIRECTORY_PATH]
        for d in SOURCES_DIR:
            includeDirs.append("-I" + d)
    #--- Make object
        make = makefile.Make(
            self.mGoal, self.mMaxParallelJobs ==
            1)  # Display command utility tool path if sequential build
        #--------------------------------------------------------------------------- Add Compile rule for sources (release)
        #--- Object file directory
        objectDirectory = "../build/cli-objects/makefile-" + self.mTargetName + "-objects"
        #---
        objectFileList = []
        for source in SOURCES:
            objectFile = objectDirectory + "/" + source + ".o"
            objectFileList.append(objectFile)
            sourcePath = make.searchFileInDirectories(source, SOURCES_DIR)
            if sourcePath != "":
                extension = os.path.splitext(source)[1]
                rule = makefile.Rule([objectFile],
                                     self.mCompilationMessage + ": " + source)
                rule.deleteTargetDirectoryOnClean()
                rule.mDependences.append(sourcePath)
                rule.enterSecondaryDependanceFile(objectFile + ".dep", make)
                rule.mCommand += self.mCompilerTool
                rule.mCommand += self.mCompilerReleaseOptions
                rule.mCommand += self.mAllCompilerOptions
                if extension == ".c":
                    rule.mCommand += self.m_C_CompilerOptions
                elif extension == ".cpp":
                    rule.mCommand += self.m_Cpp_CompilerOptions
                rule.mCommand += ["-c", sourcePath]
                rule.mCommand += ["-o", objectFile]
                rule.mCommand += includeDirs
                rule.mCommand += ["-MD", "-MP", "-MF", objectFile + ".dep"]
                make.addRule(rule)
    #--------------------------------------------------------------------------- Add EXECUTABLE link rule
        EXECUTABLE = self.mExecutable + self.mExecutableSuffix
        rule = makefile.Rule([EXECUTABLE],
                             self.mLinkingMessage + ": " + EXECUTABLE)
        rule.mOnErrorDeleteTarget = True
        rule.deleteTargetFileOnClean()
        rule.mDependences += objectFileList
        rule.mDependences.append(self.mJSONfilePath)
        rule.mCommand += self.mLinkerTool
        rule.mCommand += objectFileList
        rule.mCommand += ["-o", EXECUTABLE]
        rule.mCommand += self.mLinkerOptions
        postCommand = makefile.PostCommand(self.mStripMessage + " " +
                                           EXECUTABLE)
        postCommand.mCommand += self.mStripTool
        postCommand.mCommand.append(EXECUTABLE)
        rule.mPostCommands.append(postCommand)
        rule.mPriority = 1
        make.addRule(rule)
        #--------------------------------------------------------------------------- Add Compile rule for sources (debug)
        #--- Object file directory
        debugObjectDirectory = "../build/cli-objects/makefile-" + self.mTargetName + "-debug-objects"
        #---
        debugObjectFileList = []
        for source in SOURCES:
            objectFile = debugObjectDirectory + "/" + source + ".o"
            debugObjectFileList.append(objectFile)
            sourcePath = make.searchFileInDirectories(source, SOURCES_DIR)
            if sourcePath != "":
                extension = os.path.splitext(source)[1]
                rule = makefile.Rule([objectFile], self.mCompilationMessage +
                                     " (debug): " + source)
                rule.deleteTargetDirectoryOnClean()
                rule.mDependences.append(sourcePath)
                rule.enterSecondaryDependanceFile(objectFile + ".dep", make)
                rule.mCommand += self.mCompilerTool
                rule.mCommand += self.mCompilerDebugOptions
                rule.mCommand += self.mAllCompilerOptions
                if extension == ".c":
                    rule.mCommand += self.m_C_CompilerOptions
                elif extension == ".cpp":
                    rule.mCommand += self.m_Cpp_CompilerOptions
                rule.mCommand += ["-c", sourcePath]
                rule.mCommand += ["-o", objectFile]
                rule.mCommand += includeDirs
                rule.mCommand += ["-MD", "-MP", "-MF", objectFile + ".dep"]
                make.addRule(rule)
    #--------------------------------------------------------------------------- Add EXECUTABLE_DEBUG link rule
        EXECUTABLE_DEBUG = self.mExecutable + "-debug" + self.mExecutableSuffix
        rule = makefile.Rule([EXECUTABLE_DEBUG], self.mLinkingMessage +
                             " (debug): " + EXECUTABLE_DEBUG)
        rule.mOnErrorDeleteTarget = True
        rule.deleteTargetFileOnClean()
        rule.mDependences += debugObjectFileList
        rule.mDependences.append(self.mJSONfilePath)
        rule.mCommand += self.mLinkerTool
        rule.mCommand += debugObjectFileList
        rule.mCommand += ["-o", EXECUTABLE_DEBUG]
        rule.mCommand += self.mLinkerOptions
        make.addRule(rule)
        #--------------------------------------------------------------------------- Add Compile rule for sources (lto)
        #--- Object file directory
        objectLTODirectory = "../build/cli-objects/makefile-" + self.mTargetName + "-objects-lto"
        #---
        ltoObjectFileList = []
        for source in SOURCES:
            objectFile = objectLTODirectory + "/" + source + ".o"
            ltoObjectFileList.append(objectFile)
            sourcePath = make.searchFileInDirectories(source, SOURCES_DIR)
            if sourcePath != "":
                extension = os.path.splitext(source)[1]
                rule = makefile.Rule([objectFile], self.mCompilationMessage +
                                     " (lto): " + source)
                rule.deleteTargetDirectoryOnClean()
                rule.mDependences.append(sourcePath)
                rule.enterSecondaryDependanceFile(objectFile + ".dep", make)
                rule.mCommand += self.mCompilerTool
                rule.mCommand += self.mCompilerReleaseOptions
                rule.mCommand += self.mAllCompilerOptions
                rule.mCommand += ["-flto"]
                if extension == ".c":
                    rule.mCommand += self.m_C_CompilerOptions
                elif extension == ".cpp":
                    rule.mCommand += self.m_Cpp_CompilerOptions
                rule.mCommand += ["-c", sourcePath]
                rule.mCommand += ["-o", objectFile]
                rule.mCommand += includeDirs
                rule.mCommand += ["-MD", "-MP", "-MF", objectFile + ".dep"]
                make.addRule(rule)
    #--------------------------------------------------------------------------- Add EXECUTABLE link rule
        EXECUTABLE_LTO = self.mExecutable + "-lto" + self.mExecutableSuffix
        rule = makefile.Rule([EXECUTABLE_LTO],
                             self.mLinkingMessage + ": " + EXECUTABLE_LTO)
        rule.mOnErrorDeleteTarget = True
        rule.deleteTargetFileOnClean()
        rule.mDependences += ltoObjectFileList
        rule.mDependences.append(self.mJSONfilePath)
        rule.mCommand += self.mLinkerTool
        rule.mCommand += ltoObjectFileList
        rule.mCommand += ["-o", EXECUTABLE_LTO]
        rule.mCommand += self.mLinkerOptions
        rule.mCommand += ["-flto"]
        postCommand = makefile.PostCommand(self.mStripMessage + " " +
                                           EXECUTABLE_LTO)
        postCommand.mCommand += self.mStripTool
        postCommand.mCommand.append(EXECUTABLE_LTO)
        rule.mPostCommands.append(postCommand)
        rule.mPriority = 1
        make.addRule(rule)
        #--------------------------------------------------------------------------- Add install EXECUTABLE file rule
        if len(self.mSudoTool) > 0:
            INSTALL_EXECUTABLE = "/usr/local/bin/" + EXECUTABLE
            rule = makefile.Rule([INSTALL_EXECUTABLE],
                                 self.mInstallationgMessage + ": " +
                                 INSTALL_EXECUTABLE)
            rule.mDependences.append(EXECUTABLE)
            rule.mCommand += self.mSudoTool
            rule.mCommand += ["cp", EXECUTABLE, INSTALL_EXECUTABLE]
            make.addRule(rule)
    #--------------------------------------------------------------------------- Add install EXECUTABLE-lto file rule
        if len(self.mSudoTool) > 0:
            INSTALL_EXECUTABLE_LTO = "/usr/local/bin/" + EXECUTABLE_LTO
            rule = makefile.Rule([INSTALL_EXECUTABLE_LTO],
                                 self.mInstallationgMessage + ": " +
                                 INSTALL_EXECUTABLE_LTO)
            rule.mDependences.append(EXECUTABLE)
            rule.mCommand += self.mSudoTool
            rule.mCommand += ["cp", EXECUTABLE_LTO, INSTALL_EXECUTABLE_LTO]
            make.addRule(rule)
    #--------------------------------------------------------------------------- Add install EXECUTABLE-debug file rule
        if len(self.mSudoTool) > 0:
            INSTALL_EXECUTABLE_DEBUG = "/usr/local/bin/" + EXECUTABLE_DEBUG
            rule = makefile.Rule([INSTALL_EXECUTABLE_DEBUG],
                                 self.mInstallationgMessage + " (debug): " +
                                 INSTALL_EXECUTABLE_DEBUG)
            rule.mDependences.append(INSTALL_EXECUTABLE_DEBUG)
            rule.mCommand += self.mSudoTool
            rule.mCommand += ["cp", EXECUTABLE_DEBUG, INSTALL_EXECUTABLE_DEBUG]
            make.addRule(rule)
    #--------------------------------------------------------------------------- Compute jobs
    # make.printRules ()
        make.addGoal("all", [EXECUTABLE, EXECUTABLE_DEBUG],
                     "Build " + EXECUTABLE + " and " + EXECUTABLE_DEBUG)
        make.addGoal("debug", [EXECUTABLE_DEBUG], "Build " + EXECUTABLE_DEBUG)
        make.addGoal("release", [EXECUTABLE], "Build " + EXECUTABLE)
        make.addGoal("lto", [EXECUTABLE_LTO], "Build " + EXECUTABLE_LTO)
        if len(self.mSudoTool) > 0:
            make.addGoal("install-lto", [INSTALL_EXECUTABLE_LTO],
                         "Build and install " + INSTALL_EXECUTABLE_LTO)
            make.addGoal("install-release", [INSTALL_EXECUTABLE],
                         "Build and install " + INSTALL_EXECUTABLE)
            make.addGoal("install-debug", [INSTALL_EXECUTABLE_DEBUG],
                         "Build and install " + INSTALL_EXECUTABLE_DEBUG)

    #--------------------------------------------------------------------------- Run jobs
    # make.printGoals ()
        make.runGoal(self.mMaxParallelJobs, self.mDisplayCommands)
        #--------------------------------------------------------------------------- Ok ?
        make.printErrorCountAndExitOnError()
        displayDurationFromStartTime(startTime)
Exemple #2
0
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
#----------------------------------------------------------------------
compiler = r"avr-gcc"
cppCompiler = r"avr-g++"
linker = r"avr-gcc"
assembler = r"avr-gcc"
autosar = False
autosar_sc = 0
autosar_osapplications = False
with_ioc = False
with_com = False
scheduler = "osek"
trampoline_base_path = "../../trampoline/"
Exemple #3
0
def buildCode (GOAL, projectDir, maxConcurrentJobs, verbose):
  DEV_FILES_DIR = os.path.dirname (os.path.realpath (__file__))
#   print ("DEV_FILES_DIR: " + DEV_FILES_DIR)
#--------------------------------------------------------------------------- Prepare
  os.chdir (projectDir)
  make = makefile.Make (GOAL)
#   make.mMacTextEditor = "BBEdit" # "Atom"
  allGoal = []
#--------------------------------------------------------------------------- Analyze JSON file
  print (makefile.BOLD_GREEN () + "--- Making " + projectDir + makefile.ENDC ())
  dictionaire = dictionaryFromJsonFile (projectDir + "/makefile.json")
#   print ("JSON DICTIONARY: ")
#   print (dictionaire)
#--------------------------------------------------------------------------- Find target
  targetNameSet = set ()
  foundIRQSectionScheme = False
  for name in os.listdir (DEV_FILES_DIR + "/targets") :
    if not name.startswith ('.') :
      targetNameSet.add (name)
  if not "TARGET" in dictionaire:
    s = "\"TARGET\" is not defined in the makefile.json file; possible values:\n"
    for target in targetNameSet :
      s += "  -  \"" + target + "\"\n"
    print (makefile.BOLD_RED () + s + makefile.ENDC ())
    sys.exit (1)
  targetName = dictionaire ["TARGET"]
  if not targetName in targetNameSet :
    s = "In the makefile.json file, \"TARGET\" value \"" + targetName + "\" is invalid; "
    s += "possible values:\n"
    for target in targetNameSet :
      s += "  -  \"" + target + "\"\n"
    print (makefile.BOLD_RED () + s + makefile.ENDC ())
    sys.exit (1)
  TARGET_DIR = DEV_FILES_DIR + "/targets/" + targetName
  sys.path.append (TARGET_DIR + "/deployment")
  import deployment
#--------------------------------------------------------------------------- Install compiler ?
  BASE_NAME = "arm-none-eabi"
  TOOL_DIR = download_and_install_gccarm.installGCCARMandGetToolDirectory ()
#--------------------------------------------------------------------------- Target Dictionary
  targetDictionary = dictionaryFromJsonFile (TARGET_DIR + "/helpers/target-parameters.json")
#--------------------------------------------------------------------------- Configure compiler
  gccOptions = targetDictionary ["GCC-OPTIONS"]
  AS_TOOL_WITH_OPTIONS = [TOOL_DIR + "/bin/" + BASE_NAME + "-as"]
  AS_TOOL_WITH_OPTIONS += gccOptions
  COMPILER_TOOL_WITH_OPTIONS = [TOOL_DIR + "/bin/" + BASE_NAME + "-gcc"]
  COMPILER_TOOL_WITH_OPTIONS += gccOptions
#   LD_TOOL_WITH_OPTIONS = [TOOL_DIR + "/bin/" + BASE_NAME + "-ld"]
  LD_TOOL_WITH_OPTIONS = COMPILER_TOOL_WITH_OPTIONS
  # OBJCOPY_TOOL_WITH_OPTIONS = [TOOL_DIR + "/bin/" + BASE_NAME + "-objcopy"]
  DISPLAY_OBJ_SIZE_TOOL = [TOOL_DIR + "/bin/" + BASE_NAME + "-size"]
#   OBJDUMP_TOOL = TOOL_DIR + "/bin/" + BASE_NAME + "-objdump"
#--------------------------------------------------------------------------- Parse JSON dictinary
#--- SCHEME
  if "SCHEME" in dictionaire:
    SCHEME = dictionaire ["SCHEME"]
    schemeFilePath = TARGET_DIR + "/schemes/" + SCHEME + ".json"
    if os.path.exists (schemeFilePath) :
      schemeDictionary = dictionaryFromJsonFile (schemeFilePath)
      dictionaire ["UNUSED-IRQ-SCHEME"] = schemeDictionary ["UNUSED-IRQ-SCHEME"]
      dictionaire ["IRQ-SECTION-SCHEME"] = schemeDictionary ["IRQ-SECTION-SCHEME"]
      dictionaire ["SERVICE-SCHEME"] = schemeDictionary ["SERVICE-SCHEME"]
      dictionaire ["SECTION-SCHEME"] = schemeDictionary ["SECTION-SCHEME"]
      dictionaire ["SOURCES-IN-DEV-DIR"] = schemeDictionary ["SOURCES-IN-DEV-DIR"]
    else:
      print (makefile.RED () + makefile.BOLD () + "Unknow scheme '" + SCHEME + "'" + makefile.ENDC ())
      sys.exit (1)
#--- CPU_MHZ
  CPU_MHZ = 0
  if "CPU-MHZ" in dictionaire:
    CPU_MHZ = dictionaire ["CPU-MHZ"]
#--- ASSERTION_GENERATION
  ASSERTION_GENERATION = False
  if "ASSERTION-GENERATION" in dictionaire :
    ASSERTION_GENERATION = dictionaire ["ASSERTION-GENERATION"]
#--- USER SOURCE_FILE_DIRECTORIES
  SOURCE_FILE_DIRECTORIES = []
  if "SOURCE-DIR" in dictionaire :
    SOURCE_FILE_DIRECTORIES = dictionaire ["SOURCE-DIR"]
#--- SYSTEM SOURCE_FILE_DIRECTORIES
  if "SOURCES-IN-DEV-DIR" in dictionaire :
    sourcesInDevDir = dictionaire ["SOURCES-IN-DEV-DIR"]
    for d in sourcesInDevDir :
      SOURCE_FILE_DIRECTORIES.append (TARGET_DIR + "/sources/" + d)
#--- GROUP_SOURCES
  GROUP_SOURCES = False
  if "GROUP-SOURCES" in dictionaire:
    GROUP_SOURCES = dictionaire ["GROUP-SOURCES"]
#--- TASK_COUNT
  TASK_COUNT = "0" # Means TASK_COUNT is not defined by JSON file
  if "TASK-COUNT" in dictionaire :
    TASK_COUNT = str (dictionaire ["TASK-COUNT"])
#--- LTO
  usesLTO = False
  if "LTO" in dictionaire :
    usesLTO = dictionaire ["LTO"]
#--- SERVICE
  serviceScheme = ""
  if "SERVICE-SCHEME" in dictionaire :
    serviceScheme = dictionaire ["SERVICE-SCHEME"]
#--- SECTION
  sectionScheme = ""
  if "SECTION-SCHEME" in dictionaire :
    sectionScheme = dictionaire ["SECTION-SCHEME"]
#--- IRQ SECTION
  irqSectionScheme = ""
  if "IRQ-SECTION-SCHEME" in dictionaire :
    irqSectionScheme = dictionaire ["IRQ-SECTION-SCHEME"]
#--- UNUSED IRQ
  unusedIRQScheme = ""
  if "UNUSED-IRQ-SCHEME" in dictionaire :
    unusedIRQScheme = dictionaire ["UNUSED-IRQ-SCHEME"]
#--- DEPLOYMENT
  selectedDeployments = []
  if "DEPLOYMENT" in dictionaire :
    selectedDeployments = dictionaire ["DEPLOYMENT"]
#--------------------------------------------------------------------------- Directories
  BUILD_DIR = common_definitions.buildDirectory ()
  GENERATED_SOURCE_DIR = common_definitions.generatedSourceDirectory ()
  PRODUCT_DIR = common_definitions.productDirectory ()
  ASBUILD_DIR = common_definitions.asDirectory ()
#--------------------------------------------------------------------------- Build source lists
  includeDirsInCompilerCommand = ["-I", GENERATED_SOURCE_DIR]
  H_SOURCE_SET = set ()
  H_SOURCE_LIST = []
  CPP_SOURCE_LIST = []
  S_SOURCE_LIST = []
  for f in SOURCE_FILE_DIRECTORIES :
    for root, dirs, files in os.walk (f) :
      includeDirsInCompilerCommand += ["-I", root]
      for name in files:
        sourcePath = os.path.join (root, name)
        (b, extension) = os.path.splitext (sourcePath)
        if extension == ".cpp" :
          CPP_SOURCE_LIST.append (sourcePath)
        elif extension == ".h" :
          H_SOURCE_LIST.append (sourcePath)
          if sourcePath in H_SOURCE_SET :
            print (makefile.BOLD_RED () + "Duplicated header file \"" + sourcePath + "\"" + makefile.ENDC ())
          H_SOURCE_SET.add (sourcePath)
        elif extension == ".s" :
          S_SOURCE_LIST.append (sourcePath)
        elif extension == ".hs" :
          pass # Ok
        elif extension == ".ld" :
          pass # Ok
        elif extension != "" : # Ceci permet d'ignorer les fichés cachés (dont les noms commencent par un point)
          print (makefile.MAGENTA () + makefile.BOLD () + "Note: unhandled file " + sourcePath + makefile.ENDC ())
#--------------------------------------------------------------------------- Build base header file
  baseHeader_file = GENERATED_SOURCE_DIR + "/base.h"
  H_SOURCE_LIST.insert (0, baseHeader_file)
  rule = makefile.Rule ([baseHeader_file], "Build base header file")
  rule.mOpenSourceOnError = False
  rule.mDependences.append ("makefile.json")
  rule.mCommand += [DEV_FILES_DIR + "/build_base_header_file.py", baseHeader_file, str (CPU_MHZ), TASK_COUNT, targetName, "1" if ASSERTION_GENERATION else "0"]
  rule.mPriority = -1
  make.addRule (rule)
#--------------------------------------------------------------------------- Build all header file
  allHeadersSecondaryDependenceFile = BUILD_DIR + "/all-headers.dep"
  allHeaders_file = GENERATED_SOURCE_DIR + "/all-headers.h"
  rule = makefile.Rule ([allHeaders_file, allHeadersSecondaryDependenceFile], "Build all headers file")
  rule.mOpenSourceOnError = False
  rule.mDependences.append ("makefile.json")
  rule.mDependences += H_SOURCE_LIST
  rule.mCommand += [DEV_FILES_DIR + "/build_all_header_file.py", allHeaders_file, allHeadersSecondaryDependenceFile]
  rule.mCommand += H_SOURCE_LIST
  rule.enterSecondaryDependanceFile (allHeadersSecondaryDependenceFile, make)
  rule.mPriority = -1
  make.addRule (rule)
#--------------------------------------------------------------------------- Build precompiled header file
#   allHeadersSecondaryDependenceFile = GENERATED_SOURCE_DIR + "/all-headers.h"
#   precompiledHeader_file = GENERATED_SOURCE_DIR + "/all-headers.h.gch"
#   rule = makefile.Rule ([precompiledHeader_file], "Build Precompiled header file")
#   rule.mOpenSourceOnError = False
#   rule.mDependences.append ("makefile.json")
#   rule.mDependences.append (allHeadersSecondaryDependenceFile)
#   rule.mCommand += COMPILER_TOOL_WITH_OPTIONS
#   rule.mCommand += ["-DSTATIC=static __attribute__((unused))"] if GROUP_SOURCES else ["-DSTATIC="]
#   rule.mCommand += common_definitions.checkModeOptions ()
#   rule.mCommand += common_definitions.C_Cpp_optimizationOptions ()
#   rule.mCommand += common_definitions.Cpp_actualOptions (False)
#   rule.mCommand += includeDirsInCompilerCommand
#   rule.mCommand += ["-x", "c++-header", allHeadersSecondaryDependenceFile]
#   rule.mCommand += ["-o", precompiledHeader_file]
#   rule.mPriority = -1
#   make.addRule (rule)
#   allGoal.append (precompiledHeader_file)
#--------------------------------------------------------------   --- Build interrupt handler files
  interruptHandlerSFile = GENERATED_SOURCE_DIR + "/interrupt-handlers-assembly.s"
  interruptHandlerCppFile = GENERATED_SOURCE_DIR + "/interrupt-handlers-cpp.cpp"
  S_SOURCE_LIST.append (interruptHandlerSFile)
  CPP_SOURCE_LIST.append (interruptHandlerCppFile)
  rule = makefile.Rule ([interruptHandlerSFile, interruptHandlerCppFile], "Build interrupt files")
  rule.mOpenSourceOnError = False
  rule.mDependences += H_SOURCE_LIST
  rule.mDependences.append ("makefile.json")
  rule.mDependences.append (DEV_FILES_DIR + "/build_interrupt_handlers.py")
  if serviceScheme != "" :
    rule.mDependences.append (TARGET_DIR + "/generators-service/" + serviceScheme + "/service_generator.py")
  if sectionScheme != "" :
    rule.mDependences.append (TARGET_DIR + "/generators-section/" + sectionScheme + "/section_generator.py")
  if irqSectionScheme != "" :
    rule.mDependences.append (TARGET_DIR + "/generators-irq-section/" + irqSectionScheme + "/irq_section_generator.py")
  if unusedIRQScheme != "" :
    rule.mDependences.append (TARGET_DIR + "/generators-unused-irq/" + unusedIRQScheme + "/unused_irq_generator.py")
  rule.mCommand += [DEV_FILES_DIR + "/build_interrupt_handlers.py"]
  rule.mCommand += [TARGET_DIR]
  rule.mCommand += [interruptHandlerCppFile]
  rule.mCommand += [interruptHandlerSFile]
  rule.mCommand += [serviceScheme]
  rule.mCommand += [sectionScheme]
  rule.mCommand += [irqSectionScheme]
  rule.mCommand += [unusedIRQScheme]
  rule.mCommand += H_SOURCE_LIST
  rule.mPriority = -1
  make.addRule (rule)
#--------------------------------------------------------------------------- Group sources ?
  if GROUP_SOURCES :
    allSourceFile = GENERATED_SOURCE_DIR + "/all-sources.cpp"
    rule = makefile.Rule ([allSourceFile], "Group all sources")
    rule.mOpenSourceOnError = False
    rule.mDependences += CPP_SOURCE_LIST
    rule.mDependences.append ("makefile.json")
    rule.mCommand += [DEV_FILES_DIR + "/build_grouped_sources.py", allSourceFile]
    rule.mCommand += CPP_SOURCE_LIST
    rule.mPriority = -1
    make.addRule (rule)
    CPP_SOURCE_LIST = [allSourceFile]
#--------------------------------------------------------------------------- Build makefile rules
  objectFileList = []
  asObjectFileList = []
#--- CPP source files
  for sourcePath in CPP_SOURCE_LIST :
    (goals, objectFiles, listingFiles) = addCppSourceFileToMakeFile (
      sourcePath,
      make,
      BUILD_DIR,
      allHeadersSecondaryDependenceFile,
      COMPILER_TOOL_WITH_OPTIONS,
      includeDirsInCompilerCommand,
      usesLTO,
      GROUP_SOURCES,
      allHeaders_file,
      ASBUILD_DIR,
      AS_TOOL_WITH_OPTIONS
    )
    allGoal += goals
    objectFileList += objectFiles
    asObjectFileList += listingFiles
#-- Add ARM S files
  for sourcePath in S_SOURCE_LIST :
    (objectFiles, listingFiles) = addAsSourceFileToMakeFile (
      sourcePath,
      make,
      BUILD_DIR,
      ASBUILD_DIR,
      AS_TOOL_WITH_OPTIONS,
      includeDirsInCompilerCommand
    )
    objectFileList += objectFiles
    asObjectFileList += listingFiles
#--------------------------------------------------------------------------- Enumerate deployments
  deploymentDictionary = deployment.deploymentDictionary ()
#--------------------------------------------------------------------- - Check selected deployments
  objectFileListDictionary = dict ()
  for selectedDeployment in selectedDeployments :
    objectFileListDictionary [selectedDeployment] = list (objectFileList)
    if not selectedDeployment in deploymentDictionary.keys () :
      s = "Invalid deployment \"" + selectedDeployment + "\"; possible values:\n"
      for dep in deploymentDictionary.keys () :
        s += "  - \"" + dep + "\"\n"
      print (makefile.BOLD_RED () + s + makefile.ENDC ())
      sys.exit (1)
#--------------------------------------------------------------- Additional source for deployement
  for selectedDeployment in selectedDeployments :
    additionalSourceDirectory = deployment.additionalSourceDirectoryForDeployment (selectedDeployment)
    if additionalSourceDirectory != "" :
      fullDirPath = TARGET_DIR + "/deployment/" + additionalSourceDirectory
      for name in sorted (os.listdir (fullDirPath)) :
        sourcePath = os.path.join (fullDirPath, name)
        (b, extension) = os.path.splitext (sourcePath)
        if extension == ".cpp" :
          (goals, objectFiles, listingFiles) = addCppSourceFileToMakeFile (
            sourcePath,
            make,
            BUILD_DIR,
            allHeadersSecondaryDependenceFile,
            COMPILER_TOOL_WITH_OPTIONS,
            includeDirsInCompilerCommand,
            usesLTO,
            GROUP_SOURCES,
            allHeaders_file,
            ASBUILD_DIR,
            AS_TOOL_WITH_OPTIONS
          )
          allGoal += goals
          objectFileListDictionary [selectedDeployment] += objectFiles
          asObjectFileList += listingFiles
        elif extension == ".s" :
          (objectFiles, listingFiles) = addAsSourceFileToMakeFile (
            sourcePath,
            make,
            BUILD_DIR,
            ASBUILD_DIR,
            AS_TOOL_WITH_OPTIONS,
            includeDirsInCompilerCommand
          )
          objectFileListDictionary [selectedDeployment] += objectFiles
          asObjectFileList += listingFiles
        elif extension != "" : # Ceci permet d'ignorer les fichés cachés (dont les noms commencent par un point)
          print (makefile.MAGENTA () + makefile.BOLD () + "Note: unhandled file " + sourcePath + makefile.ENDC ())

#--------------------------------------------------------------------------- Build deployment files
  runGoalDictionary = dict ()
  for selectedDeployment in selectedDeployments :
    runGoalDictionary ["run-" + selectedDeployment] = selectedDeployment
    linkerScript = deploymentDictionary [selectedDeployment]
    LINKER_SCRIPT = TARGET_DIR + "/deployment/" + linkerScript
    PRODUCT = PRODUCT_DIR + "/deployment-" + selectedDeployment
    allGoal.append (PRODUCT + ".elf")
  #--- Add link rule
    rule = makefile.Rule ([PRODUCT + ".elf"], "Linking " + PRODUCT + ".elf")
    rule.mDependences += objectFileListDictionary [selectedDeployment]
    rule.mDependences.append (LINKER_SCRIPT)
    rule.mDependences.append ("makefile.json")
    rule.mCommand += LD_TOOL_WITH_OPTIONS
    rule.mCommand += objectFileListDictionary [selectedDeployment]
    rule.mCommand += ["-T" + LINKER_SCRIPT]
    rule.mCommand.append ("-Wl,-Map=" + PRODUCT + ".map")
    rule.mCommand += common_definitions.commonLinkerFlags (usesLTO)
    rule.mCommand += ["-o", PRODUCT + ".elf"]
    make.addRule (rule)
    make.addGoal ("run-" + selectedDeployment, allGoal, "Building " + selectedDeployment + " deployment and run")
  #--- Add deployment rules
    (goal, rule) = deployment.buildDeployment (PRODUCT, selectedDeployment, verbose)
    allGoal.append (goal)
    make.addRule (rule)
#     sys.path.pop ()
  #--- Write deployment script
    pythonScriptFilePath = projectDir + "/2-run-" + selectedDeployment + "-via-usb.py"
    if not os.path.exists (pythonScriptFilePath) :
      f = open (DEV_FILES_DIR + "/deployment-script.py.txt", "r")
      genericScript = f.read ()
      f.close ()
      pythonScriptContents = genericScript.replace ("DEPLOYMENT", "run-" + selectedDeployment)
      f = open (pythonScriptFilePath, "wt")
      f.write (pythonScriptContents)
      f.close ()
      #---
      mode = os.stat (pythonScriptFilePath).st_mode
      # print (mode)
      mode += 0o0100 # Add execute permission
      # print (mode)
      os.chmod (pythonScriptFilePath, mode)
#--------------------------------------------------------------------------- Goals
  make.addGoal ("all", allGoal, "Build all")
  make.addGoal ("view-hex", allGoal, "Building all and show hex")
  make.addGoal ("display-obj-size", allGoal, "Build binaries and display object sizes")
  make.addGoal ("as", asObjectFileList, "Compile C and C++ to assembly")
#--------------------------------------------------------------------------- Run jobs
  #make.printRules ()
  #make.checkRules ()
#   make.writeRuleDependancesInDotFile ("dependances.dot")
  make.runGoal (maxConcurrentJobs, verbose)
#--------------------------------------------------------------------------- Ok ?
  make.printErrorCountAndExitOnError ()
#---------------------------------------------------------------------------- "display-obj-size"
  if GOAL == "display-obj-size" :
    makefile.runCommand (DISPLAY_OBJ_SIZE_TOOL + objectFileList + ["-t"], "Display Object Size", False, verbose)
#---------------------------------------------------------------------------- "All" or "run"
  if GOAL == "all" :
    for selectedDeployment in selectedDeployments :
      PRODUCT = PRODUCT_DIR + "/deployment-" + selectedDeployment
      s = runProcessAndGetOutput (DISPLAY_OBJ_SIZE_TOOL + ["-t"] + [PRODUCT + ".elf"])
      secondLine = s.split('\n')[1]
      numbers = [int(s) for s in secondLine.split() if s.isdigit()]
      print ("Deployment \"" + selectedDeployment + "\":")
      print ("  Code:             " + str (numbers [0]) + " bytes")
      print ("  Initialized data: " + str (numbers [1]) + " bytes")
      print ("  RAM + STACK:      " + str (numbers [2]) + " bytes")
#---------------------------------------------------------------------------- Run ?
  if GOAL in runGoalDictionary.keys () :
    selectedDeployment = runGoalDictionary [GOAL]
    PRODUCT = PRODUCT_DIR + "/deployment-" + selectedDeployment
    DEPLOYMENT_DIR = TARGET_DIR + "/deployment"
    deployment.performDeployment (DEPLOYMENT_DIR, PRODUCT, selectedDeployment)
Exemple #4
0
def buildCode(GOAL, projectDir, maxConcurrentJobs, showCommand):
    #--------------------------------------------------------------------------- Prepare
    os.chdir(projectDir)
    make = makefile.Make(GOAL)
    make.mMacTextEditor = "TextWrangler"  # "Atom"
    allGoal = []
    #--------------------------------------------------------------------------- Install Linux UDEV rules ?
    platform = dev_platform.getPlatform()
    if (platform == "linux") or (platform == "linux32"):
        import udev_on_linux
        udev_on_linux.installUDEVrulesOnLinux()
#--------------------------------------------------------------------------- Install compiler ?
    BASE_NAME = "arm-none-eabi"
    TOOL_DIR = download_and_install_gccarm.installGCCARMandGetToolDirectory()
    AS_TOOL_WITH_OPTIONS = [
        TOOL_DIR + "/bin/" + BASE_NAME + "-as", "-mthumb", "-mcpu=cortex-m4"
    ]
    COMPILER_TOOL_WITH_OPTIONS = [
        TOOL_DIR + "/bin/" + BASE_NAME + "-gcc", "-mthumb", "-mcpu=cortex-m4"
    ]
    LD_TOOL_WITH_OPTIONS = [TOOL_DIR + "/bin/" + BASE_NAME + "-ld"]
    LD_TOOL_WITH_OPTIONS = COMPILER_TOOL_WITH_OPTIONS
    OBJCOPY_TOOL_WITH_OPTIONS = [TOOL_DIR + "/bin/" + BASE_NAME + "-objcopy"]
    DISPLAY_OBJ_SIZE_TOOL = [TOOL_DIR + "/bin/" + BASE_NAME + "-size"]
    OBJDUMP_TOOL = TOOL_DIR + "/bin/" + BASE_NAME + "-objdump"
    #--------------------------------------------------------------------------- Install Teensy loader CLI ?
    TEENSY_CLI_LOADER_PATH = teensy_cli_loader_builder.buildAndGetPath(
        TOOL_DIR + "/bin")
    #--------------------------------------------------------------------------- Analyze JSON file
    print(makefile.BOLD_GREEN() + "--- Making " + projectDir + makefile.ENDC())
    dictionaire = dictionaryFromJsonFile(projectDir + "/makefile.json")
    #--- TEENSY
    linkerScript = "common-sources/teensy-3-6.ld"
    teensyName = "TEENSY36"
    #--- ASSERTION_GENERATION
    ASSERTION_GENERATION = False
    if ("ASSERTION-GENERATION"
            in dictionaire) and dictionaire["ASSERTION-GENERATION"]:
        ASSERTION_GENERATION = True
#--- CPU_MHZ
    CPU_MHZ = 0
    if "CPU-MHZ" in dictionaire:
        CPU_MHZ = dictionaire["CPU-MHZ"]
#--- SOURCE_FILE_DIRECTORIES
    SOURCE_FILE_DIRECTORIES = []
    if "SOURCE-DIR" in dictionaire:
        SOURCE_FILE_DIRECTORIES = dictionaire["SOURCE-DIR"]
#--- GROUP_SOURCES
    GROUP_SOURCES = False
    if "GROUP-SOURCES" in dictionaire:
        GROUP_SOURCES = dictionaire["GROUP-SOURCES"]
#--- TASK_COUNT
    TASK_COUNT = "0"  # Means TASK_COUNT is not defined by JSON file
    if "TASK-COUNT" in dictionaire:
        TASK_COUNT = str(dictionaire["TASK-COUNT"])
#--- LTO
    usesLTO = False
    if ("LTO" in dictionaire) and dictionaire["LTO"]:
        usesLTO = True
#--- SERVICE
    serviceScheme = ""
    if "SERVICE-SCHEME" in dictionaire:
        serviceScheme = dictionaire["SERVICE-SCHEME"]
#--- SECTION
    sectionScheme = ""
    if "SECTION-SCHEME" in dictionaire:
        sectionScheme = dictionaire["SECTION-SCHEME"]
#--------------------------------------------------------------------------- Directories
    BUILD_DIR = common_definitions.buildDirectory()
    GENERATED_SOURCE_DIR = common_definitions.generatedSourceDirectory()
    PRODUCT_DIR = common_definitions.productDirectory()
    ASBUILD_DIR = common_definitions.asDirectory()
    #--------------------------------------------------------------------------- Build source lists
    includeDirsInCompilerCommand = [
        "-I", GENERATED_SOURCE_DIR, "-I", projectDir
    ]
    H_SOURCE_LIST = []
    CPP_SOURCE_LIST = []
    S_SOURCE_LIST = []
    for f in SOURCE_FILE_DIRECTORIES:
        for root, dirs, files in os.walk(f):
            includeDirsInCompilerCommand += ["-I", root]
            for name in files:
                sourcePath = os.path.join(root, name)
                (b, extension) = os.path.splitext(sourcePath)
                if extension == ".cpp":
                    CPP_SOURCE_LIST.append(sourcePath)
                elif extension == ".h":
                    H_SOURCE_LIST.append(sourcePath)
                elif extension == ".s":
                    S_SOURCE_LIST.append(sourcePath)
                elif extension == ".ld":
                    pass  # Ignored file
                elif extension != "":  # Ceci permet d'ignorer les fichés cachés (dont les noms commencent par un point)
                    print(makefile.MAGENTA() + makefile.BOLD() +
                          "Note: unhandled file " + sourcePath +
                          makefile.ENDC())
#--------------------------------------------------------------------------- Build base header file
    baseHeader_file = GENERATED_SOURCE_DIR + "/base.h"
    H_SOURCE_LIST.insert(0, baseHeader_file)
    rule = makefile.Rule([baseHeader_file], "Build base header file")
    rule.mOpenSourceOnError = False
    rule.mDependences.append("makefile.json")
    rule.mCommand += [
        "python", "../../dev-files/build_base_header_file.py", baseHeader_file,
        str(CPU_MHZ), TASK_COUNT, teensyName,
        "1" if ASSERTION_GENERATION else "0"
    ]
    rule.mPriority = -1
    make.addRule(rule)
    #--------------------------------------------------------------------------- Build all header file
    allHeadersSecondaryDependenceFile = BUILD_DIR + "/all-headers.dep"
    allHeaders_file = GENERATED_SOURCE_DIR + "/all-headers.h"
    rule = makefile.Rule([allHeaders_file, allHeadersSecondaryDependenceFile],
                         "Build all headers file")
    rule.mOpenSourceOnError = False
    rule.mDependences.append("makefile.json")
    rule.mDependences += H_SOURCE_LIST
    rule.mCommand += [
        "python", "../../dev-files/build_all_header_file.py", allHeaders_file,
        allHeadersSecondaryDependenceFile
    ]
    rule.mCommand += H_SOURCE_LIST
    rule.enterSecondaryDependanceFile(allHeadersSecondaryDependenceFile, make)
    rule.mPriority = -1
    make.addRule(rule)
    #--------------------------------------------------------------------------- Build interrupt handler files
    interruptHandlerSFile = GENERATED_SOURCE_DIR + "/interrupt-handlers.s"
    interruptHandlerCppFile = GENERATED_SOURCE_DIR + "/interrupt-handler-helper.cpp"
    S_SOURCE_LIST.append(interruptHandlerSFile)
    CPP_SOURCE_LIST.append(interruptHandlerCppFile)
    rule = makefile.Rule([interruptHandlerSFile, interruptHandlerCppFile],
                         "Build interrupt files")
    rule.mOpenSourceOnError = False
    rule.mDependences += H_SOURCE_LIST
    rule.mDependences.append("makefile.json")
    rule.mDependences.append("../../dev-files/build_interrupt_handlers.py")
    rule.mCommand += ["python", "../../dev-files/build_interrupt_handlers.py"]
    rule.mCommand += [interruptHandlerCppFile]
    rule.mCommand += [interruptHandlerSFile]
    rule.mCommand += [serviceScheme]
    rule.mCommand += [sectionScheme]
    rule.mCommand += H_SOURCE_LIST
    rule.mPriority = -1
    make.addRule(rule)
    #--------------------------------------------------------------------------- Group sources ?
    if GROUP_SOURCES:
        allSourceFile = GENERATED_SOURCE_DIR + "/all-sources.cpp"
        rule = makefile.Rule([allSourceFile], "Group all sources")
        rule.mOpenSourceOnError = False
        rule.mDependences += CPP_SOURCE_LIST
        rule.mDependences.append("makefile.json")
        rule.mCommand += [
            "python", "../../dev-files/build_grouped_sources.py", allSourceFile
        ]
        rule.mCommand += CPP_SOURCE_LIST
        rule.mPriority = -1
        make.addRule(rule)
        CPP_SOURCE_LIST = [allSourceFile]
#--------------------------------------------------------------------------- Build makefile rules
    objectFileList = []
    asObjectFileList = []
    #--- CPP source files
    for sourcePath in CPP_SOURCE_LIST:
        source = os.path.basename(sourcePath)
        objectFile = BUILD_DIR + "/" + source + ".o"
        objectFileForChecking = BUILD_DIR + "/" + source + ".check.o"
        asObjectFile = BUILD_DIR + "/" + source + ".s"
        #--- Checking source
        rule = makefile.Rule([objectFileForChecking], "Checking " + source)
        rule.mOpenSourceOnError = False
        rule.mDependences.append(allHeaders_file)
        rule.mDependences.append(sourcePath)
        rule.mDependences.append("makefile.json")
        rule.enterSecondaryDependanceFile(objectFileForChecking + ".dep", make)
        rule.mCommand += COMPILER_TOOL_WITH_OPTIONS
        rule.mCommand += common_definitions.checkModeOptions()
        rule.mCommand += common_definitions.C_Cpp_optimizationOptions()
        rule.mCommand += common_definitions.Cpp_actualOptions(False)
        rule.mCommand += ["-c", sourcePath]
        rule.mCommand += ["-o", objectFileForChecking]
        rule.mCommand += ["-DSTATIC="]
        rule.mCommand += includeDirsInCompilerCommand
        rule.mCommand += ["-MD", "-MP", "-MF", objectFileForChecking + ".dep"]
        make.addRule(rule)
        rule.mPriority = -1
        allGoal.append(objectFileForChecking)
        #--- Compile source
        rule = makefile.Rule([objectFile], "Compiling " + source)
        rule.mOpenSourceOnError = False
        rule.mCommand += COMPILER_TOOL_WITH_OPTIONS
        rule.mCommand += common_definitions.C_Cpp_optimizationOptions()
        rule.mCommand += common_definitions.Cpp_actualOptions(usesLTO)
        rule.mCommand += ["-g"]
        rule.mCommand += ["-c", sourcePath]
        rule.mCommand += ["-o", objectFile]
        rule.mCommand += ["-DSTATIC=static __attribute__((unused))"
                          ] if GROUP_SOURCES else ["-DSTATIC="]
        rule.mCommand += includeDirsInCompilerCommand
        rule.mCommand += ["-MD", "-MP", "-MF", objectFile + ".dep"]
        rule.mDependences.append(allHeaders_file)
        rule.mDependences.append(sourcePath)
        rule.mDependences.append("makefile.json")
        rule.enterSecondaryDependanceFile(objectFile + ".dep", make)
        make.addRule(rule)
        objectFileList.append(objectFile)
        #--- objdump python source
        objdumpPythonFile = BUILD_DIR + "/" + source + ".objdump.py"
        rule = makefile.Rule([objdumpPythonFile],
                             "Building " + source + ".objdump.py")
        rule.mDependences.append(objectFile)
        rule.mDependences.append("makefile.json")
        rule.mCommand += [
            "python", "../../dev-files/build_objdump.py", OBJDUMP_TOOL, source,
            objdumpPythonFile
        ]
        rule.mPriority = -1
        make.addRule(rule)
        allGoal.append(objdumpPythonFile)
        #--- AS rule
        rule = makefile.Rule([asObjectFile], "Compiling -> s " + source)
        rule.mOpenSourceOnError = False
        rule.mCommand += COMPILER_TOOL_WITH_OPTIONS
        rule.mCommand += common_definitions.C_Cpp_optimizationOptions()
        rule.mCommand += common_definitions.Cpp_actualOptions(usesLTO)
        rule.mCommand += ["-S", sourcePath]
        rule.mCommand += ["-o", asObjectFile]
        rule.mCommand += ["-DSTATIC="]
        rule.mCommand += includeDirsInCompilerCommand
        rule.mCommand += ["-MD", "-MP", "-MF", asObjectFile + ".dep"]
        rule.mDependences.append(sourcePath)
        rule.mDependences.append(allHeaders_file)
        rule.mDependences.append("makefile.json")
        rule.enterSecondaryDependanceFile(asObjectFile + ".dep", make)
        make.addRule(rule)
        #--- AS rule, getting output assembler file
        listingFile = ASBUILD_DIR + "/" + source + ".s.list"
        rule = makefile.Rule([listingFile], "Assembling -> listing " + source)
        rule.mOpenSourceOnError = False
        rule.mCommand += AS_TOOL_WITH_OPTIONS
        rule.mCommand += [asObjectFile]
        rule.mCommand += ["-o", "/dev/null"]
        rule.mCommand += ["-aln=" + listingFile]
        rule.mDependences.append(asObjectFile)
        rule.mDependences.append(allHeaders_file)
        rule.mDependences.append("makefile.json")
        make.addRule(rule)
        asObjectFileList.append(listingFile)
#-- Add ARM S files
    for sourcePath in S_SOURCE_LIST:
        source = os.path.basename(sourcePath)
        objectFile = BUILD_DIR + "/" + source + ".o"
        objectFileForChecking = BUILD_DIR + "/" + source + ".check.o"
        asObjectFile = ASBUILD_DIR + "/" + source + ".s"
        if sourcePath != "":
            rule = makefile.Rule([objectFile], "Assembling " + source)
            rule.mOpenSourceOnError = False
            rule.mCommand += AS_TOOL_WITH_OPTIONS
            rule.mCommand += [sourcePath]
            rule.mCommand += ["-o", objectFile]
            rule.mCommand += includeDirsInCompilerCommand
            rule.mCommand += ["--MD", objectFile + ".dep"]
            rule.mDependences.append(sourcePath)
            rule.mDependences.append("makefile.json")
            rule.enterSecondaryDependanceFile(objectFile + ".dep", make)
            make.addRule(rule)
            objectFileList.append(objectFile)
            #--- Add listing file
            listingFile = ASBUILD_DIR + "/" + source + ".list"
            rule = makefile.Rule([listingFile],
                                 "Assembling -> listing " + source)
            rule.mOpenSourceOnError = False
            rule.mCommand += AS_TOOL_WITH_OPTIONS
            rule.mCommand += [sourcePath]
            rule.mCommand += ["-o", "/dev/null"]
            rule.mCommand += ["-aln=" + listingFile]
            rule.mDependences.append(sourcePath)
            rule.mDependences.append("makefile.json")
            make.addRule(rule)
            asObjectFileList.append(listingFile)
#--------------------------------------------------------------------------- Link for internal flash
    PRODUCT_INTERNAL_FLASH = PRODUCT_DIR + "/product"
    LINKER_SCRIPT_INTERNAL_FLASH = "../../dev-files/" + linkerScript
    allGoal.append(PRODUCT_INTERNAL_FLASH + ".elf")
    #--- Add link rule
    rule = makefile.Rule([PRODUCT_INTERNAL_FLASH + ".elf"],
                         "Linking " + PRODUCT_INTERNAL_FLASH + ".elf")
    rule.mDependences += objectFileList
    rule.mDependences.append(LINKER_SCRIPT_INTERNAL_FLASH)
    rule.mDependences.append("makefile.json")
    rule.mCommand += LD_TOOL_WITH_OPTIONS
    rule.mCommand += objectFileList
    rule.mCommand += ["-T" + LINKER_SCRIPT_INTERNAL_FLASH]
    rule.mCommand.append("-Wl,-Map=" + PRODUCT_INTERNAL_FLASH + ".map")
    rule.mCommand += common_definitions.commonLinkerFlags(usesLTO)
    rule.mCommand += ["-o", PRODUCT_INTERNAL_FLASH + ".elf"]
    make.addRule(rule)
    #--- Add hex rule
    allGoal.append(PRODUCT_INTERNAL_FLASH + ".hex")
    rule = makefile.Rule([PRODUCT_INTERNAL_FLASH + ".hex"],
                         "Hexing " + PRODUCT_INTERNAL_FLASH + ".hex")
    rule.mDependences.append(PRODUCT_INTERNAL_FLASH + ".elf")
    rule.mDependences.append("makefile.json")
    rule.mCommand += OBJCOPY_TOOL_WITH_OPTIONS
    rule.mCommand.append("-O")
    rule.mCommand.append("ihex")
    rule.mCommand.append(PRODUCT_INTERNAL_FLASH + ".elf")
    rule.mCommand.append(PRODUCT_INTERNAL_FLASH + ".hex")
    make.addRule(rule)
    #--------------------------------------------------------------------------- Goals
    make.addGoal("all", allGoal, "Build all")
    make.addGoal("run", allGoal, "Building all and run")
    make.addGoal("view-hex", allGoal, "Building all and show hex")
    make.addGoal("display-obj-size", allGoal,
                 "Build binaries and display object sizes")
    make.addGoal("as", asObjectFileList, "Compile C and C++ to assembly")
    #--------------------------------------------------------------------------- Run jobs
    #make.printRules ()
    #make.checkRules ()
    #   make.writeRuleDependancesInDotFile ("dependances.dot")
    make.runGoal(maxConcurrentJobs, showCommand)
    #--------------------------------------------------------------------------- Ok ?
    make.printErrorCountAndExitOnError()
    #---------------------------------------------------------------------------- "display-obj-size"
    if GOAL == "display-obj-size":
        makefile.runCommand(DISPLAY_OBJ_SIZE_TOOL + objectFileList + ["-t"],
                            "Display Object Size", False, showCommand)
#---------------------------------------------------------------------------- "All" or "run"
    if (GOAL == "all") or (GOAL == "run") or (GOAL == "view-hex"):
        s = runProcessAndGetOutput(DISPLAY_OBJ_SIZE_TOOL + ["-t"] +
                                   [PRODUCT_INTERNAL_FLASH + ".elf"])
        secondLine = s.split('\n')[1]
        numbers = [int(s) for s in secondLine.split() if s.isdigit()]
        print("  ROM code:    " + str(numbers[0]) + " bytes")
        print("  ROM data:    " + str(numbers[1]) + " bytes")
        print("  RAM + STACK: " + str(numbers[2]) + " bytes")
#----------------------------------------------- Run ?
    if GOAL == "run":
        FLASH_TEENSY = [TEENSY_CLI_LOADER_PATH, "-w", "-v", "-mmcu=TEENSY36"]
        print(makefile.BOLD_BLUE() + "Loading Teensy..." + makefile.ENDC())
        runProcess(FLASH_TEENSY + [PRODUCT_INTERNAL_FLASH + ".hex"])
        print(makefile.BOLD_GREEN() + "Success" + makefile.ENDC())
    elif GOAL == "view-hex":
        print(makefile.BOLD_GREEN() + "View hex..." + makefile.ENDC())
        scriptDir = os.path.dirname(os.path.abspath(__file__))
        runProcess([
            "python", scriptDir + "/view-hex.py",
            PRODUCT_INTERNAL_FLASH + ".hex"
        ])
Exemple #5
0
sys.path.append('../../../python-makefile')
import makefile

#--- Change dir to script absolute path
scriptDir = os.path.dirname (os.path.abspath (sys.argv[0]))
os.chdir (scriptDir)
#--- Get goal as first argument
goal = "all"
if len (sys.argv) > 1 :
  goal = sys.argv [1]
#--- 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])
#--- Build python makefile
make = makefile.Make (goal, maxParallelJobs == 1) # Display executable if sequential build
# make.mMacTextEditor = "Atom"
sourceList = [
    "dom.cpp",
    "../../src/TrackSet.cpp",
    "../../src/Track.cpp",
    "../../src/PathSet.cpp",
    "../../src/HeadedTrackSet.cpp",
    "../../unix/Arduino.cpp",
    "../../unix/HardwareSerial.cpp"
]
objectList = []
for source in sourceList:
#--- Add compile rules
  src = os.path.basename(os.path.dirname(source)) + "/" + os.path.basename(source)
  object = "objects/" + src + ".o"