summaryrefslogtreecommitdiffstats
path: root/t/templates/source-make-builder/Makefile.in
blob: f52752343b38094554414b0e50de0af74b6f27d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

name = [% $source %]
version = [% $upstream_version %]
type = [% $type %]

packagedir = $(name)-$(version)
underscored = $(name)_$(version)

origdata = $(ROOT_DIR)/orig
origstem = $(underscored).orig

debiandata = $(ROOT_DIR)/debian

formatfile = $(debiandata)/source/format

watchfile = $(packagedir)/debian/watch

post_clean = $(ROOT_DIR)/post-clean
pre_orig = $(ROOT_DIR)/pre-orig
tar_orig = $(ROOT_DIR)/tar-orig
pre_build = $(ROOT_DIR)/pre-build
post_build = $(ROOT_DIR)/post-build

product = [% $build_product %]

ifneq (,$(wildcard $(ROOT_DIR)/dpkg-overrides))
dpkgoverrides = $(shell cat $(ROOT_DIR)/dpkg-overrides)
endif

ifeq ($(type),native)
dpkgoptions = -sn
else
dpkgoptions = -sp
endif

.DEFAULT_GOAL := $(product)

$(product):
	-mkdir -p $(packagedir)
	if [ -x $(post_clean) ] ; then \
		$(post_clean) $(packagedir) ; \
	fi

	mkdir $(origdata) || true
	cp -rp $(origdata)/. $(packagedir)

	if [ "[% $type %]" != "native" ] ; then \
		if [ -x $(pre_orig) ] ; then \
			$(pre_orig) $(shell realpath $(packagedir)) ; \
		fi ; \
		if [ -x $(tar_orig) ] ; then \
			$(tar_orig) $(origstem) $(packagedir) ; \
		fi ; \
		if [ -f $(formatfile) ] && grep --quiet "^3\.. (quilt)$$" $(formatfile) ; then \
			rm -rf $(packagedir)/debian ; \
		fi ; \
	fi

	-mkdir -p $(packagedir)/debian
	if [ -d $(debiandata) ] ; then \
		cp -rp $(debiandata)/. $(packagedir)/debian ; \
	fi
	if [ "[% $type %]" != "native" ] ; then \
		if [ ! -f $(watchfile) ] ; then \
			echo '# Empty watch file' > $(watchfile) ; \
		fi ; \
	fi

	if [ -x $(pre_build) ] ; then \
		$(pre_build) $(shell realpath $(packagedir)) ; \
	fi
	if [ -f $(formatfile) ] && grep --quiet "^3\.. (quilt)$$" $(formatfile) ; then \
		dpkg-source $(dpkgoverrides) -b $(packagedir) ; \
	else \
		dpkg-source $(dpkgoverrides) $(dpkgoptions) -b $(packagedir) ; \
	fi
	if [ -x $(post_build) ] ; then \
		$(post_build) $(product) ; \
	fi


.PHONY: clean
clean:
	rm -rf $(packagedir)
	rm -f $(underscored)*