Added support for outputing makefile style dependencies when compiling shaders.

This commit is contained in:
bkaradzic 2012-06-26 20:55:33 -07:00
parent 2b607e0f8f
commit 8dd523fa67
5 changed files with 58 additions and 7 deletions

View file

@ -99,6 +99,7 @@ int fppPreProcess(struct fppTag *tags)
global->macro=NULL; global->macro=NULL;
global->evalue=0; global->evalue=0;
global->depends=NULL;
global->input=NULL; global->input=NULL;
global->output=NULL; global->output=NULL;
global->error=NULL; global->error=NULL;

View file

@ -40,6 +40,10 @@ ReturnCode openfile(struct Global *global, char *filename)
else else
ret=addfile(global, fp, filename); ret=addfile(global, fp, filename);
if(!ret && global->depends) {
global->depends(filename, global->userdata);
}
if(!ret && global->showincluded) { if(!ret && global->showincluded) {
/* no error occured! */ /* no error occured! */
Error(global, "cpp: included \""); Error(global, "cpp: included \"");
@ -237,6 +241,9 @@ int dooptions(struct Global *global, struct fppTag *tags)
strcpy(global->work, tags->data); /* Remember input filename */ strcpy(global->work, tags->data); /* Remember input filename */
global->first_file=tags->data; global->first_file=tags->data;
break; break;
case FPPTAG_DEPENDS:
global->depends=(void (*)(char *, void *))tags->data;
break;
case FPPTAG_INPUT: case FPPTAG_INPUT:
global->input=(char *(*)(char *, int, void *))tags->data; global->input=(char *(*)(char *, int, void *))tags->data;
break; break;

View file

@ -199,6 +199,8 @@ struct Global {
int evalue; /* Current value from evallex() */ int evalue; /* Current value from evallex() */
void (*depends)(char *filename, void *); /* depends function */
char *(*input)(char *, int, void *); /* Input function */ char *(*input)(char *, int, void *); /* Input function */
char *first_file; /* Preprocessed file. */ char *first_file; /* Preprocessed file. */

3
3rdparty/fcpp/fpp.h vendored
View file

@ -156,4 +156,7 @@ struct fppTag {
/* Switch on WWW-mode */ /* Switch on WWW-mode */
#define FPPTAG_WEBMODE 33 #define FPPTAG_WEBMODE 33
/* Depends function: */
#define FPPTAG_DEPENDS 34 /* data is an depends funtion */
int fppPreProcess(struct fppTag *); int fppPreProcess(struct fppTag *);

View file

@ -268,7 +268,7 @@ void printCode(const char* _code)
bool compileGLSLShader(CommandLine& _cmdLine, const std::string& _code, const char* _outFilePath) bool compileGLSLShader(CommandLine& _cmdLine, const std::string& _code, const char* _outFilePath)
{ {
const glslopt_shader_type type = (0 == _stricmp(_cmdLine.findOption('\0', "type"), "fragment") ) ? kGlslOptShaderFragment : kGlslOptShaderVertex; const glslopt_shader_type type = tolower(_cmdLine.findOption('\0', "type")[0]) == 'f' ? kGlslOptShaderFragment : kGlslOptShaderVertex;
glslopt_ctx* ctx = glslopt_initialize(false); glslopt_ctx* ctx = glslopt_initialize(false);
@ -500,6 +500,10 @@ struct Preprocessor
m_tagptr->data = this; m_tagptr->data = this;
m_tagptr++; m_tagptr++;
m_tagptr->tag = FPPTAG_DEPENDS;
m_tagptr->data = (void*)fppDepends;
m_tagptr++;
m_tagptr->tag = FPPTAG_INPUT; m_tagptr->tag = FPPTAG_INPUT;
m_tagptr->data = (void*)fppInput; m_tagptr->data = (void*)fppInput;
m_tagptr++; m_tagptr++;
@ -550,11 +554,22 @@ struct Preprocessor
m_default += temp; m_default += temp;
} }
void addDependency(const char* _fileName)
{
m_depends += " \\\n ";
m_depends += _fileName;
}
bool run() bool run()
{ {
m_fgetsPos = 0; m_fgetsPos = 0;
FILE* file = fopen(m_filePath, "r"); FILE* file = fopen(m_filePath, "r");
if (NULL == file)
{
return false;
}
long int size = fsize(file); long int size = fsize(file);
char* input = new char[size+1]; char* input = new char[size+1];
size = fread(input, 1, size, file); size = fread(input, 1, size, file);
@ -593,6 +608,12 @@ struct Preprocessor
return NULL; return NULL;
} }
static void fppDepends(char* _fileName, void* _userData)
{
Preprocessor* thisClass = (Preprocessor*)_userData;
thisClass->addDependency(_fileName);
}
static char* fppInput(char* _buffer, int _size, void* _userData) static char* fppInput(char* _buffer, int _size, void* _userData)
{ {
Preprocessor* thisClass = (Preprocessor*)_userData; Preprocessor* thisClass = (Preprocessor*)_userData;
@ -623,6 +644,7 @@ struct Preprocessor
fppTag* m_tagptr; fppTag* m_tagptr;
char* m_filePath; char* m_filePath;
std::string m_depends;
std::string m_default; std::string m_default;
std::string m_input; std::string m_input;
std::string m_preprocessed; std::string m_preprocessed;
@ -673,6 +695,7 @@ int main(int _argc, const char* _argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
bool depends = cmdLine.hasArg("depends");
bool preprocessOnly = cmdLine.hasArg("preprocess"); bool preprocessOnly = cmdLine.hasArg("preprocess");
Preprocessor preprocessor(filePath); Preprocessor preprocessor(filePath);
@ -788,19 +811,34 @@ int main(int _argc, const char* _argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
bool compiled = false;
if (glsl) if (glsl)
{ {
if (compileGLSLShader(cmdLine, preprocessor.m_preprocessed, outFilePath) ) compiled = compileGLSLShader(cmdLine, preprocessor.m_preprocessed, outFilePath);
{
return EXIT_SUCCESS;
}
} }
else else
{ {
if (compileHLSLShader(cmdLine, preprocessor.m_preprocessed, outFilePath) ) compiled = compileHLSLShader(cmdLine, preprocessor.m_preprocessed, outFilePath);
}
if (compiled
&& depends)
{
std::string ofp = outFilePath;
ofp += ".d";
FILE* out = fopen(ofp.c_str(), "wb");
if (NULL != out)
{ {
return EXIT_SUCCESS; Stream stream(out);
stream.write(outFilePath);
stream.write(":");
stream.write(preprocessor.m_depends.c_str() );
stream.write("\n");
stream.close();
fclose(out);
} }
return EXIT_SUCCESS;
} }
} }