-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.in
184 lines (147 loc) · 6.2 KB
/
Makefile.in
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!@make_bin@ -f
#############################
### The local directories ###
#############################
local_mandir = man
local_bindir = bin
local_datarootdir = share
local_localedir = locale
local_includedir = include
############################################################
### get all the ./configure arguments into this Makefile ###
############################################################
makefile_include:=@makefile_include@
makefile_include_local_path:=$(local_includedir)/@PACKAGE_NAME@/$(makefile_include)
include $(makefile_include_local_path)
# install directory paths from configure
configure_dirs = $(filter %dir,$(configure_vars))
# executable paths from configure
configure_bins = $(filter %_bin,$(configure_vars))
# corresponding local directories
local_dirs = $(foreach directory,$(configure_dirs),$(local_$(directory)))
# merge DESTDIR from dpkg-buildpackage into paths
$(foreach configure_dir,$(configure_dirs),\
$(eval $(configure_dir) := $(abspath $(DESTDIR)/$($(configure_dir)))))
installed_files_file = installed_files.tmp
# all markdown manpages
MDMANPAGES = $(shell $(find_bin) $(local_mandir) -type f -iname '*.1.md')
# corresponding groff manpages
GFMANPAGES = $(MDMANPAGES:.1.md=.1)
local_system_uca_dir = $(local_datarootdir)/$(PACKAGE_NAME)/system-uca
UCA_XML_FILES_M4 = $(wildcard $(local_system_uca_dir)/*.xml.m4 )
UCA_XML_FILES = $(UCA_XML_FILES_M4:.m4=)
# m4
M4_INCL = m4
tuca_include_m4 = $(M4_INCL)/tuca.m4
# pandoc options for manpage creation
PANDOCOPTS = -f markdown -t man --standalone
IN_FILES = $(shell $(find_bin) $(local_dirs) $(M4_INCL) -type f -iname '*.in' -not -name '$(notdir $(makefile_include_local_path))*')
IN_FILES_INSTANTIATED = $(IN_FILES:.in=)
CONFIGURE_AC = configure.ac
CONFIGURE = configure
# get information from changelog
DEBIAN = $(wildcard debian)
DEBIAN_CHANGELOG = $(DEBIAN)/changelog
DEBIAN_CHANGELOG_VERSION = $(shell $(perl_bin) -ne 'if(s/^$(PACKAGE_NAME)\s*\((.*?)\).*$$/$$1/g){print;exit}' $(DEBIAN_CHANGELOG))
only_uca_cmd_file = $(local_localedir)/tmp_only_uca_commands.sh
# all pofiles
POFILES = $(shell find $(local_localedir) -type f -iname '*.po')
# the corresponding mofiles
MOFILES = $(POFILES:.po=.mo)
# temporary pot-file template
POTFILE = $(local_localedir)/$(PACKAGE_NAME).pot
# default target
.PHONY: all
all: $(MOFILES) $(IN_FILES_INSTANTIATED) $(UCA_XML_FILES) $(CONFIGURE) \
$(CONFIGURE_AC) $(GFMANPAGES)
%: %.m4 $(tuca_include_m4) $(wildcard $(M4_INCL)/*.m4)
$(m4_bin) -I $(M4_INCL) $< > $@
# create rule to install a FILE into the TARGET_DIRECTORY
# FILE can be a relative path from here
# $(call install_rule,FILE,TARGET_DIRECTORY)
define install_rule
$$(eval _target = $$(abspath $$(addprefix $(2)/,$$(shell echo $(1) | $(perl_bin) -pe 's|^[^/]*/+||g'))))
$$(_target): $(1) | $$(dir $$(_target))
cp -L --preserve=all $$< $$@
@echo $$@ >> $(installed_files_file)
$$(eval install_target_dirs = $$(install_target_dirs) $$(dir $$(_target)))
$$(eval install_targets = $$(install_targets) $$(_target))
endef
find_opts = -not -type d -not -iname '*.in' -not -iname '.gitignore'
# define the local content that is to install
local_datarootdir_toinstall = $(shell $(find_bin) $(local_datarootdir) $(find_opts) -not -iname '*.m4')
local_mandir_toinstall = $(GFMANPAGES)
local_localedir_toinstall = $(MOFILES)
local_bindir_toinstall = $(shell $(find_bin) $(local_bindir) $(find_opts))
local_includedir_toinstall = $(shell $(find_bin) $(local_includedir) $(find_opts))
# set up install rules for all configure directories
$(foreach configure_dir,$(configure_dirs),\
$(foreach file,$(local_$(configure_dir)_toinstall),\
$(eval $(call install_rule,$(file),$($(configure_dir))))))
# build the manpages
# manpages:
%.1: %.1.md $(DEBIAN_CHANGELOG)
$(pandoc_bin) $(PANDOCOPTS) -Vfooter='Version $(PACKAGE_VERSION)' -o $@ $<
$(sort $(install_target_dirs)): % :
mkdir -p $@
@echo $@ >> $(installed_files_file)
$(CONFIGURE): $(CONFIGURE_AC)
-autoconf
$(CONFIGURE_AC): $(DEBIAN_CHANGELOG)
$(perl_bin) -pi -e 's#^(\s*AC_INIT\([^,]*,\s*\[)([.0-9_a-zA-Z-]+)(\]\s*,.*\))#$${1}$(DEBIAN_CHANGELOG_VERSION)$${3}#g' $@
# substitute variables in a file
$(IN_FILES_INSTANTIATED): % : %.in Makefile
$(perl_bin) -pe '$(foreach var,$(configure_vars),s#[@]$(var)[@]#$($(var))#g;)' < $< > $@
### translations ###
$(only_uca_cmd_file): $(UCA_XML_FILES) | $(patsubst %/,%,$(dir $(only_uca_cmd_file)))
cat $^ | $(perl_bin) -ne 'print if s#<command[^>]*>\s*(.*?)\s*</command>#$$1#g' > $@
# create the pot-file with all translatable strings from the srcfiles
$(POTFILE): $(only_uca_cmd_file)
$(xgettext_bin) -L Shell -o $@ $^
# update the translated catalog
%.po: $(POTFILE)
VERSION_CONTROL=off $(msgmerge_bin) -U --backup=off $@ $<
touch $@ # make sure timestamp was updated
# compile the translations
%.mo: %.po
$(msgfmt_bin) -o $@ $<
.PHONY: bin_executable
bin_executable: $(local_bindir_toinstall)
for file in $^;do chmod +x $$file;done
.PHONY: install
.PHONY: $(install_targets)
install: bin_executable $(sort $(install_targets))
-@sort -u $(installed_files_file) -o $(installed_files_file)
@echo "##################################"
@echo "### Installation completed. ###"
@echo "### run 'uca-apply update' ###"
@echo "### to merge the actions ###"
@echo "### into your configuration ###"
@echo "##################################"
# remove a file/folder without asking
# $(call remove,PATH)
# This is only to display a newline after the command
define remove
rm -rf $(1)
endef
.PHONY: uninstall
uninstall:
$(foreach file,$(sort $(install_targets) $(shell cat $(installed_files_file))),$(call remove,$(file)))
rm -f $(installed_files_file)
@echo WARNING: There might still be some empty folders left. This should not be a problem.
.PHONY: clean
clean:
rm -f $(IN_FILES_INSTANTIATED) # instantiated files
rm -f $(UCA_XML_FILES) # instantiated uca xml files
rm -f $(only_uca_cmd_file)
rm -f $(GFMANPAGES) # manpages
rm -f $(MOFILES) $(POTFILE) # translations
.PHONY: debclean
debclean:
rm -rf $(addprefix $(DEBIAN)/,files *.substvars *.debhelper $(PACKAGE_NAME) debhelper-build-stamp *.debhelper.log)
.PHONY: distclean
distclean: clean debclean
rm -f $(makefile_include_local_path)*
rm -f config.status config.log # configure output
rm -rf auto*.cache/
rm -f Makefile # this Makefile itself