1BUILD_OPTIONS=-DCMAKE_BUILD_TYPE=Debug
2
3ifeq '$(findstring ;,$(PATH))' ';'
4    UNAME := Windows
5else
6    UNAME := $(shell uname 2>/dev/null || echo Unknown)
7    UNAME := $(patsubst CYGWIN%,Cygwin,$(UNAME))
8    UNAME := $(patsubst MSYS%,MSYS,$(UNAME))
9    UNAME := $(patsubst MINGW%,MSYS,$(UNAME))
10endif
11
12ifeq ($(UNAME),MSYS)
13	BUILD_OPTIONS+= -G "MSYS Makefiles"
14endif
15
16# If the variable USE_SYSTEM_LIBGIT2 is set to *any* value, use the
17# system provided libgit2 library.
18USE_SYSTEM_LIBGIT2? := \
19	$(if $(or $(USE_SYSTEM_LIBGIT2),\
20	 	  $(findstring USE_SYSTEM_LIBGIT2,$(BUILD_OPTIONS))),\
21		true)
22
23ifeq "$(TRAVIS)" "true"
24## Makefile for Travis ###################################################
25#
26#  TODO Move this to a separate file ".travis.mk" once Emake supports
27#  that.  (Apparently it already does, but I couldn't get it to work.)
28
29EMAKE_SHA1       ?= 1b23379eb5a9f82d3e2d227d0f217864e40f23e0
30PACKAGE_BASENAME := libgit
31
32include emake.mk
33
34build/libegit2.so:
35	git submodule update --init
36	mkdir -p build
37	cd build && cmake .. $(BUILD_OPTIONS) && make
38
39test: EMACS_ARGS += -L build/ -l libegit2
40test: build/libegit2.so test-ert
41
42else
43## Makefile for local use ################################################
44
45-include .config.mk
46
47PKG = libgit
48
49ELS  = $(PKG).el
50ELCS = $(ELS:.el=.elc)
51
52EMACS      ?= emacs
53EMACS_ARGS ?=
54
55LOAD_PATH  ?= -L . -L build
56
57.PHONY: test libgit2 submodule-update
58
59all: lisp
60
61help:
62	$(info make all               - build everything)
63	$(info make module            - generate module)
64	$(info make lisp              - generate byte-code and autoloads)
65	$(info make submodule-init    - update the submodule)
66	$(info make submodule-update  - update the submodule)
67	$(info make test              - run tests)
68	$(info make clean             - remove generated files)
69	@printf "\n"
70
71module: build/libegit2.so
72
73build/libegit2.so: libgit2
74	@printf "Building $<\n"
75	@mkdir -p build
76	@cd build && cmake .. $(BUILD_OPTIONS) && make
77
78lisp: $(ELCS) loaddefs module
79
80loaddefs: $(PKG)-autoloads.el
81
82%.elc: %.el
83	@printf "Compiling $<\n"
84	@$(EMACS) -Q --batch $(EMACS_ARGS) $(LOAD_PATH) -f batch-byte-compile $<
85
86test: libgit.elc build/libegit2.so
87	$(EMACS) -Q --batch $(LOAD_PATH) -l libgit \
88	  $(addprefix -l test/,$(shell ls test)) \
89	  -f ert-run-tests-batch-and-exit
90
91submodule-init: libgit2
92
93submodule-update:
94	@git submodule update
95
96libgit2:
97ifeq ($(USE_SYSTEM_LIBGIT2?),)
98	@git submodule update --init
99else
100	@echo "Using the system provided libgit2 library"
101endif
102
103CLEAN  = $(ELCS) $(PKG)-autoloads.el build
104
105clean:
106	@printf "Cleaning...\n"
107	@rm -rf $(CLEAN)
108
109define LOADDEFS_TMPL
110;;; $(PKG)-autoloads.el --- automatically extracted autoloads
111;;
112;;; Code:
113(add-to-list 'load-path (directory-file-name \
114(or (file-name-directory #$$) (car load-path))))
115
116;; Local Variables:
117;; version-control: never
118;; no-byte-compile: t
119;; no-update-autoloads: t
120;; End:
121;;; $(PKG)-autoloads.el ends here
122endef
123export LOADDEFS_TMPL
124#'
125
126$(PKG)-autoloads.el: $(ELS)
127	@printf "Generating $@\n"
128	@printf "%s" "$$LOADDEFS_TMPL" > $@
129	@$(EMACS) -Q --batch --eval "(progn\
130	(setq make-backup-files nil)\
131	(setq vc-handled-backends nil)\
132	(setq default-directory (file-truename default-directory))\
133	(setq generated-autoload-file (expand-file-name \"$@\"))\
134	(setq find-file-visit-truename t)\
135	(update-directory-autoloads default-directory))"
136
137endif
138