I want to generate a build error if one or more files matching a certain pattern are found in the current directory.
To illustrate, my make file target currently looks like this:
generate-java:
swig -c++ -java interface.i
The swig utility generates Java classes for each C++ class it encounters in the C++ source code. However, if it encounters usage of a C++ class that for which no definition has been found it will generate a dummy class. The dummy class typically is named something like SWIGTYPE_p_MyClass.
If this situation occurs then I want to treat it as an error. So if a file is found that is named SWIGTYPE_p*.java or contains the string SWIGTYPE_p then I want the build to fail.
I think I need to change the build target to someting like this:
generate-java:
swig -c++ -java interface.i
find . -name "SWIGTYPE_p.*\.java" --> generate build error if found
find . -name "*\.java" | xargs grep SWIGTYPE_p --> generate build error if found
I think I need to compose a command that returns an exit status different from zero in case the string is found. However, I don’t know how to do this. Can anyone help?
You can use the
testcommand of the shell to test whether the output of yourfindcommand is empty. This will emit a fail status (!=0) if find returns something.