Closed madebr closed 1 year ago
Hi! I considered your suggested approach, and I see two problems with it:
Detecting location of the re2c binary. As you can see from the answer to SO question, it is far from easy and very platform-dependent, so it would be hard to test (impossible on all platforms). The portable way argv[0]
doesn't work because if re2c is in PATH
, then argv[0]
can be just re2c
.
A relative path works for the installed binary, but it makes the discovery of include files more opportunistic for the case of development binary (what if the relative include path just happens to be there and contains the wrong files?). Currently development binary won't find the include files unless you pass an explicit -I
option, which is a safer default.
What is your use case? One possible way out is to create a wrapper script that would pass an explicit -I
option after relocating re2c installation. I don't think other programs are easily relocatable; at least it is not the default expectation as far as I know.
bison accomplishes this by using gnulib. Others accomplish this by extra arguments (like your -I
), or using environment variables.
My use case is adding re2c alongside a compiler toolchain for distribution. I suppose a re2c wrapper script like you described will be the way the go.
I suppose a re2c wrapper script like you described will be the way the go.
Sounds good. Closing the bug, please reopen if the wrapper approach doesn't work.
re2c
has an absolute default stdlib include path baked in. Because of this, you cannot move the re2c install tree if you including files from this folder.It's added here: https://github.com/skvadrik/re2c/blob/6b7a437ab4240191bed24c00fce35269e2469aa2/CMakeLists.txt#L102-L104 And used here: https://github.com/skvadrik/re2c/blob/6b7a437ab4240191bed24c00fce35269e2469aa2/src/parse/input.cc#L48-L51
Ideally, the CMake script should generate a relative path from the re2c
bin
directory to the stdlib folder so the following macro is set instead:This generates:
../share/re2c/stdlib
.Inside
re2c
, you can then append this relative path to the location of the runningre2c
binary to build an absolute path to the standard library.This StackOverflow question suggests a few ways to compute the location of the re2c binary.
Related to this, a change of installation prefix triggers a complete rebuild. Reproducer: