contrib: Fix relpath.sh exit status for invalid arguments
relpath.sh now exits with a non-zero status and writes usage to stderr on error, fixing libstdc++ build issues.
The relpath.sh script previously always exited successfully, even when given invalid arguments, and printed usage instructions to standard output. This caused build failures in libstdc++‘s Makefile, which assumed an error status would prevent further processing. This change corrects the script to print usage to standard error and exit with a non-zero status for invalid inputs, resolving the aforementioned build issue.
In Details
The relpath.sh script, part of GCC's contrib utilities, is used to compute the relative path between two directories. A bug in this script caused it to always return an exit status of 0 and print its usage message to stdout, even when invoked with incorrect arguments. This behavior interfered with build systems, such as the libstdc++-v3/src/c++23/Makefile, that rely on non-zero exit codes to detect errors. This commit fixes relpath.sh to adhere to conventional error handling by emitting usage to stderr and returning a non-zero exit code upon encountering invalid arguments.
- relpath.sh
- A shell script in the GCC contrib directory that calculates the relative path between two given directory paths.
- exit status
- A numerical value returned by a program or script to the operating system upon termination. Conventionally, an exit status of 0 indicates success, while any non-zero value signifies an error.
- stderr
- Standard error, a stream used by processes to output error messages. It is typically displayed on the console, separate from standard output.