Learn how to use the `sed` command to effectively delete trailing backslashes in makefiles, resolving the `*** multiple target patterns. Stop.` error with simple steps.
---
This video is based on the question https://stackoverflow.com/q/68452854/ asked by the user 'Tas' ( https://stackoverflow.com/u/16486870/ ) and on the answer https://stackoverflow.com/a/68456416/ provided by the user 'Renaud Pacalet' ( https://stackoverflow.com/u/1773798/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Sed command to delete "\" which causes "*** multiple target patterns. Stop." error
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
How to Fix *** multiple target patterns. Stop. Error by Removing Trailing Backslashes with Sed
If you've ever encountered the frustrating *** multiple target patterns. Stop. error while working with Makefiles, you might have noticed an extra backslash (\) at the end of some lines. In this guide, we’ll explore how to effectively use the sed command to remove these unwanted backslashes, ensuring your Makefile runs smoothly. Let’s dive in!
Understanding the Problem
In a typical Makefile, you might have lines defining object files, and it's common to split them across multiple lines using a backslash. However, sometimes you can end up with an extra backslash, which leads to errors during the build process.
For example, consider the following lines in a Makefile:
[[See Video to Reveal this Text or Code Snippet]]
In this example, the trailing backslash on the line containing /usr/lib/toy.c is causing the *** multiple target patterns. Stop. error when we try to run make.
So, how can we remove these trailing backslashes efficiently from our Makefile?
The Solution: Using Sed Command
The sed command is a powerful tool for manipulating text, perfect for this task. The following command can be used to eliminate trailing backslashes that may appear at the end of lines in your file:
[[See Video to Reveal this Text or Code Snippet]]
Breakdown of the Command
Suppress Default Output:
The -n option suppresses the default output, which allows us to control what gets printed using the p (print) command.
Enable Extended Regular Expressions:
The -E option allows us to use extended regular expressions, making it easier to write complex patterns.
Main Command Components:
${s/\$//;p;}: This part applies only to the last line of the input and removes any trailing backslash.
N; s/([^]*:)/\1/; P; D: This set of commands processes every line:
N: Appends the next line to the pattern space.
s/([^]*:)/\1/: Deletes the trailing backslash before the first colon : if it exists.
P: Prints the first part of the pattern space before the newline.
D: Deletes the processed part of the pattern space, allowing the command to loop back without reading a new line.
How the Commands Work Together
Initial State: When the command starts, the pattern space has one line. By using the N command, we add the next line, which updates our pattern space to contain two lines.
Substitution: The substitution command looks for a backslash that precedes another line. If found, it will remove the backslash and print the current line without it.
Handling the Last Line: The special handling for the last line ensures that if there’s a backslash at the end, it gets processed correctly.
Simplified Version
If you are sure that the last line does not contain a trailing backslash, you can simplify the command slightly:
[[See Video to Reveal this Text or Code Snippet]]
Summary
Using the sed command, you can efficiently remove any trailing backslashes from your Makefile, avoiding the dreaded *** multiple target patterns. Stop. error. Just remember to tweak the command appropriately based on the structure of your Makefile. With these techniques, you can keep your build process smooth and error-free.
Happy coding!
Информация по комментариям в разработке