Skip to content
This repository
tree: 20f416d9d8
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 120 lines (99 sloc) 3.204 kb
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
/*
* Copyright 2010, 2011, 2012 Vladimir Panteleev <vladimir@thecybershadow.net>
* This file is part of RABCDAsm.
*
* RABCDAsm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RABCDAsm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RABCDAsm. If not, see <http://www.gnu.org/licenses/>.
*/

/// A simple tool to build RABCDAsm in one command.
/// You can use the DC and DCFLAGS environment variables to override the detected compiler and compilation flags.

module build_rabcdasm;

version(D_Version2)
{ /* All OK */ }
else
static assert(false, "Unsupported D version.\nThis software requires a D2 ( http://dlang.org/ ) compiler to build.");

version(D_Version2):

version(DigitalMars)
const DEFAULT_COMPILER = "dmd";
else
const DEFAULT_COMPILER = "gdmd";

const DEFAULT_FLAGS = "-O -inline";
const LZMA_FLAGS = "-version=HAVE_LZMA";

import std.exception;
import std.file;
import std.process;
import std.stdio;
import std.string;

string compiler, flags;

void compile(string program)
{
stderr.writeln("* Building ", program);
enforce(system(format("rdmd --build-only --compiler=%s %s %s", compiler, flags, program)) == 0, "Compilation of " ~ program ~ " failed");
}

void test(string code, string extraFlags=null)
{
const FN = "test.d";
std.file.write(FN, code);
scope(exit) remove(FN);
enforce(system(format("rdmd --compiler=%s %s %s %s", compiler, flags, extraFlags, FN)) == 0, "Test failed");
stderr.writeln(" >>> OK");
}

int main()
{
try
{
compiler = getenv("DC");
if (compiler is null)
compiler = DEFAULT_COMPILER;

flags = getenv("DCFLAGS");
if (flags is null)
flags = DEFAULT_FLAGS;

stderr.writeln("* Checking for working compiler...");
test(`
void main() {}
`);

bool haveLZMA;

stderr.writeln("* Checking for LZMA...");
try
{
test(`
import lzma, std.exception;
void main()
{
LZMAHeader header;
auto data = cast(immutable(ubyte)[])"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
auto cdata = lzmaCompress(data, &header);
header.decompressedSize = data.length;
auto ddata = lzmaDecompress(header, cdata);
enforce(data == ddata);
}
`, LZMA_FLAGS);

// Test succeeded
haveLZMA = true;
}
catch (Exception e)
stderr.writeln(" >>> LZMA not found, building without LZMA support.");

if (haveLZMA)
flags ~= " " ~ LZMA_FLAGS;

foreach (program; ["rabcasm", "rabcdasm", "abcexport", "abcreplace", "swfbinexport", "swfbinreplace", "swfdecompress", "swf7zcompress"])
compile(program);

if (haveLZMA)
compile("swflzmacompress");

return 0;
}
catch (Exception e)
{
stderr.writeln("Error: ", e.msg);
return 1;
}
}
Something went wrong with that request. Please try again.