diff --git a/Makefile b/Makefile index 878964a..32478bc 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +HASH := $(shell git rev-parse --short HEAD) SRCS := $(wildcard src/*.c) OBJS := $(SRCS:src/%.c=build/%.o) DEPS := $(OBJS:%.o=%.d) @@ -6,7 +7,7 @@ WARNING_FLAGS := -Wall -Wextra INCLUDE_FLAGS := -I include CC := clang -CFLAGS := $(WARNING_FLAGS) $(INCLUDE_FLAGS) -MMD -MP -std=c99 -ggdb +CFLAGS := $(WARNING_FLAGS) $(INCLUDE_FLAGS) -DKILO_COMMIT_HASH=$(HASH) -MMD -MP -std=c99 -ggdb kilo: $(OBJS) $(CC) $(CFLAGS) $^ -o $@ diff --git a/include/kilo.h b/include/kilo.h index 0127fd6..3fc14f3 100644 --- a/include/kilo.h +++ b/include/kilo.h @@ -1,7 +1,6 @@ #ifndef KILO_H #define KILO_H -#define KILO_VERSION "0.0.1" #define KILO_TAB_STOP 4 #include diff --git a/include/utils.h b/include/utils.h index efa9ef9..063bfac 100644 --- a/include/utils.h +++ b/include/utils.h @@ -6,6 +6,9 @@ #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) +#define _STRINGIZE(x) #x +#define STRINGIZE(x) _STRINGIZE(x) + typedef int ERRCODE; #define RETURN(code) do {errcode = code; goto END;} while(0) diff --git a/src/ui.c b/src/ui.c index 6be551c..571ab38 100644 --- a/src/ui.c +++ b/src/ui.c @@ -50,7 +50,7 @@ static void ui_draw_rows(struct append_buf *draw_buf) { } else if (no_file && y == E.screenrows / 2) { char welcome[64]; int len = snprintf(welcome, sizeof(welcome), - "Welcome to kilo! -- v%s", KILO_VERSION); + "Welcome to kilo! -- %s", STRINGIZE(KILO_COMMIT_HASH)); int padding = (E.screencols - len) / 2; for (int i = 0; i < padding; i++)