From 7d78f85cb2da3354f8d05d2054f90d83d84de66f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 15 Jun 2024 01:29:58 +0200 Subject: makefile --- .gitignore | 6 ++++-- attocc.c | 9 +++++++++ makefile | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 makefile diff --git a/.gitignore b/.gitignore index d2886f5..eafa3bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -/attocc -/test*.c +/* +!/attocc.c +!/makefile +!/.gitignore diff --git a/attocc.c b/attocc.c index 57c934a..7d4abf4 100644 --- a/attocc.c +++ b/attocc.c @@ -39,6 +39,8 @@ static char *OPERATORS[] = { ">=", "||", "&&", "+", "-", "*", "/", "%", "<", ">", "~", "&", "|", "^", "!", "&", "*", "=", }; + +#ifdef DEBUG static char *OPERATOR_NAMES[] = { "OP_SIZEOF", "OP_SHIFT_LEFT", @@ -90,6 +92,7 @@ static char *SEPERATOR_NAMES[] = { "SEP_LPAREN", "SEP_RPAREN", "SEP_LSQUARE", "SEP_RSQUARE", "SEP_LCURLY", "SEP_RCURLY", "SEP_SEMICOLON", "SEP_COMMA", "SEP_DOT", "SEP_COLOR", }; +#endif enum keyword { KW_AUTO, @@ -396,6 +399,7 @@ struct token *tokenize(char *source) { return tokens; } +#ifdef DEBUG void debug_tokens(struct token *tokens) { for (int i = 0; tokens[i].kind != TOK_END; i++) { switch (tokens[i].kind) { @@ -420,6 +424,7 @@ void debug_tokens(struct token *tokens) { } printf("TOK_END\n"); } +#endif int main(int argc, char **argv) { if (argc < 3) { @@ -467,7 +472,11 @@ int main(int argc, char **argv) { struct token *tokens = tokenize(source); if (!tokens) return 1; + +#ifdef DEBUG debug_tokens(tokens); +#endif + free(tokens); return 0; diff --git a/makefile b/makefile new file mode 100644 index 0000000..ffd9c32 --- /dev/null +++ b/makefile @@ -0,0 +1,15 @@ +.PHONY: all clean +ALL = attocc attocc-small attocc-debug +all: $(ALL) +clean: + rm $(ALL) + +attocc: attocc.c + gcc -O3 -o $@ $< + +attocc-debug: attocc.c + gcc -DDEBUG -Wall -Wextra -Wpedantic -o $@ $< + +attocc-small: attocc.c + gcc -Wl,--gc-sections -flto -ffunction-sections -fdata-sections -fPIC -s -Os -o $@ $< + strip -x $@ -- cgit v1.2.3-70-g09d2