Skip to content

Commit acc8a9e

Browse files
author
Sebastien Varrette
committed
Initialize root Makefile for the repo
Signed-off-by: Sebastien Varrette <[email protected]>
1 parent 8f0aaac commit acc8a9e

File tree

1 file changed

+257
-0
lines changed

1 file changed

+257
-0
lines changed

Makefile

+257
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
####################################################################################
2+
# Makefile (configuration file for GNU make - see http://www.gnu.org/software/make/)
3+
# Time-stamp: <Jeu 2015-04-02 10:28 svarrette>
4+
# __ __ _ __ _ _
5+
# | \/ | __ _| | _____ / _(_) | ___
6+
# | |\/| |/ _` | |/ / _ \ |_| | |/ _ \
7+
# | | | | (_| | < __/ _| | | __/
8+
# |_| |_|\__,_|_|\_\___|_| |_|_|\___|
9+
#
10+
# Copyright (c) 2012 Sebastien Varrette <[email protected]>
11+
# . http://varrette.gforge.uni.lu
12+
#
13+
####################################################################################
14+
#
15+
############################## Variables Declarations ##############################
16+
SHELL = /bin/bash
17+
18+
UNAME = $(shell uname)
19+
20+
# Some directories
21+
SUPER_DIR = $(shell basename `pwd`)
22+
23+
# Git stuff management
24+
HAS_GITFLOW = $(shell git flow version 2>/dev/null || [ $$? -eq 0 ])
25+
LAST_TAG_COMMIT = $(shell git rev-list --tags --max-count=1)
26+
LAST_TAG = $(shell git describe --tags $(LAST_TAG_COMMIT) )
27+
TAG_PREFIX = "v"
28+
# GITFLOW_BR_MASTER = $(shell git config --get gitflow.branch.master)
29+
# GITFLOW_BR_DEVELOP = $(shell git config --get gitflow.branch.develop)
30+
GITFLOW_BR_MASTER=production
31+
GITFLOW_BR_DEVELOP=master
32+
33+
CURRENT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
34+
GIT_REMOTES = $(shell git remote | xargs echo )
35+
GIT_DIRTY = $(shell git diff --shortstat 2> /dev/null | tail -n1 )
36+
# Git subtrees repositories
37+
# Format: '<url>[|<branch>]' - don't forget the quotes. if branch is ignored, 'master' is used
38+
#GIT_SUBTREE_REPOS = 'https://github.com/ULHPC/easybuild-framework.git|develop' \
39+
'https://github.com/hpcugent/easybuild-wiki.git'
40+
GITSTATS = ./.submodules/gitstats/gitstats
41+
GITSTATS_DIR = gitstats
42+
43+
VERSION = $(shell [ -f VERSION ] && head VERSION || echo "0.0.1")
44+
# OR try to guess directly from the last git tag
45+
#VERSION = $(shell git describe --tags $(LAST_TAG_COMMIT) | sed "s/^$(TAG_PREFIX)//")
46+
MAJOR = $(shell echo $(VERSION) | sed "s/^\([0-9]*\).*/\1/")
47+
MINOR = $(shell echo $(VERSION) | sed "s/[0-9]*\.\([0-9]*\).*/\1/")
48+
PATCH = $(shell echo $(VERSION) | sed "s/[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/")
49+
# total number of commits
50+
BUILD = $(shell git log --oneline | wc -l | sed -e "s/[ \t]*//g")
51+
52+
#REVISION = $(shell git rev-list $(LAST_TAG).. --count)
53+
#ROOTDIR = $(shell git rev-parse --show-toplevel)
54+
NEXT_MAJOR_VERSION = $(shell expr $(MAJOR) + 1).0.0-b$(BUILD)
55+
NEXT_MINOR_VERSION = $(MAJOR).$(shell expr $(MINOR) + 1).0-b$(BUILD)
56+
NEXT_PATCH_VERSION = $(MAJOR).$(MINOR).$(shell expr $(PATCH) + 1)-b$(BUILD)
57+
58+
# Default targets
59+
TARGETS =
60+
61+
# Local configuration - Kept for compatibity reason
62+
LOCAL_MAKEFILE = .Makefile.local
63+
64+
# Makefile custom hooks
65+
MAKEFILE_BEFORE = .Makefile.before
66+
MAKEFILE_AFTER = .Makefile.after
67+
68+
### Main variables
69+
.PHONY: all archive clean fetch help release setup start_bump_major start_bump_minor start_bump_patch subtree_setup subtree_up subtree_diff test upgrade versioninfo
70+
71+
############################### Now starting rules ################################
72+
# Load local settings, if existing (to override variable eventually)
73+
ifneq (,$(wildcard $(LOCAL_MAKEFILE)))
74+
include $(LOCAL_MAKEFILE)
75+
endif
76+
ifneq (,$(wildcard $(MAKEFILE_BEFORE)))
77+
include $(MAKEFILE_BEFORE)
78+
endif
79+
80+
# Required rule : what's to be done each time
81+
all: $(TARGETS)
82+
83+
# Test values of variables - for debug purposes
84+
test:
85+
@echo "--- Compilation commands --- "
86+
@echo "HAS_GITFLOW -> '$(HAS_GITFLOW)'"
87+
@echo "--- Directories --- "
88+
@echo "SUPER_DIR -> '$(SUPER_DIR)'"
89+
@echo "--- Git stuff ---"
90+
@echo "GITFLOW -> '$(GITFLOW)'"
91+
@echo "GITFLOW_BR_MASTER -> '$(GITFLOW_BR_MASTER)'"
92+
@echo "GITFLOW_BR_DEVELOP -> '$(GITFLOW_BR_DEVELOP)'"
93+
@echo "CURRENT_BRANCH -> '$(CURRENT_BRANCH)'"
94+
@echo "GIT_REMOTES -> '$(GIT_REMOTES)'"
95+
@echo "GIT_DIRTY -> '$(GIT_DIRTY)'"
96+
@echo "GIT_SUBTREE_REPOS -> '$(GIT_SUBTREE_REPOS)'"
97+
@echo ""
98+
@echo "Consider running 'make versioninfo' to get info on git versionning variables"
99+
100+
############################### Archiving ################################
101+
archive: clean
102+
tar -C ../ -cvzf ../$(SUPER_DIR)-$(VERSION).tar.gz --exclude ".svn" --exclude ".git" --exclude "*~" --exclude ".DS_Store" $(SUPER_DIR)/
103+
104+
############################### Git Bootstrapping rules ################################
105+
setup:
106+
git fetch origin
107+
git branch --set-upstream $(GITFLOW_BR_MASTER) origin/$(GITFLOW_BR_MASTER)
108+
git config gitflow.branch.master $(GITFLOW_BR_MASTER)
109+
git config gitflow.branch.develop $(GITFLOW_BR_DEVELOP)
110+
git config gitflow.prefix.feature feature/
111+
git config gitflow.prefix.release release/
112+
git config gitflow.prefix.hotfix hotfix/
113+
git config gitflow.prefix.support support/
114+
git config gitflow.prefix.versiontag $(TAG_PREFIX)
115+
$(MAKE) update
116+
$(if $(GIT_SUBTREE_REPOS), $(MAKE) subtree_setup)
117+
118+
fetch:
119+
git fetch --all -v
120+
121+
versioninfo:
122+
@echo "Current version: $(VERSION)"
123+
@echo "Last tag: $(LAST_TAG)"
124+
@echo "$(shell git rev-list $(LAST_TAG).. --count) commit(s) since last tag"
125+
@echo "Build: $(BUILD) (total number of commits)"
126+
@echo "next major version: $(NEXT_MAJOR_VERSION)"
127+
@echo "next minor version: $(NEXT_MINOR_VERSION)"
128+
@echo "next patch version: $(NEXT_PATCH_VERSION)"
129+
130+
### Git flow management - this should be factorized
131+
ifeq ($(HAS_GITFLOW),)
132+
start_bump_patch start_bump_minor start_bump_major release:
133+
@echo "Unable to find git-flow on your system. "
134+
@echo "See https://github.com/nvie/gitflow for installation details"
135+
else
136+
start_bump_patch: clean
137+
@echo "Start the patch release of the repository from $(VERSION) to $(NEXT_PATCH_VERSION)"
138+
git pull origin
139+
git flow release start $(NEXT_PATCH_VERSION)
140+
@echo $(NEXT_PATCH_VERSION) > VERSION
141+
git commit -s -m "Patch bump to version $(NEXT_PATCH_VERSION)" VERSION
142+
@echo "=> remember to update the version number in $(MAIN_TEX)"
143+
@echo "=> run 'make release' once you finished the bump"
144+
145+
start_bump_minor: clean
146+
@echo "Start the minor release of the repository from $(VERSION) to $(NEXT_MINOR_VERSION)"
147+
git pull origin
148+
git flow release start $(NEXT_MINOR_VERSION)
149+
@echo $(NEXT_MINOR_VERSION) > VERSION
150+
git commit -s -m "Minor bump to version $(NEXT_MINOR_VERSION)" VERSION
151+
@echo "=> remember to update the version number in $(MAIN_TEX)"
152+
@echo "=> run 'make release' once you finished the bump"
153+
154+
start_bump_major: clean
155+
@echo "Start the major release of the repository from $(VERSION) to $(NEXT_MAJOR_VERSION)"
156+
git pull origin
157+
git flow release start $(NEXT_MAJOR_VERSION)
158+
@echo $(NEXT_MAJOR_VERSION) > VERSION
159+
git commit -s -m "Major bump to version $(NEXT_MAJOR_VERSION)" VERSION
160+
@echo "=> remember to update the version number in $(MAIN_TEX)"
161+
@echo "=> run 'make release' once you finished the bump"
162+
163+
release: clean
164+
git flow release finish -s $(VERSION)
165+
git checkout $(GITFLOW_BR_MASTER)
166+
git push origin
167+
git checkout $(GITFLOW_BR_DEVELOP)
168+
git push origin
169+
git push origin --tags
170+
endif
171+
172+
### Git submodule management: upgrade to the latest version
173+
update:
174+
git submodule init
175+
git submodule update
176+
177+
upgrade: update
178+
git submodule foreach 'git fetch origin; git checkout $$(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'
179+
@for submoddir in $(shell git submodule status | awk '{ print $$2 }' | xargs echo); do \
180+
git commit -s -m "Upgrading Git submodule '$$submoddir' to the latest version" $$submoddir ;\
181+
done
182+
183+
184+
### Git subtree management
185+
ifeq ($(GIT_SUBTREE_REPOS),)
186+
subtree_setup subtree_diff subtree_up:
187+
@echo "no repository configured in GIT_SUBTREE_REPOS..."
188+
else
189+
subtree_setup:
190+
@for elem in $(GIT_SUBTREE_REPOS); do \
191+
url=`echo $$elem | cut -d '|' -f 1`; \
192+
repo=`basename $$url .git`; \
193+
if [[ ! "$(GIT_REMOTES)" =~ "$$repo" ]]; then \
194+
echo "=> initializing Git remote '$$repo'"; \
195+
git remote add -f $$repo $$url; \
196+
fi \
197+
done
198+
199+
subtree_diff:
200+
@for elem in $(GIT_SUBTREE_REPOS); do \
201+
url=`echo $$elem | cut -d '|' -f 1`; \
202+
repo=`basename $$url .git`; \
203+
path=`echo $$repo | tr '-' '/'`; \
204+
br=`echo $$elem | cut -d '|' -f 2`; \
205+
[ "$$br" == "$$url" ] && br='master'; \
206+
echo -e "\n============ diff on subtree '$$path' with remote '$$repo/$$br' ===========\n"; \
207+
git diff $${repo}/$$br $(CURRENT_BRANCH):$$path; \
208+
done
209+
210+
subtree_up:
211+
$(if $(GIT_DIRTY), $(error "Unable to pull subtree(s): Dirty Git repository"))
212+
@for elem in $(GIT_SUBTREE_REPOS); do \
213+
url=`echo $$elem | cut -d '|' -f 1`; \
214+
repo=`basename $$url .git`; \
215+
path=`echo $$repo | tr '-' '/'`; \
216+
br=`echo $$elem | cut -d '|' -f 2`; \
217+
[ "$$br" == "$$url" ] && br='master'; \
218+
echo -e "\n===> pulling changes into subtree '$$path' using remote '$$repo/$$br'"; \
219+
echo -e " \__ fetching remote '$$repo'"; \
220+
git fetch $$repo; \
221+
echo -e " \__ pulling changes"; \
222+
git subtree pull --prefix $$path --squash $${repo} $${br}; \
223+
done
224+
endif
225+
226+
227+
# Clean option
228+
clean:
229+
@echo nothing to be cleaned for the moment
230+
231+
232+
# Perform various git statistics
233+
stats:
234+
@if [ ! -d $(GITSTATS_DIR) ]; then mkdir -p $(GITSTATS_DIR); fi
235+
$(GITSTATS) . $(GITSTATS_DIR)/
236+
237+
# # force recompilation
238+
# force :
239+
# @touch $(MAIN_TEX)
240+
# @$(MAKE)
241+
242+
243+
# print help message
244+
help :
245+
@echo '+----------------------------------------------------------------------+'
246+
@echo '| Available Commands |'
247+
@echo '+----------------------------------------------------------------------+'
248+
@echo '| make setup: Initiate git-flow for your local copy of the repository|'
249+
@echo '| make start_bump_{major,minor,patch}: start a new version release with|'
250+
@echo '| git-flow at a given level (major, minor or patch bump) |'
251+
@echo '| make release: Finalize the release using git-flow |'
252+
@echo '+----------------------------------------------------------------------+'
253+
254+
ifneq (,$(wildcard $(MAKEFILE_AFTER)))
255+
include $(MAKEFILE_AFTER)
256+
endif
257+

0 commit comments

Comments
 (0)