Lets say I have a define coming from gcc -D option, e.g.
gcc -DBINDIR=\"/usr/bin\"
What I want is to prepend a path to this existing define so BINDIR is something like "/home/user/testbuild/usr/bin"
What I tried:
#define STRINGIZE_NX(A) #A
#define STRINGIZE(A) STRINGIZE_NX(A)
#define PRE_PATH "/home/user/testbuild"
#pragma message "PRE_PATH: " STRINGIZE(PRE_PATH)
#ifndef BINDIR
# error "BINDIR must be defined"
#else
# pragma message "BINDIR: " STRINGIZE(BINDIR)
# define TMP BINDIR
# pragma message "TMP: " STRINGIZE(TMP)
# undef BINDIR
# define BINDIR PRE_PATH TMP
# pragma message "BINDIR: " STRINGIZE(BINDIR)
# undef TMP
#endif
When looking to the compiler output, it seems to me that TMP is not assigned to the value of BINDIR in the way I expected:
note: #pragma message: PRE_PATH: "/home/user/testbuild"
note: #pragma message: BINDIR: "/usr/bin"
note: #pragma message: TMP: BINDIR
note: #pragma message: "/home/user/testbuild" BINDIR
And finally compiler will fail where the defines should get concatenated:
error: expected ')' before 'TMP'
# define BINDIR PRE_PATH TMP
What am I doing wrong?
Thanks for every help!