Commit 1207c885 authored by David Griffith's avatar David Griffith 💬

Remove Makefile sed fiddling in favor of export-subst in .gitattributes.

parent 1aaec61e
.gitignore export-ignore
.gitattributes export-ignore
Makefile export-subst
......@@ -13,21 +13,25 @@ PREFIX=/usr/local
# Under normal circumstances, nothing below this point should be changed.
##########################################################################
NAME = minipro
VERSION = 0.3dev
# If we're working from git, we have access to proper variables. If
# not, make it clear that we're working from a release.
#
GIT_DIR ?= .git
ifneq ($(and $(wildcard $(GIT_DIR)),$(shell which git)),)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
GIT_HASH = $(shell git rev-parse HEAD)
GIT_HASH_SHORT = $(shell git rev-parse --short HEAD)
GIT_TAG = $(shell git describe --abbrev=0 --tags)
GIT_DATE = $(shell git show -s --format=%ci)
else
GIT_BRANCH = none
GIT_HASH = none
GIT_HASH_SHORT = none
GIT_TAG = none
GIT_BRANCH = $(shell echo "$Format:%D$" | sed s/^.*\>\\s*//)
GIT_HASH = "$Format:%H$"
GIT_HASH_SHORT = "$Format:%h$"
GIT_DATE = "$Format:%ci$"
endif
BUILD_DATE_TIME = $(shell date +%Y%m%d.%k%M%S | sed s/\ //g)
BUILD_DATE = $(shell date "+%Y-%m-%d %H:%M:%S %z")
VERSION_HEADER = version.h
VERSION_STRINGS = version.c
......@@ -64,10 +68,11 @@ $(VERSION_HEADER):
@echo " * This file is automatically generated. Do not edit." >> $@
@echo " */" >> $@
@echo "extern const char build_timestamp[];" >> $@
@echo "#define VERSION \"$(VERSION)\"" >> $@
@echo "#define GIT_BRANCH \"$(GIT_BRANCH)\"" >> $@
@echo "#define GIT_HASH \"$(GIT_HASH)\"" >> $@
@echo "#define GIT_HASH_SHORT \"$(GIT_HASH_SHORT)\"" >> $@
@echo "#define GIT_TAG \"$(GIT_TAG)\"" >> $@
@echo "#define GIT_DATE \"$(GIT_DATE)\"" >> $@
version_strings: $(VERSION_STRINGS)
$(VERSION_STRINGS):
......@@ -77,7 +82,7 @@ $(VERSION_STRINGS):
@echo " */" >> $@
@echo "#include \"minipro.h\"" >> $@
@echo "#include \"version.h\"" >> $@
@echo "const char build_timestamp[] = \"$(BUILD_DATE_TIME)\";" >> $@
@echo "const char build_timestamp[] = \"$(BUILD_DATE)\";" >> $@
minipro: $(VERSION_HEADER) $(VERSION_STRINGS) $(COMMON_OBJECTS) main.o
$(CC) $(COMMON_OBJECTS) main.o $(LIBS) -o $(MINIPRO)
......@@ -87,7 +92,7 @@ clean:
rm -f version.h version.c version.o
distclean: clean
rm -rf minipro-$(GIT_TAG)*
rm -rf $(NAME)-$(GIT_TAG)*
install:
mkdir -p $(BIN_INSTDIR)
......@@ -101,15 +106,13 @@ uninstall:
rm -f $(BIN_INSTDIR)/$(MINIPROHEX)
rm -f $(MAN_INSTDIR)/minipro.1
dist: distclean version-info
git archive --format=tar --prefix=minipro-$(GIT_TAG)/ HEAD | tar xf -
sed -i "s/GIT_BRANCH = none/GIT_BRANCH = $(GIT_BRANCH)/" minipro-$(GIT_TAG)/Makefile
sed -i "s/GIT_HASH = none/GIT_HASH = $(GIT_HASH)/" minipro-$(GIT_TAG)/Makefile
sed -i "s/GIT_HASH_SHORT = none/GIT_HASH_SHORT = $(GIT_HASH_SHORT)/" minipro-$(GIT_TAG)/Makefile
sed -i "s/GIT_TAG = none/GIT_TAG = $(GIT_TAG)/" minipro-$(GIT_TAG)/Makefile
tar zcf minipro-$(GIT_TAG).tar.gz minipro-$(GIT_TAG)
rm -rf minipro-$(GIT_TAG)
dist:
ifneq ($(and $(wildcard $(GIT_DIR)),$(shell which git)),)
git archive --format=tgz --prefix $(NAME)-$(VERSION)/ HEAD -o $(NAME)-$(VERSION).tar.gz
@echo Created minipro-$(GIT_TAG).tar.gz
else
@echo "Not in a git repository or git command not found. Cannot make a tarball."
endif
.PHONY: all dist distclean clean install test version-info
......@@ -57,12 +57,11 @@ struct
void print_version_and_exit(uint32_t rv)
{
char output[] = "minipro version %s A free and open TL866XX programmer\n"
"Build:\t\t%s\n"
"Build date:\t%s\n"
"Commit date:\t%s\n"
"Git commit:\t%s\n"
"Git tag:\t%s\n"
"Git branch:\t%s\n";
fprintf(rv ? stderr : stdout, output, GIT_TAG, build_timestamp, GIT_HASH,
GIT_TAG, GIT_BRANCH);
fprintf(rv ? stderr : stdout, output, VERSION, build_timestamp, GIT_DATE, GIT_HASH, GIT_BRANCH);
exit(rv);
}
......@@ -93,7 +92,7 @@ void print_help_and_exit(char *progname, uint32_t rv)
" -V Show version information\n"
" -t Start hardware check\n"
" -h Show help (this text)\n";
fprintf(rv ? stderr : stdout, usage, GIT_TAG, basename(progname));
fprintf(rv ? stderr : stdout, usage, VERSION, basename(progname));
exit(rv);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment