Skip to content

Commit ec69256

Browse files
committed
[BUILD] centralize version and date into one file for each
The version does not appear anymore in the Makefiles nor in the include files. It was a nightmare to maintain. Now there is a VERSION file which contains the major version, a VERDATE file which contains the date for this version and a SUBVERS file which may contain a sub-version. A "make version" target has been added to all makefiles to check the version. The GNU Makefile also has an update-version target to update those files. This should never be used. It is still possible to override those values by specifying them in the equivalent make variables. By default, the GNU makefile tries to detect a GIT repository and always uses the version and date from the current repository. This can be disabled by setting IGNOREGIT to a non-void value.
1 parent 031a26b commit ec69256

File tree

7 files changed

+63
-19
lines changed

7 files changed

+63
-19
lines changed

Makefile

+28-7
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,24 @@ DEFINE = -DTPROXY
113113
# Now let's determine the version, sub-version and release date.
114114
# If we're in the GIT tree, we can use the last commit's version and date.
115115
ifeq ($(IGNOREGIT),)
116-
VERSION := $(shell [ -d .git/. ] && ref=`git-describe --tags 2>/dev/null` && ref=$${ref%-g*} && echo "$${ref\#v}" )
117-
endif
118-
116+
VERSION := $(shell [ -d .git/. ] && ref=`(git-describe --tags) 2>/dev/null` && ref=$${ref%-g*} && echo "$${ref\#v}")
119117
ifneq ($(VERSION),)
120118
# OK git is there and works.
121119
SUBVERS := $(shell comms=`git-log --no-merges v$(VERSION).. 2>/dev/null |grep -c ^commit `; [ $$comms -gt 0 ] && echo "-$$comms" )
122120
VERDATE := $(shell date +%Y/%m/%d -d "`git-log HEAD^.. 2>/dev/null | grep -m 1 ^Date: | cut -f2- -d: | cut -f1 -d+`" )
123-
else
121+
endif
122+
endif
123+
124124
# Otherwise, use the hard-coded version of last tag, number of changes
125125
# since last tag, and release date.
126-
VERSION := 1.3.12
127-
SUBVERS :=
128-
VERDATE := 2007/06/17
126+
ifeq ($(VERSION),)
127+
VERSION := $(shell cat VERSION 2>/dev/null || touch VERSION)
128+
endif
129+
ifeq ($(SUBVERS),)
130+
SUBVERS := $(shell cat SUBVERS 2>/dev/null || touch SUBVERS)
131+
endif
132+
ifeq ($(VERDATE),)
133+
VERDATE := $(shell cat VERDATE 2>/dev/null || touch VERDATE)
129134
endif
130135
131136
#### build options
@@ -256,3 +261,19 @@ tar: clean
256261
257262
git-tar: clean
258263
git-tar-tree HEAD haproxy-$(VERSION) | gzip -9 > haproxy-$(VERSION)$(SUBVERS).tar.gz
264+
265+
version:
266+
@echo "VERSION: $(VERSION)"
267+
@echo "SUBVERS: $(SUBVERS)"
268+
@echo "VERDATE: $(VERDATE)"
269+
270+
# never use this one if you don't know what it is used for.
271+
update-version:
272+
@echo "Ready to update the following versions :"
273+
@echo "VERSION: $(VERSION)"
274+
@echo "SUBVERS: $(SUBVERS)"
275+
@echo "VERDATE: $(VERDATE)"
276+
@echo "Press [ENTER] to continue or Ctrl-C to abort now.";read
277+
echo "$(VERSION)" > VERSION
278+
echo "$(SUBVERS)" > SUBVERS
279+
echo "$(VERDATE)" > VERDATE

Makefile.bsd

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
# make TARGET=freebsd CPU=i686 DLMALLOC_SRC=/usr/local/src/dlmalloc.c \
88
# OPT_OBJS=src/dlmalloc.o
99

10-
VERSION := 1.3.12
11-
1210
# Select target OS. TARGET must match a system for which COPTS and LIBS are
1311
# correctly defined below.
1412
TARGET = openbsd
@@ -87,10 +85,17 @@ TARGET_OPTS=$(COPTS.$(TARGET))
8785
REGEX_OPTS=$(COPTS.$(REGEX))
8886
CPU_OPTS=$(COPTS.$(CPU))
8987

90-
COPTS=-Iinclude $(ADDINC) $(CPU_OPTS) $(TARGET_OPTS) $(REGEX_OPTS) $(SMALL_OPTS) $(DEFINE)
91-
LIBS=$(LIBS.$(TARGET)) $(LIBS.$(REGEX)) $(ADDLIB)
88+
VERSION != cat VERSION 2>/dev/null || touch VERSION
89+
SUBVERS != cat SUBVERS 2>/dev/null || touch SUBVERS
90+
VERDATE != cat VERDATE 2>/dev/null || touch VERDATE
91+
92+
VER_OPTS := -DCONFIG_HAPROXY_VERSION=\"$(VERSION)$(SUBVERS)\" \
93+
-DCONFIG_HAPROXY_DATE=\"$(VERDATE)\"
9294

93-
CFLAGS = -Wall $(COPTS) $(DEBUG)
95+
COPTS = -Iinclude $(ADDINC) $(CPU_OPTS) $(TARGET_OPTS) $(REGEX_OPTS) \
96+
$(SMALL_OPTS) $(VER_OPTS) $(DEFINE)
97+
LIBS = $(LIBS.$(TARGET)) $(LIBS.$(REGEX)) $(ADDLIB)
98+
CFLAGS = -Wall $(COPTS) $(DEBUG)
9499
LDFLAGS = -g
95100

96101
OBJS = src/haproxy.o src/sessionhash.o src/base64.o \
@@ -118,3 +123,8 @@ clean:
118123
rm -f *.[oas] src/*.[oas] core haproxy test
119124
for dir in . src include/* doc; do rm -f $$dir/*~ $$dir/*.rej;done
120125
rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION) nohup.out gmon.out
126+
127+
version:
128+
@echo "VERSION: $(VERSION)"
129+
@echo "SUBVERS: $(SUBVERS)"
130+
@echo "VERDATE: $(VERDATE)"

Makefile.osx

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
# make DLMALLOC_SRC=/usr/local/src/dlmalloc.c \
88
# OPT_OBJS=src/dlmalloc.o
99

10-
VERSION := 1.3.12
11-
1210
# Select target OS. TARGET must match a system for which COPTS and LIBS are
1311
# correctly defined below.
1412
TARGET = generic
@@ -84,10 +82,17 @@ TARGET_OPTS=$(COPTS.$(TARGET))
8482
REGEX_OPTS=$(COPTS.$(REGEX))
8583
CPU_OPTS=$(COPTS.$(CPU))
8684

87-
COPTS=-Iinclude $(ADDINC) $(CPU_OPTS) $(TARGET_OPTS) $(REGEX_OPTS) $(SMALL_OPTS) $(DEFINE)
88-
LIBS=$(LIBS.$(TARGET)) $(LIBS.$(REGEX)) $(ADDLIB)
85+
VERSION != cat VERSION 2>/dev/null || touch VERSION
86+
SUBVERS != cat SUBVERS 2>/dev/null || touch SUBVERS
87+
VERDATE != cat VERDATE 2>/dev/null || touch VERDATE
88+
89+
VER_OPTS := -DCONFIG_HAPROXY_VERSION=\"$(VERSION)$(SUBVERS)\" \
90+
-DCONFIG_HAPROXY_DATE=\"$(VERDATE)\"
8991

90-
CFLAGS = -Wall $(COPTS) $(DEBUG) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386
92+
COPTS = -Iinclude $(ADDINC) $(CPU_OPTS) $(TARGET_OPTS) $(REGEX_OPTS) \
93+
$(SMALL_OPTS) $(VER_OPTS) $(DEFINE)
94+
LIBS = $(LIBS.$(TARGET)) $(LIBS.$(REGEX)) $(ADDLIB)
95+
CFLAGS = -Wall $(COPTS) $(DEBUG) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386
9196
LDFLAGS = -g -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386
9297

9398
OBJS = src/haproxy.o src/sessionhash.o src/base64.o \
@@ -115,3 +120,8 @@ clean:
115120
rm -f *.[oas] src/*.[oas] core haproxy test
116121
for dir in . src include/* doc; do rm -f $$dir/*~ $$dir/*.rej;done
117122
rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION) nohup.out gmon.out
123+
124+
version:
125+
@echo "VERSION: $(VERSION)"
126+
@echo "SUBVERS: $(SUBVERS)"
127+
@echo "VERDATE: $(VERDATE)"

SUBVERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

VERDATE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2007/06/17

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.3.12

include/common/version.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
#ifdef CONFIG_HAPROXY_VERSION
5858
#define HAPROXY_VERSION CONFIG_HAPROXY_VERSION
5959
#else
60-
#define HAPROXY_VERSION "1.3.12"
60+
#error "Must define CONFIG_HAPROXY_VERSION"
6161
#endif
6262

6363
#ifdef CONFIG_HAPROXY_DATE
6464
#define HAPROXY_DATE CONFIG_HAPROXY_DATE
6565
#else
66-
#define HAPROXY_DATE "2007/06/17"
66+
#error "Must define CONFIG_HAPROXY_DATE"
6767
#endif
6868

6969
#endif /* _COMMON_VERSION_H */

0 commit comments

Comments
 (0)