# Passing arguments to make rules

A word of caution: this sort of goes against how `make` is intended to be used. But it can be convenient, and fun.

```
action:
  @echo command $(filter-out $@,$(MAKECMDGOALS))

%:
  @:
```

Example call:

```bash
make action arg1 arg2
```

* `$(MAKECMDGOALS)` is the list of targets passed to make (`action arg1 arg2`)
* `$@` is an automatic variable expanding to the name of the target rul (`action`)
* `filter-out` is a function that removes items from a list: `filter-out $@,$(MAKECMDGOALS) -> arg1 arg2`
* `%` is a wildcard. If no rule is matched (as for `arg1` and `arg2` in the example), this goal will be run
* `:` is a no-op. It means "do nothing", like the bash equivalent
* `@` in front of a recipe makes it silent

The result is that `command` will be invoked as: `command arg1 arg2`. `make` will still recognize `arg1` and `arg2` as targets, but will run the wildcard rule for them, silently doing nothing.

A side effect of the wildcard target is that `make` won't complain if we pass an invalid target - it will just silently do nothing:

```bash
make non-existing targets
```

And if one of the arguments we want to pass to `command` also is the name of another target, recipes in that rule will be executed as well - which probably is not somehting we want.

Source: [stackoverflow](https://stackoverflow.com/a/6273809)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.eliasnorrby.com/make/passing-arguments-to-make-rule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
