Skip to content

Instantly share code, notes, and snippets.

@mosmeh
Created April 3, 2020 09:44
Show Gist options
  • Save mosmeh/6e3bf8b70f0ab9278fe23de4be4a241c to your computer and use it in GitHub Desktop.
Save mosmeh/6e3bf8b70f0ab9278fe23de4be4a241c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#ifndef FOO_VERSION
#define FOO_VERSION "unknown"
#endif
int main(void) {
printf("version " FOO_VERSION
#ifdef FOO_COMMIT
" (commit " FOO_COMMIT ")"
#endif
"\n");
return 0;
}
OBJS := foo
VERSION := $(shell cat VERSION 2> /dev/null)
COMMIT := $(shell git describe --always --tags --dirty 2> /dev/null)
CFLAGS := $(if $(VERSION),-DFOO_VERSION=\"$(VERSION)\") $(if $(COMMIT),-DFOO_COMMIT=\"$(COMMIT)\")
.PHONY: all clean
all: $(OBJS)
clean:
$(RM) $(OBJS)
foo: foo.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment