Skip to content

Instantly share code, notes, and snippets.

@leidegre
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leidegre/3d11e16a7565083b8a47 to your computer and use it in GitHub Desktop.
Save leidegre/3d11e16a7565083b8a47 to your computer and use it in GitHub Desktop.
void Dummy()
{
// so that we have at least one object file
}
#include <cstdio>
extern const char* g_Text;
int main(int argc, const char* argv[])
{
printf("%s\n", g_Text);
return 0;
}
#include <cassert>
#include <cstdio>
#include <cctype>
#include <cstring>
int main(int argc, const char* argv[])
{
assert(3 <= argc);
FILE* f = fopen(argv[2], "rb");
if (!f)
{
return 1;
}
char temp[512];
size_t read = fread(temp, 1, sizeof(temp), f);
temp[read] = 0;
char output_file[256];
strcpy(output_file, argv[1]);
strcat(output_file, "\\");
strcat(output_file, strrchr(argv[2], '\\') + 1);
strcat(output_file, ".cpp");
FILE* f2 = fopen(output_file, "w+b");
if (!f2)
{
fclose(f);
return 1;
}
char* p = temp;
while (*p)
{
if (!isalnum(*p))
*p = '.';
++p;
}
fprintf(f2, "const char* g_Text = \"%s\";\n", temp);
fclose(f2);
fclose(f);
return 0;
}
This is some text.
Build {
Passes = {
A = { Name = "A", BuildOrder = 1 },
B = { Name = "B", BuildOrder = 2 },
},
Units = function()
local path = require "tundra.path"
Program {
Name = "strc",
Pass = "A",
Sources = {
"Strc.cpp",
},
}
Always "strc"
DefRule {
Name = "Strc",
Pass = "B",
ConfigInvariant = false,
Command = "$(OBJECTDIR)$(SEP)strc$(PROGSUFFIX) $(OBJECTDIR) $(<)",
ImplicitInputs = { "$(OBJECTDIR)$(SEP)strc$(PROGSUFFIX)" },
Blueprint = {
InputFiles = { Type = "table", Required = true },
},
Setup = function (env, data)
local ouput_files = {}
for _, v in ipairs(data.InputFiles) do
local output_file = "$(OBJECTDIR)/" .. path.get_filename(v) .. ".cpp"
ouput_files[#ouput_files] = output_file
print("stc: " .. output_file)
end
return {
InputFiles = data.InputFiles,
OutputFiles = ouput_files,
}
end
}
StaticLibrary {
Name = "textlib",
Sources = {
"Dummy.cpp",
Strc {
InputFiles = "Text.txt",
}
}
}
Program {
Name = "text",
Depends = { "textlib" },
Sources = {
"Main.cpp",
}
}
end,
Configs = {
Config {
Name = "win64-msvc",
SupportedHosts = { "windows" },
DefaultOnHost = "windows",
Tools = { { "msvc-vs2013"; TargetArch = "x64"; } },
Env = {
GENERATE_PDB = "1",
CXXOPTS = { "/FC" }
}
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment