forked from pierremolinaro/python-makefile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·67 lines (65 loc) · 2.24 KB
/
build.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, os
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 = "TextWrangler"
#--- Add C files compile rule
sourceList = ["main.c", "myRoutine.c"]
objectList = []
for source in sourceList:
#--- Add compile rules
object = "objects/" + source + ".o"
depObject = object + ".dep"
objectList.append (object)
rule = makefile.Rule ([object], "Compiling " + source) # Release 2
rule.deleteTargetDirectoryOnClean ()
rule.mDependences.append (source)
rule.mCommand.append ("gcc")
rule.mCommand += ["-c", source]
rule.mCommand += ["-o", object]
rule.mCommand += ["-MD", "-MP", "-MF", depObject]
rule.enterSecondaryDependanceFile (depObject, make)
rule.mPriority = os.path.getsize (scriptDir + "/" + source)
rule.mOpenSourceOnError = True
make.addRule (rule)
#--- Add linker rule
product = "myRoutine"
mapFile = product + ".map"
rule = makefile.Rule ([product, mapFile], "Linking " + product) # Release 2
rule.mDeleteTargetOnError = True
rule.deleteTargetFileOnClean ()
rule.mDependences += objectList
rule.mCommand += ["gcc"]
rule.mCommand += objectList
rule.mCommand += ["-o", product]
rule.mCommand += ["-Wl,-map," + mapFile]
postCommand = makefile.PostCommand ("Stripping " + product)
postCommand.mCommand += ["strip", "-A", "-n", "-r", "-u", product]
rule.mPostCommands.append (postCommand)
make.addRule (rule)
#--- Print rules
# make.printRules ()
# make.writeRuleDependancesInDotFile ("make-deps.dot")
make.checkRules ()
#--- Add goals
make.addGoal ("all", [product, mapFile], "Building all")
make.addGoal ("compile", objectList, "Compile C files")
#make.simulateClean ()
#make.printGoals ()
#make.doNotShowProgressString ()
make.runGoal (maxParallelJobs, maxParallelJobs == 1)
#--- Build Ok ?
make.printErrorCountAndExitOnError ()