Resolves the issue described in #2. (Which I also just hit)
Currently, if someone runs make and peg isn't installed, build/parser.c ends up becoming an empty file. This breaks the Makefile logic like so:
$ guix shell clang-toolchain make -- make
peg grammar.peg > build/parser.c
/gnu/store/y9wj7889n87i8pabsgqrrdsx2yip4kyn-bash-minimal-5.2.37/bin/sh: line 1: peg: command not found
make: *** [Makefile:11: build/parser.c] Error 127
$ guix shell clang-toolchain make -- make
cc -O3 -o build/parser main.c
main.c:17:14: error: unknown type name 'yycontext'
17 | void yyerror(yycontext* ctx, char* message) {
| ^
main.c:59:5: error: use of undeclared identifier 'yycontext'
59 | yycontext ctx;
| ^~~~~~~~~
main.c:60:5: error: call to undeclared library function 'memset' with type 'void *(void *, int, unsigned long)'; ISO C99 and later do
not support implicit function declarations [-Wimplicit-function-declaration]
60 | memset(&ctx, 0, sizeof(yycontext));
| ^
main.c:60:5: note: include the header <string.h> or explicitly provide a declaration for 'memset'
main.c:60:13: error: use of undeclared identifier 'ctx'
60 | memset(&ctx, 0, sizeof(yycontext));
| ^~~
main.c:60:28: error: use of undeclared identifier 'yycontext'
60 | memset(&ctx, 0, sizeof(yycontext));
| ^~~~~~~~~
main.c:61:9: error: call to undeclared function 'yyparse'; ISO C99 and later do not support implicit function declarations
[-Wimplicit-function-declaration]
61 | if (yyparse(&ctx) == 0) {
| ^
main.c:61:18: error: use of undeclared identifier 'ctx'
61 | if (yyparse(&ctx) == 0) {
| ^~~
main.c:62:18: error: use of undeclared identifier 'ctx'
62 | yyerror(&ctx, "syntax error\n");
| ^~~
8 errors generated.
make: *** [Makefile:14: build/parser] Error 1
By using -o instead of >, the file won't be created unless peg runs succesfully.
Resolves the issue described in https://codeberg.org/ziglang/zig-spec/issues/2. (Which I also just hit)
Currently, if someone runs `make` and `peg` isn't installed, `build/parser.c` ends up becoming an empty file. This breaks the Makefile logic like so:
```sh-session
$ guix shell clang-toolchain make -- make
peg grammar.peg > build/parser.c
/gnu/store/y9wj7889n87i8pabsgqrrdsx2yip4kyn-bash-minimal-5.2.37/bin/sh: line 1: peg: command not found
make: *** [Makefile:11: build/parser.c] Error 127
$ guix shell clang-toolchain make -- make
cc -O3 -o build/parser main.c
main.c:17:14: error: unknown type name 'yycontext'
17 | void yyerror(yycontext* ctx, char* message) {
| ^
main.c:59:5: error: use of undeclared identifier 'yycontext'
59 | yycontext ctx;
| ^~~~~~~~~
main.c:60:5: error: call to undeclared library function 'memset' with type 'void *(void *, int, unsigned long)'; ISO C99 and later do
not support implicit function declarations [-Wimplicit-function-declaration]
60 | memset(&ctx, 0, sizeof(yycontext));
| ^
main.c:60:5: note: include the header <string.h> or explicitly provide a declaration for 'memset'
main.c:60:13: error: use of undeclared identifier 'ctx'
60 | memset(&ctx, 0, sizeof(yycontext));
| ^~~
main.c:60:28: error: use of undeclared identifier 'yycontext'
60 | memset(&ctx, 0, sizeof(yycontext));
| ^~~~~~~~~
main.c:61:9: error: call to undeclared function 'yyparse'; ISO C99 and later do not support implicit function declarations
[-Wimplicit-function-declaration]
61 | if (yyparse(&ctx) == 0) {
| ^
main.c:61:18: error: use of undeclared identifier 'ctx'
61 | if (yyparse(&ctx) == 0) {
| ^~~
main.c:62:18: error: use of undeclared identifier 'ctx'
62 | yyerror(&ctx, "syntax error\n");
| ^~~
8 errors generated.
make: *** [Makefile:14: build/parser] Error 1
```
By using `-o` instead of `>`, the file won't be created unless `peg` runs succesfully.