# Redefining __BASE_FILE__ with qmake

• I use __BASE_FILE__ to show the logging file in my debug output. The problem is that it includes the relative directory from where qmake invokes the makefile. In my case the output will be something like src/MyFile.cpp. I know it's possible to redefine the file macros to only show the file basename, but I cannot figure out how to get qmake to a define which involves the current file being processed (QMAKE_FILE_IN_BASE). Is that possible or is there any other way to solve this?

• @Marco-Nilsson I use __FILE__. You won't get pathing with that. It's plenty to work with for debugging. Here is an excerpt from my logger (available at https://github.com/ambershark-mike/sharklog/blob/master/lib/sharklog/location.h_):

/*!
The following macro and defines section is used to define
different location information in different compilers, like
msvc, mingw, gcc, and clang.
*/
#if !defined(SHARKLOG_LOCATION)
#if defined(_MSC_VER)
#if _MSC_VER >= 1300
#define __SHARKLOG_FUNC__ __FUNCSIG__
#endif
#else
#if defined(__GNUC__)
#define __SHARKLOG_FUNC__ __PRETTY_FUNCTION__
#endif
#endif

#if !defined(__SHARKLOG_FUNC__)
#define __SHARKLOG_FUNC__ ""
#endif

//! This macro is used to generate location information for the logger, see \ref Location
#define SHARKLOG_LOCATION sharklog::Location(__FILE__, __SHARKLOG_FUNC__, __LINE__)
#endif


That block handles all location tracking for logged lines on all the platforms I support. MSVC, mingw, g++, clang, etc.

• Oops I totally lied... I just tested it and it does do the full path. :( I could have swore it just did the actual file name.

Anyway here is a post on a way to do it:
https://stackoverflow.com/questions/8487986/file-macro-shows-full-path

• Oops I totally lied... I just tested it and it does do the full path. :( I could have swore it just did the actual file name.

Anyway here is a post on a way to do it:
https://stackoverflow.com/questions/8487986/file-macro-shows-full-path

I've tried using the macro with strrchr/__builtin_strrchr but my gcc (4.4.7) does not modify the strings at compile time. It could be due to the very archaic gcc version but it's the best you've got on AVR32.

It could be done if I could either find a way to get qmake to define the source file, or if I can get it to make inside the subfolder.