Created
August 13, 2010 21:33
-
-
Save wess/523574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dirent.h> | |
#include <string> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <iostream> | |
#include <fstream> | |
#include <v8.h> | |
using namespace std; | |
using namespace v8; | |
extern Handle<Context> baseContext_; | |
namespace Conf | |
{ | |
bool _isVerbose; | |
struct buildSet | |
{ | |
Handle<String> compiler; | |
char* includes[]; | |
char* libs[]; | |
char* flags[]; | |
char* src[]; | |
Handle <String> target; | |
}; | |
buildSet build; | |
bool isThere(const char* path) | |
{ | |
struct stat sInfo; | |
int res = stat(path, &sInfo); | |
return (res != -1); | |
} | |
Handle<Value> Compiler(const Arguments &args) | |
{ | |
HandleScope scope; | |
if(args[0]->IsUndefined()) | |
return ThrowException(String::New("No compiler given")); | |
build.compiler = args[0]->ToString(); | |
String::Utf8Value cmd(build.compiler); | |
char* cmdCat = new char[10]; | |
strcpy(cmdCat, "/usr/bin/"); | |
strcpy(cmdCat, *cmd); | |
strcat(cmdCat, " -v 1>&- 2>&-"); | |
if(!system(cmdCat)) | |
{ | |
printf("\n"); | |
printf("\033[22;32mChecking for compiler...\033[01;37mYes"); | |
} | |
else | |
{ | |
printf("\n"); | |
printf("\033[22;32mChecking for compiler...\033[22;31mFailed!"); | |
printf("\n"); | |
printf("\033[0m"); | |
exit(1); | |
} | |
return Undefined(); | |
} | |
Handle<Value> Includes(const Arguments &args) | |
{ | |
HandleScope scope; | |
printf("\n"); | |
printf("\033[22;32mChecking Includes"); | |
if(args[0]->IsUndefined()) | |
return ThrowException(String::New("Includes requires an array of paths")); | |
Handle<Array> incs = args[0].As<Array>(); | |
for(int i=0; i < (int)incs->Length(); i++) | |
{ | |
String::Utf8Value cPath(incs->Get(i)->ToString()); | |
if(isThere(*cPath)) | |
{ | |
printf("\n\t"); | |
printf("\033[22;32mChecking for %s...\033[01;37mYes", *cPath); | |
build.includes[i] = *cPath; | |
} | |
else | |
{ | |
printf("\n\t"); | |
printf("\033[22;32mChecking for %s...\033[22;31mFailed!", *cPath); | |
printf("\n"); | |
printf("\033[0m"); | |
exit(1); | |
} | |
} | |
return Undefined(); | |
} | |
Handle<Value> Libs(const Arguments &args) | |
{ | |
HandleScope scope; | |
printf("\n"); | |
printf("\033[22;32mChecking Libs"); | |
if(args[0]->IsUndefined()) | |
return ThrowException(String::New("Includes requires an array of libs include path to said lib")); | |
Handle<Array> libs = args[0].As<Array>(); | |
for(int i=0; i < (int)libs->Length(); i++) | |
{ | |
String::Utf8Value lPath(libs->Get(i)->ToString()); | |
if(isThere(*lPath)) | |
{ | |
printf("\n\t"); | |
printf("\033[22;32mChecking for %s...\033[01;37mYes", *lPath); | |
build.libs[i] = *lPath; | |
} | |
else | |
{ | |
printf("\n\t"); | |
printf("\033[22;32mChecking for %s...\033[22;31mFailed!", *lPath); | |
printf("\n"); | |
printf("\033[0m"); | |
exit(1); | |
} | |
} | |
return Undefined(); | |
} | |
Handle<Value> Flags(const Arguments &args) | |
{ | |
printf("\n"); | |
printf("\033[22;32mChecking Flags"); | |
/* | |
if(args[0]->IsUndefined()) | |
{ | |
Handle<Array> flags = Array::New(); | |
for(int i=0; i < strlen(build.flags); i++) | |
includes->Set(Integer::New(i), String::New(build.flags[i])); | |
return flags; | |
} | |
else | |
{ | |
Handle<Array> flags(argsp[0]->ToArray()); | |
for(int i=0; i < flags.Length(); i++) | |
build.includes[i] = (char *)flags->Get(Integer::New(i)); | |
} | |
*/ | |
return Undefined(); | |
} | |
Handle<Value> Src(const Arguments &args) | |
{ | |
HandleScope scope; | |
printf("\n"); | |
printf("\033[22;32mChecking Source files"); | |
if(args[0]->IsUndefined()) | |
return ThrowException(String::New("Includes requires an array of source files with path")); | |
Handle<Array> srcs = args[0].As<Array>(); | |
for(int i=0; i < (int)srcs->Length(); i++) | |
{ | |
String::Utf8Value zpath(srcs->Get(i)->ToString()); | |
if(isThere(*zpath)) | |
{ | |
printf("\n\t"); | |
printf("\033[22;32mChecking for %s...\033[01;37mYes", *zpath); | |
build.src[i] = *zpath; | |
} | |
else | |
{ | |
printf("\n\t"); | |
printf("\033[22;32mChecking for %s...\033[22;31mFailed!", *zpath); | |
printf("\n"); | |
printf("\033[0m"); | |
exit(1); | |
} | |
} | |
return Undefined(); | |
} | |
Handle<Value> Target(const Arguments &args) | |
{ | |
printf("\n"); | |
printf("\033[22;32mSetting Target"); | |
/* | |
if(args[0]->IsUndefined()) | |
return build.target; | |
else | |
build.target = args[0]->ToString(); | |
*/ | |
return Undefined(); | |
} | |
Handle<Value> Run(const Arguments &args) | |
{ | |
printf("\n"); | |
printf("\033[22;32mRunning"); | |
printf("\n"); | |
printf("\033[0m"); | |
return Undefined(); | |
} | |
Handle<Value> Verbose(const Arguments &args) | |
{ | |
printf("\n"); | |
printf("\033[22;32mSet Verbose"); | |
//_isVerbose = args[0]->ToBoolean(); | |
return Undefined(); | |
} | |
Handle<Value> Check(const Arguments &args) | |
{ | |
printf("\n"); | |
printf("\033[22;32m Checking"); | |
return Undefined(); | |
//String::Utf8Value cmd(args[0]->ToString()); | |
//return (!system(*cmd)) True() : False(); | |
} | |
Handle<Value> ConfigureNew(const Arguments &args) | |
{ | |
return args.This(); | |
} | |
} | |
/** Expose Class to js **/ | |
void ConfigureInit(Handle<ObjectTemplate> &global) | |
{ | |
HandleScope scope; | |
Handle<FunctionTemplate> tpl = FunctionTemplate::New(Conf::ConfigureNew); | |
tpl->SetClassName(String::New("Configure")); | |
Handle<ObjectTemplate> objTpl = tpl->InstanceTemplate(); | |
objTpl->SetInternalFieldCount(2); | |
Handle<ObjectTemplate> protoTpl = tpl->PrototypeTemplate(); | |
protoTpl->Set("compiler", FunctionTemplate::New(Conf::Compiler)); | |
protoTpl->Set("includes", FunctionTemplate::New(Conf::Includes)); | |
protoTpl->Set("libs", FunctionTemplate::New(Conf::Libs)); | |
protoTpl->Set("flags", FunctionTemplate::New(Conf::Flags)); | |
protoTpl->Set("src", FunctionTemplate::New(Conf::Src)); | |
protoTpl->Set("target", FunctionTemplate::New(Conf::Target)); | |
protoTpl->Set("run", FunctionTemplate::New(Conf::Run)); | |
protoTpl->Set("verbose", FunctionTemplate::New(Conf::Verbose)); | |
protoTpl->Set("check", FunctionTemplate::New(Conf::Check)); | |
global->Set(String::New("Configure"), tpl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment