This set of commits fixes multiple issues with both make scripts. It started with #7358 and digging into it I found more problems.
@Gusted [commented](https://codeberg.org/forgejo/forgejo/issues/7358#issuecomment-3145145):
> I do think the place where verify-version gets called should likely be backend instead and the error should likely include extra details on how to fix the error, but that can be discussed in the PR.
I think it should be closest to where `$(FORGEJO_VERSION)` is used and that's part of `$(LDFLAGS)`, so I added it where the latter is used.
When it comes to wording feel free to make suggestions.
**I haven't tested docker builds.**
I believe the most optimal way to do it is to create POSIX-compliant shell script where all those conditionals and variable expansion may be placed, and then that script should generate POSIX-compliant Makefile.
# Testing
## BSDMakefile
Should be launched from a BSD OS. You need to add `-f BSDMakefile` on OpenBSD.
* `make show-version-major show-version-minor`
Should display two lines with version numbers.
* `make TAGS=bindata`
Should launch the building process once.
## Makefile
* `make TAGS=bindata`
Should do the same as `make build`.
* `make `*target*
Should build given target like it used to.
* Copy everything except *.git* and *VERSION* to a separate directory.
`make TAGS=bindata`
Should fail with error “Could not determine FORGEJO_VERSION...”
* Copy everything except *.git* and *VERSION* to a separate directory.
`make clean`
Should execute correctly.
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7455
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Matt Latusek <matlib@matlibhax.com>
Co-committed-by: Matt Latusek <matlib@matlibhax.com>
1. `make build` fails because `||` and `&&` have the same precedence in
sh/bash, so the `false` command always evaluated (leading to an error).
```
+ which gmake /usr/local/bin/gmake
+ false
*** Failed target: .BEGIN
*** Failed command: which "gmake" || printf "Error: GNU Make is
required!\n\n" 1>&2 && false
*** Error code 1
```
2. When `GPREFIX` is set to an empty string with quotation marks,
`gmake` mistakenly thinks that it's a file name:
``` gmake: *** empty string invalid as file name. Stop. ```
The syntax of the gitea Makefile is not platform-agnostic and is
specific to the GNU version of `make`. BSD platforms such as FreeBSD
ship with bmake (BSD make) as their default `make` program; attempting
to compile gitea by simply executing `make` causes a wall of errors to
show as a result of syntax incompatible with BSD make.
If a file named `BSDmakefile` is present, `bmake` will give it
preference over a generic `Makefile`. This `BSDmakefile` is taken from
the BSD-licensed `gmake-proxy` project [0], which transparently proxies
all `make` commands to `gmake` (GNU make) on systems where `bmake` is
the default, and if `gmake` is not installed an error message is
displayed.
[0]: https://github.com/neosmart/gmake-proxy