summaryrefslogtreecommitdiffstats
path: root/Rules.mk
blob: 4329bae10bf22528b6662846e08a7020ef6054c6 (plain) (blame)
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# -*- Makefile -*-
# Rules for building and creating the version file

VERSION_FILE = version.h
# There's only one line in $(VERSION_FILE); use the shell builtin `read'
STORED_VERSION_STRING = \
	$(subst ",,$(shell [ ! -r $(VERSION_FILE) ] || \
			   read ignore ignore v <$(VERSION_FILE) && echo $$v))
#" workaround editor syntax highlighting quirk

GET_VERSION = ./scripts/get-version
VERSION_STRING := $(shell $(GET_VERSION) linux || echo "v$(VERSION)")
# Mac Info.plist style with three numbers 1.2.3
CFBUNDLEVERSION_STRING := $(shell $(GET_VERSION) darwin $(VERSION_STRING) || \
	echo "$(VERSION).0")
# Windows .nsi style with four numbers 1.2.3.4
PRODVERSION_STRING := $(shell $(GET_VERSION) win $(VERSION_STRING) || \
	echo "$(VERSION).0.0")

MSGOBJS=$(addprefix share/locale/,$(MSGLANGS:.po=.UTF-8/LC_MESSAGES/$(NAME).mo))

ifeq ($(V),1)
	PRETTYECHO=true
	COMPILE_PREFIX=
else
	PRETTYECHO=echo
	COMPILE_PREFIX=@
endif

C_SOURCES = $(filter %.c, $(SOURCES))
CXX_SOURCES = $(filter %.cpp, $(SOURCES)) $(RESOURCES:.qrc=.qrc.cpp)
OTHER_SOURCES = $(filter-out %.c %.cpp, $(SOURCES))
OBJS = $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o) $(OTHER_SOURCES)

# Add the objects for the header files which define QObject subclasses
HEADERS_NEEDING_MOC += $(shell grep -l -s 'Q_OBJECT' $(HEADERS))
MOC_OBJS = $(HEADERS_NEEDING_MOC:.h=.moc.o)

ALL_OBJS = $(OBJS) $(MOC_OBJS)

# Files for using Qt Creator
CREATOR_FILES = $(NAME).config $(NAME).creator $(NAME).files $(NAME).includes

all: $(TARGET) doc

$(TARGET): gen_version_file $(ALL_OBJS) $(MSGOBJS) $(INFOPLIST)
	@$(PRETTYECHO) '    LINK' $(TARGET)
	$(COMPILE_PREFIX)$(CXX) $(LDFLAGS) -o $(TARGET) $(ALL_OBJS) $(LIBS)

gen_version_file $(VERSION_FILE):
ifneq ($(STORED_VERSION_STRING),$(VERSION_STRING))
	$(info updating $(VERSION_FILE) to $(VERSION_STRING))
	@echo \#define VERSION_STRING \"$(VERSION_STRING)\" >$(VERSION_FILE)
endif

install: all
	$(INSTALL) -d -m 755 $(BINDIR)
	$(INSTALL) $(NAME) $(BINDIR)
	$(INSTALL) -d -m 755 $(DESKTOPDIR)
	$(INSTALL) $(DESKTOPFILE) $(DESKTOPDIR)
	$(INSTALL) -d -m 755 $(ICONDIR)
	$(INSTALL) -m 644 $(ICONFILE) $(ICONDIR)
	@-if test -z "$(DESTDIR)"; then \
		$(gtk_update_icon_cache); \
	fi
	$(INSTALL) -d -m 755 $(MANDIR)
	$(INSTALL) -m 644 $(MANFILES) $(MANDIR)
	@-if test ! -z "$(XSLT)"; then \
		$(INSTALL) -d -m 755 $(DATADIR)/$(NAME); \
		$(INSTALL) -d -m 755 $(XSLTDIR); \
		$(INSTALL) -m 644 $(XSLTFILES) $(XSLTDIR); \
	fi
	@-if test ! -z "$(MARBLEDIR)"; then \
		$(INSTALL) -d -m 755 $(DATADIR)/$(NAME)/$(MARBLEDIR); \
		$(TAR) cf - $(MARBLEDIR) | ( cd $(DATADIR)/$(NAME); $(TAR) xf - ); \
	fi
	for LOC in $(wildcard share/locale/*/LC_MESSAGES); do \
		$(INSTALL) -d $(prefix)/$$LOC; \
		$(INSTALL) -m 644 $$LOC/$(NAME).mo $(prefix)/$$LOC/$(NAME).mo; \
	done
	$(INSTALL) -d -m 755 $(DOCDIR)
	$(INSTALL) -m 644 Documentation/user-manual.html $(DOCDIR)
	for IMG in $(wildcard Documentation/images/*); do \
		$(INSTALL) -m 644 $$IMG $(DOCDIR)/images; \
	done


install-macosx: all
	$(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/Resources
	$(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/MacOS
	$(INSTALL) $(NAME) $(MACOSXINSTALL)/Contents/MacOS/$(NAME)-bin
	$(INSTALL) $(MACOSXFILES)/$(NAME).sh $(MACOSXINSTALL)/Contents/MacOS/$(NAME)
	$(INSTALL) $(MACOSXFILES)/PkgInfo $(MACOSXINSTALL)/Contents/
	$(INSTALL) $(MACOSXFILES)/Info.plist $(MACOSXINSTALL)/Contents/
	$(INSTALL) $(ICONFILE) $(MACOSXINSTALL)/Contents/Resources/
	$(INSTALL) $(MACOSXFILES)/$(CAPITALIZED_NAME).icns $(MACOSXINSTALL)/Contents/Resources/
	@-if test ! -z "$(MARBLEDIR)"; then \
		$(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/Resources/share/$(MARBLEDIR); \
		$(TAR) cf - $(MARBLEDIR) | ( cd $(MACOSXINSTALL)/Contents/Resources/share; $(TAR) xf - ); \
	fi
	for LOC in $(wildcard share/locale/*/LC_MESSAGES); do \
		$(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/Resources/$$LOC; \
		$(INSTALL) $$LOC/$(NAME).mo $(MACOSXINSTALL)/Contents/Resources/$$LOC/$(NAME).mo; \
	done
	@-if test ! -z "$(XSLT)"; then \
		$(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/Resources/xslt; \
		$(INSTALL) -m 644 $(XSLTFILES) $(MACOSXINSTALL)/Contents/Resources/xslt/; \
	fi
	$(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/resources/share/doc/$(NAME)
	$(INSTALL) -m 644 Documentation/user-manual.html $(MACOSXINSTALL)/Contents/Resources/share/doc/$(NAME)
	for IMG in $(wildcard Documentation/images/*); do \
		$(INSTALL) -m 644 $$IMG $(MACOSXINSTALL)/Contents/Resources/share/doc/$(NAME)/images; \
	done


create-macosx-bundle: all
	$(INSTALL) -d -m 755 $(MACOSXSTAGING)/Contents/Resources
	$(INSTALL) -d -m 755 $(MACOSXSTAGING)/Contents/MacOS
	$(INSTALL) $(NAME) $(MACOSXSTAGING)/Contents/MacOS/
	$(INSTALL) $(MACOSXFILES)/PkgInfo $(MACOSXSTAGING)/Contents/
	$(INSTALL) $(MACOSXFILES)/Info.plist $(MACOSXSTAGING)/Contents/
	$(INSTALL) $(ICONFILE) $(MACOSXSTAGING)/Contents/Resources/
	$(INSTALL) $(MACOSXFILES)/$(CAPITALIZED_NAME).icns $(MACOSXSTAGING)/Contents/Resources/
	for LOC in $(wildcard share/locale/*/LC_MESSAGES); do \
		$(INSTALL) -d -m 755 $(MACOSXSTAGING)/Contents/Resources/$$LOC; \
		$(INSTALL) $$LOC/$(NAME).mo $(MACOSXSTAGING)/Contents/Resources/$$LOC/$(NAME).mo; \
	done
	@-if test ! -z "$(XSLT)"; then \
		$(INSTALL) -d -m 755 $(MACOSXSTAGING)/Contents/Resources/xslt; \
		$(INSTALL) -m 644 $(XSLTFILES) $(MACOSXSTAGING)/Contents/Resources/xslt/; \
	fi
	$(INSTALL) -d -m 755 $(MACOSXSTAGING)/Contents/resources/share/doc/$(NAME)
	$(INSTALL) -m 644 Documentation/user-manual.html $(MACOSXSTAGING)/Contents/Resources/share/doc/$(NAME)
	for IMG in $(wildcard Documentation/images/*); do \
		$(INSTALL) -m 644 $$IMG $(MACOSXSTAGING)/Contents/Resources/share/doc/$(NAME)/images; \
	done
	$(GTK_MAC_BUNDLER) packaging/macosx/$(NAME).bundle

sign-macosx-bundle: all
	codesign -s "3A8CE62A483083EDEA5581A61E770EC1FA8BECE8" /Applications/$(CAPITALIZED_NAME).app/Contents/MacOS/$(NAME)-bin

install-cross-windows: all
	$(INSTALL) -d -m 755 $(WINDOWSSTAGING)/share/locale
	for MSG in $(WINMSGDIRS); do\
		$(INSTALL) -d -m 755 $(WINDOWSSTAGING)/$$MSG;\
		$(INSTALL) $(CROSS_PATH)/$$MSG/* $(WINDOWSSTAGING)/$$MSG;\
	done
	for LOC in $(wildcard share/locale/*/LC_MESSAGES); do \
		$(INSTALL) -d -m 755 $(WINDOWSSTAGING)/$$LOC; \
		$(INSTALL) $$LOC/$(NAME).mo $(WINDOWSSTAGING)/$$LOC/$(NAME).mo; \
	done
	$(INSTALL) -d -m 755 $(WINDOWSSTAGING)/share/doc/$(NAME)
	$(INSTALL) -m 644 Documentation/user-manual.html $(WINDOWSSTAGING)/share/doc/$(NAME)
	for IMG in $(wildcard Documentation/images/*); do \
		$(INSTALL) -m 644 $$IMG $(WINDOWSSTAGING)/share/doc/$(NAME)/images; \
	done


create-windows-installer: all $(NSIFILE) install-cross-windows
	$(MAKENSIS) $(NSIFILE)

$(NSIFILE): $(NSIINPUTFILE)
	$(shell cat $(NSIINPUTFILE) | sed -e 's/VERSIONTOKEN/$(VERSION_STRING)/;s/PRODVTOKEN/$(PRODVERSION_STRING)/' > $(NSIFILE))

$(INFOPLIST): $(INFOPLISTINPUT)
	$(shell cat $(INFOPLISTINPUT) | sed -e 's/CFBUNDLEVERSION_TOKEN/$(CFBUNDLEVERSION_STRING)/' > $(INFOPLIST))

# Transifex merge the translations
update-po-files:
	xgettext -o po/$(NAME)-new.pot -s -k_ -kN_ -ktr --keyword=C_:1c,2  --add-comments="++GETTEXT" *.c qt-ui/*.cpp
	tx push -s
	tx pull -af

MOCFLAGS = $(filter -I%, $(CXXFLAGS) $(EXTRA_FLAGS)) $(filter -D%, $(CXXFLAGS) $(EXTRA_FLAGS))

%.o: %.c
	@$(PRETTYECHO) '    CC' $<
	@mkdir -p .dep/$(@D)
	$(COMPILE_PREFIX)$(CC) $(CFLAGS) $(EXTRA_FLAGS) -MD -MF .dep/$@.dep -c -o $@ $<

%.o: %.cpp
	@$(PRETTYECHO) '    CXX' $<
	@mkdir -p .dep/$(@D)
	$(COMPILE_PREFIX)$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) -MD -MF .dep/$@.dep -c -o $@ $<

# This rule is for running the moc on QObject subclasses defined in the .h
# files.
%.moc.cpp: %.h
	@$(PRETTYECHO) '    MOC' $<
	$(COMPILE_PREFIX)$(MOC) $(MOCFLAGS) $< -o $@

# This rule is for running the moc on QObject subclasses defined in the .cpp
# files; remember to #include "<file>.moc" at the end of the .cpp file, or
# you'll get linker errors ("undefined vtable for...")
%.moc: %.cpp
	@$(PRETTYECHO) '    MOC' $<
	$(COMPILE_PREFIX)$(MOC) -i $(MOCFLAGS) $< -o $@

# This creates the Qt resource sources.
%.qrc.cpp: %.qrc
	@$(PRETTYECHO) '    RCC' $<
	$(COMPILE_PREFIX)$(RCC) $< -o $@
%.qrc:

# This creates the ui headers.
ui_%.h: %.ui
	@$(PRETTYECHO) '    UIC' $<
	$(COMPILE_PREFIX)$(UIC) $< -o $@

# This forces the creation of ui headers with the wrong path
# This is required because the -MG option to the compiler outputs
# unknown files with no path prefix
ui_%.h: qt-ui/%.ui
	@$(PRETTYECHO) '    UIC' $<
	$(COMPILE_PREFIX)$(UIC) $< -o qt-ui/$@

share/locale/%.UTF-8/LC_MESSAGES/$(NAME).mo: po/%.po po/%.aliases
	@$(PRETTYECHO) '    MSGFMT' $*.po
	@mkdir -p $(dir $@)
	$(COMPILE_PREFIX)msgfmt -c -o $@ po/$*.po
	@-if test -s po/$*.aliases; then \
		for ALIAS in `cat po/$*.aliases`; do \
			mkdir -p share/locale/$$ALIAS/LC_MESSAGES; \
			cp $@ share/locale/$$ALIAS/LC_MESSAGES; \
		done; \
	fi

satellite.png: satellite.svg
	convert -transparent white -resize 11x16 -depth 8 $< $@

# This should work, but it doesn't get the colors quite right - so I manually converted with Gimp
#	convert -colorspace RGB -transparent white -resize 256x256 subsurface-icon.svg subsurface-icon.png
#
# The following creates the pixbuf data in .h files with the basename followed by '_pixmap'
# as name of the data structure
%.h: %.png
	@echo '    gdk-pixbuf-csource' $<
	@gdk-pixbuf-csource --struct --name `echo $* | sed 's/-/_/g'`_pixbuf $< > $@

doc:
	$(MAKE) -C Documentation doc

clean:
	rm -f $(ALL_OBJS) *~ $(NAME) $(NAME).exe po/*~ po/$(NAME)-new.pot \
		$(VERSION_FILE) $(HEADERS_NEEDING_MOC:.h=.moc) *.moc qt-ui/*.moc qt-ui/ui_*.h
	rm -f $(RESOURCES:.qrc=.qrc.cpp)
	rm -rf share

confclean: clean
	rm -f $(CONFIGFILE)
	rm -rf .dep

distclean: confclean
	rm -f $(CREATOR_FILES)

release:
	@scripts/check-version -cr $(VERSION_STRING)
	git archive --prefix $(CAPITALIZED_NAME)-$(VERSION_STRING)/ \
		    --output $(CAPITALIZED_NAME)-$(VERSION_STRING).tgz \
		    v$(VERSION_STRING)

.PHONY: creator-files
creator-files: $(CREATOR_FILES)
$(NAME).files: Makefile $(CONFIGFILE)
	echo $(wildcard *.h qt-ui/*.h qt-ui/*.ui) $(HEADERS) $(SOURCES) | tr ' ' '\n' | sort | uniq > $(NAME).files
	{ echo Makefile; echo Rules.mk; echo Configure.mk; } >> $(NAME).files
$(NAME).config: Makefile $(CONFIGFILE)
	echo $(patsubst -D%,%,$(filter -D%, $(CXXFLAGS) $(CFLAGS) $(EXTRA_FLAGS))) | tr ' ' '\n' | sort | uniq > $(NAME).config
$(NAME).includes: Makefile $(CONFIGFILE)
	echo $$PWD > $(NAME).includes
	echo $(patsubst -I%,%,$(filter -I%, $(CXXFLAGS) $(CFLAGS) $(EXTRA_FLAGS))) | tr ' ' '\n' | sort | uniq >> $(NAME).includes
$(NAME).creator:
	echo '[General]' > $(NAME).creator

ifneq ($(CONFIGURED)$(CONFIGURING),)
.dep/%.o.dep: %.cpp
	@mkdir -p $(@D)
	@$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) -MM -MG -MF $@ -MT $(<:.cpp=.o) -c $<
endif

DEPS = $(addprefix .dep/,$(C_SOURCES:.c=.o.dep) $(CXX_SOURCES:.cpp=.o.dep))
-include $(DEPS)