2001-11-08 00:47:38 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: Insight Segmentation & Registration Toolkit
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2000 National Library of Medicine
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
See COPYRIGHT.txt for copyright details.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmAddCustomCommandCommand.h"
|
|
|
|
|
|
|
|
|
|
|
|
// cmAddCustomCommandCommand
|
2001-11-09 18:33:22 +03:00
|
|
|
bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
2001-11-09 18:42:16 +03:00
|
|
|
/* Let's complain at the end of this function about the lack of a particular
|
2001-11-09 18:33:22 +03:00
|
|
|
arg. For the moment, let's say that SOURCE, COMMAND, TARGET are always
|
2001-11-09 18:42:16 +03:00
|
|
|
required.
|
2001-11-09 18:33:22 +03:00
|
|
|
*/
|
|
|
|
if (args.size() < 6)
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
|
|
|
this->SetError("called with wrong number of arguments.");
|
|
|
|
return false;
|
|
|
|
}
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2001-11-09 18:33:22 +03:00
|
|
|
std::string source, command, target;
|
|
|
|
std::vector<std::string> command_args, depends, outputs;
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2001-11-09 18:33:22 +03:00
|
|
|
enum tdoing {
|
|
|
|
doing_source,
|
|
|
|
doing_command,
|
|
|
|
doing_target,
|
|
|
|
doing_args,
|
|
|
|
doing_depends,
|
|
|
|
doing_outputs,
|
|
|
|
doing_nothing
|
|
|
|
};
|
|
|
|
|
|
|
|
tdoing doing = doing_nothing;
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2001-11-09 18:33:22 +03:00
|
|
|
for (unsigned int j = 0; j < args.size(); ++j)
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
2001-11-09 18:33:22 +03:00
|
|
|
std::string copy = args[j];
|
|
|
|
m_Makefile->ExpandVariablesInString(copy);
|
|
|
|
|
|
|
|
if(copy == "SOURCE")
|
|
|
|
{
|
|
|
|
doing = doing_source;
|
|
|
|
}
|
|
|
|
else if(copy == "COMMAND")
|
|
|
|
{
|
|
|
|
doing = doing_command;
|
|
|
|
}
|
|
|
|
else if(copy == "TARGET")
|
|
|
|
{
|
|
|
|
doing = doing_target;
|
|
|
|
}
|
|
|
|
else if(copy == "ARGS")
|
|
|
|
{
|
|
|
|
doing = doing_args;
|
|
|
|
}
|
|
|
|
else if (copy == "DEPENDS")
|
|
|
|
{
|
|
|
|
doing = doing_depends;
|
|
|
|
}
|
|
|
|
else if (copy == "OUTPUTS")
|
|
|
|
{
|
|
|
|
doing = doing_outputs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (doing)
|
|
|
|
{
|
|
|
|
case doing_source:
|
|
|
|
source = copy;
|
|
|
|
break;
|
|
|
|
case doing_command:
|
|
|
|
command = copy;
|
|
|
|
break;
|
|
|
|
case doing_target:
|
|
|
|
target = copy;
|
|
|
|
break;
|
|
|
|
case doing_args:
|
|
|
|
command_args.push_back(copy);
|
|
|
|
break;
|
|
|
|
case doing_depends:
|
|
|
|
depends.push_back(copy);
|
|
|
|
break;
|
|
|
|
case doing_outputs:
|
|
|
|
outputs.push_back(copy);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this->SetError("Wrong syntax. Unknow type of argument.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2001-11-08 00:47:38 +03:00
|
|
|
}
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2001-11-09 18:33:22 +03:00
|
|
|
/* At this point we could complain about the lack of arguments.
|
|
|
|
For the moment, let's say that SOURCE, COMMAND, TARGET are always
|
|
|
|
required.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(source.empty())
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
2001-11-09 18:33:22 +03:00
|
|
|
this->SetError("Wrong syntax. Empty SOURCE.");
|
|
|
|
return false;
|
2001-11-08 00:47:38 +03:00
|
|
|
}
|
2001-11-09 18:33:22 +03:00
|
|
|
if(command.empty())
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
2001-11-09 18:33:22 +03:00
|
|
|
this->SetError("Wrong syntax. Empty COMMAND.");
|
2001-11-08 00:47:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
2001-11-09 18:33:22 +03:00
|
|
|
if(target.empty())
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
2001-11-09 18:33:22 +03:00
|
|
|
this->SetError("Wrong syntax. Empty TARGET.");
|
|
|
|
return false;
|
2001-11-08 00:47:38 +03:00
|
|
|
}
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2001-11-09 18:33:22 +03:00
|
|
|
m_Makefile->AddCustomCommand(source.c_str(),
|
|
|
|
command.c_str(),
|
|
|
|
command_args,
|
2001-11-08 22:34:51 +03:00
|
|
|
depends,
|
|
|
|
outputs,
|
2001-11-09 18:33:22 +03:00
|
|
|
target.c_str());
|
2001-11-08 00:47:38 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|