Is there a way to declare my own variable inside of a spec file and refer to it as %{my_var} ?
2 Answers
Define your variable at the beginning: %define my_var my_value and use it with %{my_var}.
According to rpm packaging guide - defining your own macros, %global can be used too.
See also: https://rpm-software-management.github.io/rpm/manual/macros.html
Sure. You use %global or %define for that. See for example the fedora firefox.spec.