Qmake DEFINES macro with parameter - macros

I want to know how to define C++ preprocessor macro using qmake DEFINES variable. I have tried to do the following:
Project file
TEMPLATE = app
CONFIG += c++14 console
SOURCES += main.cpp
DEFINES += "TEMPORARY_UNUSED(x)=\"(void)x;\""
DEFINES += "BASE_CLASS_UNUSED(x)=\"(void)x;\""
Main.cpp file
int main() {
int hello;
TEMPORARY_UNUSED(hello)
BASE_CLASS_UNUSED(hello)
}
But this resulted in following error: [main.o] Error 2. I have no idea how macro definition (very simple by the way) could cause errors in build process.
This is macro definitions using c++'s #define. They work just as I expected
#define TEMPORARY_UNUSED(x) (void)x;
#define BASE_CLASS_UNUSED(x) (void)x;
The question is: how do I define c++ preprocessor macro using qmake DEFINES and how my macro was able to cause compilation errors.
P.S. I'm perfectly aware of Q_UNUSED macro but I prefer to have a macro that indicates not only that the variable is unused but also why it is unused.
P.S. Code that I have posted is 100% of my project, there no more files that define/redefine anything else.

You need to escape the parentheses and the semicolon with backslashes:
DEFINES += TEMPORARY_UNUSED\\(x\\)=\\(void\\)x\\;
Otherwise the () and the ; in the -D compiler argument will be interpreted as parts of a more complex command.
Note that the /D option of MSVC does not support function-like macro definitions. To overcome this restriction, write your preprocessor directives into a header file and include it with the /FI compiler switch.

Related

Doxygen ignoring aliases

I want to define an alias in doxygen. According to the documentation and testimonials, I just add something like this in Doxyfile
ALIASES += sideeffect="\par Side Effects:\n"
and then use #sideeffect in the source code documentation. But I get this message when running doxygen:
/path/to/file.f:12: warning: Found unknown command `\sideeffect'
I tried escaping the quotes and backslashes too:
ALIASES += "sideeffect=\"\\par Side Effects:\\n\""
and with = instead of += (I also make sure the ALIASES option is not defined anywhere else in Doxyfile). Other options are working fine.
Even a simple ALIASES += "foo=bar" does not work (unknown command `\foo').
I'm using doxygen 1.7.6.1 (Ubuntu 12.04), and the Doxyfile created by this version has the ALIASES line, so I guess it should be supported. What could I be doing wrong?
Try this
ALIASES += "sideeffect = \par \"Side Effects:\" \n"
This worked for me:
\sideeffect This will cause a catastrophic explosion.
It yields:
I am using 1.8.3.1

How to use vim LatexSuite with a Makefile?

I would like to type :make in Vim to compile my LaTeX document. I wrote down compilation rules in a Makefile, but as soon as I enable the LatexSuite Vim extension, the Makefile is no longer used. Instead, Vim runs latex -interaction=nonstopmode (note the absence of a filename) and hangs in that command. I did not change the g:Tex_UseMakefile option from its default 1 to 0 and according to the documentation, that should cause my Makefile to be used, but it's not.
What configuration is needed to tell LatexSuite to just use my Makefile?
LatexSuite was obtained via OpenSuSE repositories: vim-plugin-latex-20120125-21.1.1.noarch
You can override this via following setting in your vimrc.
autocmd FileType tex let g:Tex_CompileRule_dvi = 'make'
Alternatively, set makeprg in $HOME/.vim/after/ftplugin/tex.vim
set makeprg='make'
Helpful in-source documentation of file <latex-suite-root-folder>/compiler/tex.vim
Section " Customization of 'makeprg': {{{
This (g:Tex_CompileRule_dvi) is a string which should be directly be able to be cast into
" &makeprg.

Read environment variable using Macros iOS [duplicate]

In the code below, I would like the value of THE_VERSION_STRING to be taken from the value of the environment variable MY_VERSION at compile time
namespace myPluginStrings {
const char* pluginVendor = "me";
const char* pluginRequires = THE_VERSION_STRING;
};
So that if I type:
export MY_VERSION="2010.4"
pluginRequires will be set at "2010.4", even if MY_VERSION is set to something else at run time.
UPDATE: (feb 21) Thanks for your help everyone. It works.
As I'm using Rake as a build system, each of my CFLAGS is a ruby variable. Also the values need to end up in quotes. Therefore the gcc command line for me needs to look like this:
gcc file.c -o file -D"PLUGIN_VERSION=\"6.5\""
Which means this is in my Rakefile:
"-D\"PLUGIN_VERSION=\\\"#{ENV['MY_VERSION']}\\\"\""
If I recall correctly, you can use the command line parameter -D with gcc to #define a value at compile time.
i.e.:
$ gcc file.c -o file -D"THE_VERSION_STRING=${THE_VERSION_STRING}"
In the code below, I would like the value of THE_VERSION_STRING to be taken from the value of the environment variable MY_VERSION at compile time
No, you can't do it like this. The only way to extract environment variables is at runtime with the getenv() function. You will need to explicitly extract the value and copy it to pluginRequires.
If you want the effect of a compile-time constant, then you'll have to specify the definition on the compiler commandline as Seth suggests.

How can I syntax check a Scala script without executing the script and generating any class files?

One can write scripts in Scala. So you can put this into Hello.scala
#!/bin/sh
exec scala $0 $#
!#
println("You supplied " + args.length + " arguments!")
and make it executable in Unix by
chmod u+x Hello.scala
Then you can run the script simply by
./Hello.scala
This compiles the script and runs it if there are no syntax errors. However, this does not account for situation when I only want to syntax check without executing the script. I do not want to modify the script (i.e. by removing the #! directive) and I do not want any *.class files to be generated.
How can I syntax check a Scala script?
I expect that you actually want a little more than just checking for correct syntax ... presumably what you want to know is that your file would compile correctly if you did actually compile it. That involves type checking as well as syntax checking.
For Scala source files (ie. not scripts) you can specify the -Ystop:refchecks command line argument to cause the compiler to stop before it starts code generation (if you really are only interested in syntactic correctness you could specify -Ystop:parser). If there are errors they will be shown on the console in exactly the same way as if you fully compiled the sources.
For Scala scripts you can also specify the -Ystop:refchecks argument. If you do this, then you will either see compile errors reported on the console or, if there are no errors in the script, you will see the following,
$ scala -Ystop:refchecks Hello.scala
java.lang.ClassNotFoundException: Main
The ClassNotFoundException indicating that no classfiles have been generated and that your script has not been executed.
If you want to cut lines off your file to pass to the interpreter, you can create a script called CutScala.scala (or whatever you prefer):
#!/bin/sh
exec scala $0 $#
!#
import scala.collection.JavaConversions._
import java.io._
val p = new ProcessBuilder(
List(
"scala",
"-e",
io.Source.fromFile(args(1)).getLines().drop(args(0).toInt).mkString("\n")
) :::
args.drop(2).toList
).start()
p.waitFor
val output = List(p.getInputStream,p.getErrorStream).map(
x => new BufferedReader(new InputStreamReader(x))
)
println("Exit code = " + p.exitValue)
for ((reader,title) <- (output zip List("Output:","Errors:"))) {
println(title);
Iterator.continually(reader.readLine).takeWhile(_!=null).foreach(println)
println
}
and then call it like
./CutScala.scala 4 Hello.scala a b c
to drop the first 4 lines and just parse the rest. Miles' answer tells you how to do the other (more difficult) half of not producing any output and not running anything.

Is there any syntax or trick to be able to create a multiline rpm spec file macro

Background.
$ rpmbuild --version
RPM version 4.3.3
I am working on a spec file that needs to process a list of files in multiple scriptlets. DRY (don't repeat youself) has me defining the list once as a macro which is expanded into the various helper scripts. Maintaining the list is a pain since I haven't seen a way to avoid putting all the files on the same line.
%define LIST \
a \
b
gives an error
%define LIST a\
b\
gives an error as well
%define LIST a
%define LIST %LIST b
Fails due to a recursion error
You cannot really make multiline macros in a spec file the way you can in your ~/.rpmmacros file. Kind of silly.
I create a subdirectory SPECS/inc/ with spec files which act as multi-line macros which are used by all packages created for my site. Instead of using macros as %foo, you can just do %include inc/foo.spec. You can also create shortcuts to avoid the include syntax %global foo %include inc/foo.spec. Then it works just like a multi-line macro.
Here is a complete example.
inc/env.spec
%global foo %include inc/foo.spec
%global bar %include inc/bar.spec
#Lots of other common things to all packages
inc/foo.spec
a
b
c
d
And then in my package spec file, mylib.spec:
%include inc/env.spec
Name: mylib
Version: X.Y
#etc...
%foo
Since you explained your goal a bit more, let's try different approach. Try this in your spec file:
Source1: flist
%{expand:%global LIST %(cat %{SOURCE1})}
And this in Source1 file (in this case flist):
a \
b \
c
I have tested this with rpm 4.4.6 since that's the oldest version available to me at this time.
In macro definitions, an end-of-line backslash is removed and used to tell RPM that the macro definition continues. The newline character is NOT stripped (unlike a make file). Therefore, if you are constructing a multi-line script, semi-colons are not needed. This also means that if you are splitting a single command, you must use 3 backslashes. Two to yield a backslash that the shell will see and one to tell rpmbuild to keep parsing the macro. The shell will remove the backslash it sees, plus the newline and that will yield one command on two lines. Whew !!
You have to have at least some part of the value on the first line, i.e.:
%define LIST a\
b\
c
This macro definition will work. If you plan to use these as commands, i.e. something like
%define DOSOMETHING rm file1\
rm file2\
rm file3
...
%build
%DOSOMETHING
this will not work. The lines in executable sections are split into separate commands first, THEN the macros are expanded. I.e. defining the macro will work, executing it as three separate commands will not.
If you want to execute 3 separate commands, it's easier to do it like
%define DOSOMETHING rm file1; rm file2; rm file3
If I was you, I'd maintain the list in a source file.
Contents of %{_sourcedir}/LIST:
a
b
c
d
In the spec file:
%define process_files() \
for i in %(cat %{_sourcedir}/LIST)
do \
echo "process list of files here" \
done
This example should work:
cat file.spec
%define MAKE make \\\
status=success \\\
#EOL
%build
${MAKE}
cat Makefile
status?=fail
default:
echo "status=${status}"