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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
--
-- _premake_main.lua
-- Script-side entry point for the main program logic.
-- Copyright (c) 2002-2008 Jason Perkins and the Premake project
--
local scriptfile = "premake4.lua"
local shorthelp = "Type 'premake4 --help' for help"
local versionhelp = "premake4 (Premake Build Script Generator) %s"
--
-- Fire a particular action. Generates the output files from the templates
-- listed in the action descriptor, and calls any registered handler functions.
--
local function doaction(name)
local action = premake.actions[name]
-- walk the session objects and generate files from the templates
local function generatefiles(this, templates)
if (not templates) then return end
for _,tmpl in ipairs(templates) do
local output = true
if (tmpl[3]) then
output = tmpl[3](this)
end
if (output) then
local fname = path.getrelative(os.getcwd(), premake.getoutputname(this, tmpl[1]))
printf("Generating %s...", fname)
local f, err = io.open(fname, "wb")
if (not f) then
error(err, 0)
end
io.output(f)
-- call the template function to generate the output
tmpl[2](this)
io.output():close()
end
end
end
for _,sln in ipairs(_SOLUTIONS) do
generatefiles(sln, action.solutiontemplates)
for prj in premake.eachproject(sln) do
generatefiles(prj, action.projecttemplates)
end
end
if (action.execute) then
action.execute()
end
end
--
-- Inject a new target platform into each solution; called if the --platform
-- argument was specified on the command line.
--
local function injectplatform(platform)
if not platform then return true end
platform = premake.checkvalue(platform, premake.fields.platforms.allowed)
for _, sln in ipairs(_SOLUTIONS) do
local platforms = sln.platforms or { }
-- an empty table is equivalent to a native build
if #platforms == 0 then
table.insert(platforms, "Native")
end
-- the solution must provide a native build in order to support this feature
if not table.contains(platforms, "Native") then
return false, sln.name .. " does not target native platform\nNative platform settings are required for the --platform feature."
end
-- add it to the end of the list, if it isn't in there already
if not table.contains(platforms, platform) then
table.insert(platforms, platform)
end
sln.platforms = platforms
end
return true
end
--
-- Script-side program entry point.
--
function _premake_main(scriptpath)
-- if running off the disk (in debug mode), load everything
-- listed in _manifest.lua; the list divisions make sure
-- everything gets initialized in the proper order.
if (scriptpath) then
local scripts = dofile(scriptpath .. "/_manifest.lua")
for _,v in ipairs(scripts) do
dofile(scriptpath .. "/" .. v)
end
end
-- If there is a project script available, run it to get the
-- project information, available options and actions, etc.
local fname = _OPTIONS["file"] or scriptfile
if (os.isfile(fname)) then
dofile(fname)
end
-- Process special options
if (_OPTIONS["version"]) then
printf(versionhelp, _PREMAKE_VERSION)
return 1
end
if (_OPTIONS["help"]) then
premake.showhelp()
return 1
end
-- If no action was specified, show a short help message
if (not _ACTION) then
print(shorthelp)
return 1
end
-- If there wasn't a project script I've got to bail now
if (not os.isfile(fname)) then
error("No Premake script ("..scriptfile..") found!", 2)
end
-- Validate the command-line arguments. This has to happen after the
-- script has run to allow for project-specific options
if (not premake.actions[_ACTION]) then
error("Error: no such action '".._ACTION.."'", 0)
end
ok, err = premake.checkoptions()
if (not ok) then error("Error: " .. err, 0) end
-- Sanity check the current project setup
ok, err = premake.checktools()
if (not ok) then error("Error: " .. err, 0) end
-- If a platform was specified on the command line, inject it now
ok, err = injectplatform(_OPTIONS["platform"])
if (not ok) then error("Error: " .. err, 0) end
-- work-in-progress: build the configurations
print("Building configurations...")
premake.buildconfigs()
ok, err = premake.checkprojects()
if (not ok) then error("Error: " .. err, 0) end
-- Hand over control to the action
printf("Running action '%s'...", _ACTION)
doaction(_ACTION)
print("Done.")
return 0
end
|