You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
13 KiB

  1. #
  2. # Makefile
  3. #
  4. # Tray icon flag. Possible values:
  5. # none, tray (for gnome 2.x) , indicator (for gnome 3.x)
  6. ICON ?= indicator
  7. # Build type. Possible values:
  8. # debug, release, win
  9. BUILD_TYPE ?= release
  10. BINNAME = neo_layout_viewer
  11. BINDIR = bin
  12. # Path prefix for 'make install'
  13. PREFIX = /usr/local
  14. APPNAME = NeoLayoutViewer
  15. # Prefix for package name generation
  16. PACKAGE_NAME = neo-layout-viewer
  17. GIT_COMMIT_VERSION=$(shell git log --oneline --max-count=1 | head --bytes=7)
  18. ENV_FILE = .build_env
  19. # compiler options for a debug build
  20. #VALAC_DEBUG_OPTS = -g --save-temps
  21. VALAC_DEBUG_OPTS = -g
  22. # compiler options for a release build.
  23. # Note that some cc-warnings can not resolved. Use '-X -w' to hide them.
  24. VALAC_RELEASE_OPTS = -X -O2 --disable-assert
  25. # falg required for pbuilder environment and deb-file naming scheme.
  26. UBUNTU ?= 0
  27. DISTDIR = dist
  28. TMPDIR = tmp
  29. ARCHS = amd64 # i386 armhf arm64
  30. BASETGZ_DIR = /var/cache/pbuilder
  31. ifeq ($(UBUNTU),1)
  32. # Ubuntu, valac requires universe-component
  33. MIRROR=http://de.archive.ubuntu.com/ubuntu/
  34. DIST = bionic
  35. COMPONENTS = main universe #restricted multiverse
  36. UBUNTU_SUFFIX = ubuntu1
  37. else
  38. # Debian
  39. DIST = sid
  40. MIRROR = http://ftp.de.debian.org/debian
  41. COMPONENTS = main
  42. UBUNTU_SUFFIX =
  43. endif
  44. # Debian Packaging version number
  45. # Pattern: [epoch:]upstream_version[-debian_revision].
  46. # The absence of a debian_revision is equivalent to a debian_revision of 0.
  47. RELEASE_VERSION=$(shell sed -n "/^$(PACKAGE_NAME)\s*(\([^()]*\)[)].*/{ s//\1/p; q0 }; q1" debian/changelog || echo -n "undefined" )
  48. #Token for .orig.tar.gz-files: dpkg-source request upstream tarball without revision substring
  49. SRC_VERSION=$(shell echo -n "$(RELEASE_VERSION)" | cut -d\- -f 1 -z)
  50. #########################################################
  51. # Test build under MingW for Windows
  52. WIN ?=
  53. ifeq ($(WIN),)
  54. NL = \n
  55. BINEXT =
  56. else
  57. BUILD_TYPE = win
  58. BINEXT = .exe
  59. ICON = tray
  60. GTK_PREBUILD_ZIP=http://win32builder.gnome.org/gtk+-bundle_3.10.4-20131202_win64.zip
  61. GEE_XZ=https://ftp.gnome.org/pub/gnome/sources/libgee/0.8/libgee-0.8.8.tar.xz
  62. PKG_CONFIG_PATH=$(shell pwd)/win/lib/pkgconfig
  63. #PKG_CONFIG_PATH=${HOME}/software/gtk/gtk+-3.10_win64/lib/pkgconfig
  64. GCC_WIN = x86_64-w64-mingw32-gcc
  65. GCC_WIN_FLAGS = -mwindows $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --cflags --libs gtk+-3.0 gee-$(GEEVERSION))
  66. VALAC_RELEASE_OPTS += -D _OLD_GTK_STOCK # Old gtk-versions (<3.16) do not define `gtk_label_set_xalign`
  67. VALAC_DEBUG_OPTS += -D _OLD_GTK_STOCK
  68. endif
  69. #########################################################
  70. EXEC_PREFIX = $(PREFIX)
  71. DATADIR = $(PREFIX)/share
  72. VALAC = valac -D $(ICON) \
  73. --Xcc="-lm" --Xcc="-DXK_TECHNICAL" --Xcc="-DXK_PUBLISHING" --Xcc="-DXK_APL"
  74. VAPIDIR = --vapidir=vapi/
  75. # Source files
  76. SRC = src/version.vala \
  77. src/main.vala \
  78. src/app.vala \
  79. src/neo-window.vala \
  80. src/scaling-image.vala \
  81. src/config-manager.vala
  82. ifeq ($(WIN),)
  83. VALAC_DEBUG_OPTS += -D _NO_WIN
  84. VALAC_RELEASE_OPTS += -D _NO_WIN
  85. SRC += src/key-overlay.vala \
  86. src/keybinding-manager.vala \
  87. csrc/keysend.c \
  88. csrc/checkModifier.c
  89. endif
  90. # Asset files
  91. ASSET_FILES=$(wildcard assets/**/*.png)
  92. # Test for valac version, workaround for Arch Linux bug
  93. ifeq ($(wildcard /usr/include/gee-0.8),)
  94. # Similar, but for Windows/MingW
  95. ifeq ($(wildcard /mingw64/include/gee-0.8),)
  96. GEEVERSION=1.0
  97. else
  98. GEEVERSION=0.8
  99. endif
  100. else
  101. GEEVERSION=0.8
  102. endif
  103. # Packages
  104. PKGS = --pkg x11 --pkg keysym --pkg gtk+-3.0 --pkg gee-$(GEEVERSION) --pkg gdk-x11-3.0 --pkg posix --pkg gdk-3.0
  105. # Add some args if tray icon is demanded.
  106. ifeq ($(ICON),tray)
  107. SRC += src/tray.vala
  108. endif
  109. ifeq ($(ICON),indicator)
  110. SRC += src/indicator.vala
  111. PKGS += --pkg appindicator3-0.1
  112. endif
  113. .PHONY: debug release install clean last_build_env
  114. # .FORCE: last_build_env
  115. # The target respects BUILD_TYPE and cleaning if it changes
  116. all: info last_build_env "$(BINDIR)/$(BINNAME)$(BINEXT)"
  117. @echo "Done"
  118. "$(BINDIR)/$(BINNAME)$(BINEXT)": $(SRC) Makefile "$(BINDIR)"
  119. make build_$(BUILD_TYPE)
  120. # Remove binary if current env differs from last build env
  121. # This toggles a rebuild.
  122. last_build_env:
  123. @(test "$$(env|sort)" = "$$(test -f $(ENV_FILE) && cat $(ENV_FILE) )" \
  124. && echo "Same environment as last build.") \
  125. || (echo "Env has changed. Force build" \
  126. && make clean \
  127. && env | sort > "$(ENV_FILE)" \
  128. )
  129. # Clean release build, similar to 'BUILD_TYPE=release make all'
  130. release: clean build_release
  131. info:
  132. @/bin/echo -e " $(NL)"\
  133. "Buildtype: $(BUILD_TYPE)$(NL)" \
  134. "Trayicon: $(ICON)$(NL)" \
  135. "$(NL)" \
  136. "Notes:$(NL)" \
  137. " Use 'ICON=... make' to switch type of panel menu.$(NL)" \
  138. " indicator: For gnome 3.x (default)$(NL)" \
  139. " tray: For gnome 2.x$(NL)" \
  140. " none: Disables icon$(NL)$(NL)" \
  141. " Use 'BUILD_TYPE=[release|debug] make' to switch build type$(NL)$(NL)" \
  142. gen_version:
  143. @/bin/echo -e "namespace NeoLayoutViewer{$(NL)" \
  144. "public const string RELEASE_VERSION = \"$(RELEASE_VERSION)\";$(NL)" \
  145. "public const string GIT_COMMIT_VERSION = \"$(GIT_COMMIT_VERSION)\";$(NL)" \
  146. "public const string SHARED_ASSETS_PATH = \"$(DATADIR)/$(APPNAME)/assets\";$(NL)" \
  147. "}" \
  148. > src/version.vala
  149. src/version.vala: Makefile gen_version
  150. "$(BINDIR)":
  151. @test -d "$(BINDIR)" || \
  152. (mkdir -p "$(BINDIR)" && ln -s ../assets "$(BINDIR)/assets")
  153. "$(DISTDIR)":
  154. @test -d "$(DISTDIR)" || \
  155. (mkdir -p "$(DISTDIR)")
  156. "$(TMPDIR)":
  157. @test -d "$(TMPDIR)" || \
  158. (mkdir -p "$(TMPDIR)")
  159. build_debug: $(SRC) "$(BINDIR)"
  160. $(VALAC) $(VAPIDIR) $(VALAC_DEBUG_OPTS) $(SRC) -o "$(BINDIR)/$(BINNAME)$(BINEXT)" $(PKGS) $(CC_INCLUDES)
  161. build_release: $(SRC) "$(BINDIR)"
  162. $(VALAC) $(VAPIDIR) $(VALAC_RELEASE_OPTS) $(SRC) -o "$(BINDIR)/$(BINNAME)$(BINEXT)" $(PKGS) $(CC_INCLUDES)
  163. # Two staged compiling
  164. build_release2: $(SRC) "$(BINDIR)"
  165. $(VALAC) --ccode $(VAPIDIR) $(VALAC_RELEASE_OPTS) $(SRC) $(PKGS) $(CC_INCLUDES)
  166. gcc $(SRC:.vala=.c) $(CC_INCLUDES) -o "$(BINDIR)/$(BINNAME)$(BINEXT)" \
  167. `pkg-config --cflags --libs gtk+-3.0 gee-$(GEEVERSION)`
  168. man: man/neo_layout_viewer.1.gz
  169. man/%.gz: man/%
  170. gzip -c "$<" > "$@"
  171. install: man
  172. test -f "$(BINDIR)/$(BINNAME)$(BINEXT)" || make all
  173. install -d $(EXEC_PREFIX)/bin
  174. install -D -m 0755 "$(BINDIR)/$(BINNAME)$(BINEXT)" "$(EXEC_PREFIX)/bin"
  175. $(foreach ASSET_FILE,$(ASSET_FILES), \
  176. install -D -m 0644 $(ASSET_FILE) "$(DATADIR)/$(APPNAME)/$(ASSET_FILE)" ; )
  177. install -d $(PREFIX)/share/man/man1/
  178. install -t $(PREFIX)/share/man/man1/ man/neo_layout_viewer.1.gz
  179. install -D -t $(PREFIX)/share/applications/ Keyboard_Layout_Viewer.desktop
  180. uninstall:
  181. @rm -fv "$(EXEC_PREFIX)/bin/$(BINNAME)$(BINEXT)"
  182. @test -d "$(DATADIR)/$(APPNAME)/assets" && rm -v -r "$(DATADIR)/$(APPNAME)"
  183. # Prefixed with test because of dangerous -r-flag...
  184. @rm -fv $(PREFIX)/share/man/man1/neo_layout_viewer.1.gz
  185. @rm -v -r $(PREFIX)/share/applications/Keyboard_Layout_Viewer.desktop
  186. # clean all build files, but not dist results.
  187. clean:
  188. @rm -v -d -f *~ *.c src/*.c src/*~ "$(BINDIR)"/* "$(BINDIR)" "$(ENV_FILE)"
  189. @rm -v -d -f -r "$(TMPDIR)"/*
  190. @rm -v -d -f "$(TMPDIR)"
  191. @rm -v -f man/*.gz
  192. run:
  193. "$(BINDIR)/$(BINNAME)$(BINEXT)"
  194. ######################################################
  195. ## Targets for .*deb build
  196. src-package: "$(DISTDIR)"
  197. tar czf "$(DISTDIR)"/neo-layout-viewer_$(RELEASE_VERSION)-src.tar.gz \
  198. --exclude=.git --exclude=.gitignore --exclude=win \
  199. --exclude=bin --exclude=man/*.gz --exclude=.pc\
  200. --exclude=dist --exclude=tmp \
  201. --transform 's,^\./,neo-layout-viewer-$(RELEASE_VERSION)/,' \
  202. .
  203. dist-package: "$(DISTDIR)" release man
  204. tar czf "$(DISTDIR)"/neo-layout-viewer_$(RELEASE_VERSION).tgz \
  205. --transform 's,^$(BINDIR)/,,' \
  206. --transform 's,^,neo-layout-viewer-$(RELEASE_VERSION)/,' \
  207. "$(BINDIR)/$(BINNAME)" assets AUTHORS COPYING README.md \
  208. man/*.gz
  209. deb-packages: "$(TMPDIR)" "$(DISTDIR)" src-package
  210. cp "$(DISTDIR)"/neo-layout-viewer_$(RELEASE_VERSION)-src.tar.gz "$(TMPDIR)"/neo-layout-viewer_$(SRC_VERSION).orig.tar.gz && \
  211. cd "$(TMPDIR)" && \
  212. tar xzf neo-layout-viewer_$(SRC_VERSION).orig.tar.gz && \
  213. cd neo-layout-viewer-$(RELEASE_VERSION) && \
  214. for arch in $(ARCHS); do \
  215. sudo mkdir -p $(BASETGZ_DIR)/$(DIST)-aptcache/ && \
  216. sudo pbuilder update --override-config --distribution "$(DIST)" --mirror "$(MIRROR)" --components "$(COMPONENTS)" --architecture $$arch --basetgz $(BASETGZ_DIR)/$(DIST)-$$arch-base.tgz --aptcache $(BASETGZ_DIR)/$(DIST)-aptcache/ || \
  217. sudo pbuilder create --override-config --distribution $(DIST) --mirror $(MIRROR) --components "$(COMPONENTS)" --architecture $$arch --basetgz $(BASETGZ_DIR)/$(DIST)-$$arch-base.tgz --aptcache $(BASETGZ_DIR)/$(DIST)-aptcache/ && \
  218. DEB_BUILD_OPTIONS="noautodbgsym" pdebuild --buildresult .. --debbuildopts "-i -us -uc -b" -- --override-config --distribution $(DIST) --mirror $(MIRROR) --components "$(COMPONENTS)" --architecture $$arch --basetgz $(BASETGZ_DIR)/$(DIST)-$$arch-base.tgz --aptcache $(BASETGZ_DIR)/$(DIST)-aptcache/ && \
  219. mv ../neo-layout-viewer_$(RELEASE_VERSION)_$$arch*deb ../../dist/neo-layout-viewer_$(RELEASE_VERSION)$(UBUNTU_SUFFIX)_$$arch.deb ; \
  220. done
  221. deb-package: "$(TMPDIR)" "$(DISTDIR)" src-package
  222. cp "$(DISTDIR)"/neo-layout-viewer_$(RELEASE_VERSION)-src.tar.gz "$(TMPDIR)"/neo-layout-viewer_$(SRC_VERSION).orig.tar.gz && \
  223. cd "$(TMPDIR)" && \
  224. tar xzf neo-layout-viewer_$(SRC_VERSION).orig.tar.gz && \
  225. cd neo-layout-viewer-$(RELEASE_VERSION) && \
  226. DEB_BUILD_OPTIONS="noautodbgsym" pdebuild --buildresult .. --debbuildopts "-i -us -uc -b" && \
  227. mv ../neo-layout-viewer_$(RELEASE_VERSION)_$(shell dpkg --print-architecture).deb ../../dist/neo-layout-viewer_$(RELEASE_VERSION)$(UBUNTU_SUFFIX)_$(shell dpkg --print-architecture).deb
  228. dist: src-package dist-package deb-packages
  229. ######################################################
  230. ## Windows stuff
  231. # Building under MingW
  232. build_win: $(SRC)
  233. $(VALAC) $(VAPIDIR) $(VALAC_RELEASE_OPTS) $(SRC) -o "$(BINDIR)/$(BINNAME)$(BINEXT)" $(PKGS) $(CC_INCLUDES)
  234. # Cross compiling under Debian/Ubuntu
  235. build_cross_win: bin/libgtk-3-0.dll
  236. test "$(WIN)" = "1" || (echo "Call this target with WIN=1" && exit 1)
  237. echo "Flags: $(GCC_WIN_FLAGS)"
  238. PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" \
  239. $(VALAC) --ccode $(VAPIDIR) $(VALAC_RELEASE_OPTS) $(SRC) $(PKGS) $(CC_INCLUDES)
  240. PKG_CONFIG_PATH="$(PKG_CONFIG_PATH), \
  241. $(GCC_WIN) $(SRC:.vala=.c) -o "$(BINDIR)/$(BINNAME)$(BINEXT)" $(GCC_WIN_FLAGS)
  242. bin/libgtk-3-0.dll:
  243. WIN=1 make win_gtk
  244. win_download_gtk:
  245. test "$(WIN)" = "1" || (echo "Call this target with WIN=1" && exit 1)
  246. test -d win || mkdir win
  247. test -f win/$$(basename "$(GTK_PREBUILD_ZIP)") || \
  248. ( cd win && wget -c "$(GTK_PREBUILD_ZIP), && \
  249. unzip $$(basename "$(GTK_PREBUILD_ZIP)") )
  250. cd win && find -name '*.pc' | while read pc; do sed -e "s@^prefix=.*@prefix=$$PWD@" -i "$$pc"; done
  251. win_build_gee:
  252. test "$(WIN)" = "1" || (echo "Call this target with WIN=1" && exit 1)
  253. cd win && wget -c "$(GEE_XZ)" && \
  254. tar xJvf ./libgee-0.8.8.tar.xz > /dev/null
  255. cd win/libgee-0.8.8 && \
  256. sed -i -e 's/if test ".cross_compiling" != yes; then/if test 0 != 0; then/' ./configure
  257. cd win/libgee-0.8.8 && \
  258. PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) CC=$(GCC_WIN) \
  259. CC_FLAGS="$(GCC_WIN_FLAGS)" \
  260. ./configure --build=x86_64 --prefix=$(PKG_CONFIG_PATH)/../.. && \
  261. make && make install
  262. win_gtk: win_download_gtk win_build_gee
  263. test "$(WIN)" = "1" || (echo "Call this target with WIN=1" && exit 1)
  264. cp win/bin/*.dll bin/.
  265. print_version:
  266. @echo "Source archive: $(PACKAGE_NAME)_$(SRC_VERSION).orig.tar.gz"
  267. @echo "Deb file: $(PACKAGE_NAME)_$(RELEASE_VERSION)_$(shell dpkg --print-architecture).deb"
  268. # Test to avoid sudo. Unfortunately, dpkg-buildpackage still ask...
  269. deb-packages_as_user: "$(TMPDIR)" "$(DISTDIR)" src-package
  270. cp "$(DISTDIR)"/neo-layout-viewer_$(RELEASE_VERSION)-src.tar.gz "$(TMPDIR)"/neo-layout-viewer_$(SRC_VERSION).orig.tar.gz && \
  271. cd "$(TMPDIR)" && \
  272. tar xzf neo-layout-viewer_$(SRC_VERSION).orig.tar.gz && \
  273. cd neo-layout-viewer-$(RELEASE_VERSION) && \
  274. for arch in $(ARCHS); do \
  275. mkdir -p $(BASETGZ_DIR)/$(DIST)-aptcache/ && \
  276. test "$(SKIP_PBUILDER_UPDATE)" = "1" || \
  277. pbuilder update --override-config --distribution "$(DIST)" --mirror "$(MIRROR)" --components "$(COMPONENTS)" --architecture $$arch --basetgz $(BASETGZ_DIR)/$(DIST)-$$arch-base.tgz --aptcache $(BASETGZ_DIR)/$(DIST)-aptcache/ || \
  278. pbuilder create --override-config --distribution $(DIST) --mirror $(MIRROR) --components "$(COMPONENTS)" --architecture $$arch --basetgz $(BASETGZ_DIR)/$(DIST)-$$arch-base.tgz --aptcache $(BASETGZ_DIR)/$(DIST)-aptcache/ && \
  279. DEB_BUILD_OPTIONS="noautodbgsym" pdebuild --buildresult .. --debbuildopts "-i -us -uc -b" -- --override-config --distribution $(DIST) --mirror $(MIRROR) --components "$(COMPONENTS)" --architecture $$arch --basetgz $(BASETGZ_DIR)/$(DIST)-$$arch-base.tgz --aptcache $(BASETGZ_DIR)/$(DIST)-aptcache/ && \
  280. mv ../neo-layout-viewer_$(RELEASE_VERSION)_$$arch*deb ../../dist/neo-layout-viewer_$(RELEASE_VERSION)$(UBUNTU_SUFFIX)_$$arch.deb ; \
  281. done