1

What does the -A option in gcc do? I am using arm-none-linux-gnueabi-gcc.

Below is the rule in my makefile.

$(SH_OBJ): $(OBJS)

$(CC) $(LFLAGS) -o $@-debug -A $@-debug $^ $(LIBPATH) $(LDLIBS)
Paul Dawson
  • 1,332
  • 14
  • 27
Tanaji
  • 71
  • 1
  • 3
  • 1
    Did you look for it in the documentation for the version of gcc you're using? https://gcc.gnu.org/onlinedocs/ – Shawn Jul 24 '19 at 12:09
  • Turns out it's for an old obsolete feature of the preprocessor, There should be an `=` in the argument to it, though... – Shawn Jul 24 '19 at 12:16
  • This answer/predicate doesn't seem to make sense from the make rules. I wonder if it is generating assembler? Maybe the `$(CC)` is not gcc but some look alike. A sample command line of the rule would be helpful. For instance, why is the `-o` the same as the `-A`? – artless noise Jul 24 '19 at 13:50

1 Answers1

1

I suggested looking it up, and since it's an option I've never seen before, I followed my own advice. -A is an option passed to the preprocessor:

From documentation:

-A predicate=answer

Make an assertion with the predicate predicate and answer answer. This form is preferred to the older form -A predicate(answer), which is still supported, because it does not use shell special characters. See Obsolete Features.

-A -predicate=answer

Cancel an assertion with the predicate predicate and answer answer.

(The argument in your makefile is $@-debug, though, which lacks the = to split the predicate and answer parts. Odd.)

And documentation on assertions:

Assertions are a deprecated alternative to macros in writing conditionals to test what sort of computer or system the compiled program will run on. Assertions are usually predefined, but you can define them with preprocessing directives or command-line options.

Assertions were intended to provide a more systematic way to describe the compiler’s target system and we added them for compatibility with existing compilers. In practice they are just as unpredictable as the system-specific predefined macros. In addition, they are not part of any standard, and only a few compilers support them. Therefore, the use of assertions is less portable than the use of system-specific predefined macros. We recommend you do not use them at all.

I'm guessing this is a makefile for a really old project?

Community
  • 1
  • 1
Shawn
  • 47,241
  • 3
  • 26
  • 60
  • It seems that the `=` part could be omitted: I see `-Aquestion=answer -A-question[=answer]` in `man gcc`. I guess, that would imply that the preprocessor should test whether the predicate is defined? Not sure. Does it make sense? Anyway, one has to play with the preprocessor to find out. The documentation could be cleaner here (it has _question_ in the beginning and _predicate_ later, and the `=answer` part is marked optional only in the former). Unsurprisingly, because the feature is probably rarely used today. – Vladislav Ivanishin Jul 24 '19 at 13:24
  • 1
    @VladislavIvanishin The 2nd form is to `unassert` the question. Note the minus '-' before 'question'. I looked at the code and it is basically to make a command line '#define' but I don't think you can use '#undef' on it. For instance you can not `#undef __arm__`. It is like a built-in define as per [dump gcc cpp defines](https://stackoverflow.com/questions/2224334/gcc-dump-preprocessor-defines). – artless noise Jul 24 '19 at 19:06
  • I tried to use it with my Ubuntu 7.4.0-1ubuntu1~18.04.1 x86_64, but it doesn't seem to do anything. The code uses `cpp_assert()` found in libcpp in the gcc source. If I do what the OP says it throws an error. Ie, -Afoo-debug gives *error: missing '(' after predicate*... which shawn kind of notes.This is why I think it is not a gcc optoin, but maybe the linker or assembler. – artless noise Jul 24 '19 at 19:13
  • Even with this answer, I don't understand what a "predicate" is, and how is it related to an assertion - and what are the end effects to the source code. Sometimes looking up - and even finding - the documentation is not enough ... EDIT: guess here there is more on "predicates" and "assertions": https://gcc.gnu.org/onlinedocs/gcc-3.3.2/cpp/Assertions.html ; still don't get what it does to source code – sdbbs Jan 25 '23 at 13:57