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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
<%
local csc = premake.csc
--
-- Given a .resx resource file, builds the path to corresponding .resource
-- file, matching the behavior and naming of Visual Studio.
--
function getresourcefilename(cfg, fname)
if path.getextension(fname) == ".resx" then
local name = cfg.buildtarget.basename .. "."
local dir = path.getdirectory(fname)
if dir ~= "." then
name = name .. path.translate(dir, ".") .. "."
end
return "$(OBJDIR)/" .. name .. path.getbasename(fname) .. ".resources"
else
return fname
end
end
-- Do some processing up front: build a list of configuration-dependent libraries.
-- Libraries that are built to a location other than $(TARGETDIR) will need to
-- be copied so they can be found at runtime.
local cfglibs = { }
local cfgpairs = { }
local anycfg
for cfg in premake.eachconfig(this) do
anycfg = cfg
cfglibs[cfg] = premake.getlinks(cfg, "siblings", "fullpath")
cfgpairs[cfg] = { }
for _, fname in ipairs(cfglibs[cfg]) do
if path.getdirectory(fname) ~= cfg.buildtarget.directory then
cfgpairs[cfg]["$(TARGETDIR)/"..path.getname(fname)] = fname
end
end
end
-- sort the files into categories, based on their build action
local sources = {}
local embedded = { }
local copypairs = { }
for fcfg in premake.eachfile(this) do
local action = csc.getbuildaction(fcfg)
if action == "Compile" then
table.insert(sources, fcfg.name)
elseif action == "EmbeddedResource" then
table.insert(embedded, fcfg.name)
elseif action == "Content" then
copypairs["$(TARGETDIR)/"..path.getname(fcfg.name)] = fcfg.name
elseif path.getname(fcfg.name):lower() == "app.config" then
copypairs["$(TARGET).config"] = fcfg.name
end
end
-- Any assemblies that are on the library search paths should be copied
-- to $(TARGETDIR) so they can be found at runtime
local paths = table.translate(this.libdirs, function(v) return path.join(this.basedir, v) end)
paths = table.join({this.basedir}, paths)
for _, libname in ipairs(premake.getlinks(this, "system", "fullpath")) do
local libdir = os.pathsearch(libname..".dll", unpack(paths))
if (libdir) then
local target = "$(TARGETDIR)/"..path.getname(libname)
local source = path.getrelative(this.basedir, path.join(libdir, libname))..".dll"
copypairs[target] = source
end
end
-- end of preprocessing --
%>
# <%= premake.actions[_ACTION].shortname %> project makefile autogenerated by Premake
ifndef config
config=<%= _MAKE.esc(this.configurations[1]:lower()) %>
endif
ifndef verbose
SILENT = @
endif
ifndef CSC
CSC=<%= csc.getcompilervar(this) %>
endif
ifndef RESGEN
RESGEN=resgen
endif
<% for cfg in premake.eachconfig(this) do %>
ifeq ($(config),<%= _MAKE.esc(cfg.name:lower())%>)
TARGETDIR := <%= _MAKE.esc(cfg.buildtarget.directory) %>
OBJDIR := <%= _MAKE.esc(cfg.objectsdir) %>
DEPENDS := <%= table.concat(_MAKE.esc(premake.getlinks(cfg, "dependencies", "fullpath")), " ") %>
REFERENCES := <%= table.implode(_MAKE.esc(cfglibs[cfg]), "/r:", "", " ") %>
FLAGS += <%= table.concat(csc.getflags(cfg), " ") %> <%= table.implode(cfg.defines, "/d:", "", " ") %>
define PREBUILDCMDS
<% if #cfg.prebuildcommands > 0 then %>
@echo Running pre-build commands
<%= table.implode(cfg.prebuildcommands, "", "", "\n\t") %>
<% end %>
endef
define PRELINKCMDS
<% if #cfg.prelinkcommands > 0 then %>
@echo Running pre-link commands
<%= table.implode(cfg.prelinkcommands, "", "", "\n\t") %>
<% end %>
endef
define POSTBUILDCMDS
<% if #cfg.postbuildcommands > 0 then %>
@echo Running post-build commands
<%= table.implode(cfg.postbuildcommands, "", "", "\n\t") %>
<% end %>
endef
endif
<% end %>
# To maintain compatibility with VS.NET, these values must be set at the project level
TARGET = $(TARGETDIR)/<%= _MAKE.esc(this.buildtarget.name) %>
FLAGS += /t:<%= csc.getkind(this):lower() %> <%= table.implode(_MAKE.esc(this.libdirs), "/lib:", "", " ") %>
REFERENCES += <%= table.implode(_MAKE.esc(premake.getlinks(this, "system", "basename")), "/r:", ".dll", " ") %>
SOURCES := \
<% for _, fname in ipairs(sources) do %>
<%= _MAKE.esc(path.translate(fname)) %> \
<% end %>
EMBEDFILES := \
<% for _, fname in ipairs(embedded) do %>
<%= _MAKE.esc(getresourcefilename(this, fname)) %> \
<% end %>
COPYFILES += \
<% for target, source in pairs(cfgpairs[anycfg]) do %>
<%= _MAKE.esc(target) %> \
<% end %>
<% for target, source in pairs(copypairs) do %>
<%= _MAKE.esc(target) %> \
<% end %>
SHELLTYPE := msdos
ifeq (,$(ComSpec)$(COMSPEC))
SHELLTYPE := posix
endif
ifeq (/bin,$(findstring /bin,$(SHELL)))
SHELLTYPE := posix
endif
ifeq (posix,$(SHELLTYPE))
define MKDIR_RULE
@echo Creating $@
$(SILENT) mkdir -p $@
endef
define COPY_RULE
@echo Copying $(notdir $@)
$(SILENT) cp -fR $^ $@
endef
else
define MKDIR_RULE
@echo Creating $@
$(SILENT) mkdir $(subst /,\\,$@)
endef
define COPY_RULE
@echo Copying $(notdir $@)
$(SILENT) copy /Y $(subst /,\\,$^) $(subst /,\\,$@)
endef
endif
.PHONY: clean prebuild prelink
all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)
$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS)
$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) $(SOURCES) $(patsubst %,/resource:%,$(EMBEDFILES))
$(POSTBUILDCMDS)
$(TARGETDIR):
$(MKDIR_RULE)
$(OBJDIR):
$(MKDIR_RULE)
clean:
@echo Cleaning <%= this.name %>
ifeq (posix,$(SHELLTYPE))
$(SILENT) rm -f $(TARGETDIR)/<%= this.buildtarget.basename %>.* $(COPYFILES)
$(SILENT) rm -rf $(OBJDIR)
else
$(SILENT) if exist $(subst /,\\,$(TARGETDIR)/<%= this.buildtarget.basename %>.*) del $(subst /,\\,$(TARGETDIR)/<%= this.buildtarget.basename %>.*)
<% for target, source in pairs(cfgpairs[anycfg]) do %>
$(SILENT) if exist $(subst /,\\,<%= target %>) del $(subst /,\\,<%= target %>)
<% end %>
<% for target, source in pairs(copypairs) do %>
$(SILENT) if exist $(subst /,\\,<%= target %>) del $(subst /,\\,<%= target %>)
<% end %>
$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
endif
prebuild:
$(PREBUILDCMDS)
prelink:
$(PRELINKCMDS)
# Per-configuration copied file rules
<% for cfg in premake.eachconfig(this) do %>
ifeq ($(config),<%= _MAKE.esc(cfg.name:lower())%>)
<% for target, source in pairs(cfgpairs[cfg]) do %>
<%= _MAKE.esc(target) %>: <%= _MAKE.esc(source) %>
$(COPY_RULE)
<% end %>
endif
<% end %>
# Copied file rules
<% for target, source in pairs(copypairs) do %>
<%= _MAKE.esc(target) %>: <%= _MAKE.esc(source) %>
$(COPY_RULE)
<% end %>
# Embedded file rules
<% for _, fname in ipairs(embedded) do if path.getextension(fname) == ".resx" then %>
<%= _MAKE.esc(getresourcefilename(this, fname)) %>: <%= _MAKE.esc(fname) %>
$(SILENT) $(RESGEN) $^ $@
<% end end %>
|