build: mark binary data as read-only with objcopy
[platform/upstream/kmscon.git] / Makefile.am
1 #
2 # Kmscon - Global Makefile
3 # Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
4 #
5
6 #
7 # Global Configurations and Initializations
8 #
9
10 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
11 AM_MAKEFLAGS = --no-print-directory
12 AUTOMAKE_OPTIONS = color-tests
13 AM_DISTCHECK_CONFIGURE_FLAGS = --enable-all
14
15 SUBDIRS = .
16
17 .DELETE_ON_ERROR:
18
19 include_HEADERS =
20 EXTRA_DIST = \
21         README \
22         COPYING \
23         NEWS \
24         docs/kmscon.service \
25         docs/kmsconvt@.service
26 CLEANFILES =
27 pkgconfigdir = $(libdir)/pkgconfig
28 pkgconfig_DATA =
29 MANPAGES =
30 MANPAGES_ALIASES =
31 TPHONY =
32
33 bin_PROGRAMS =
34 check_PROGRAMS =
35 noinst_PROGRAMS =
36 lib_LTLIBRARIES =
37 noinst_LTLIBRARIES =
38
39 moduledir = $(libdir)/kmscon
40 module_LTLIBRARIES =
41
42 #
43 # Default CFlags
44 # Make all files include "config.h" by default. This shouldn't cause any
45 # problems and we cannot forget to include it anymore.
46 #
47 # Also make the linker discard all unused symbols.
48 #
49 # When compiling in debug mode, we enable debug symbols so debugging with gdb
50 # is easier. If optimizations are disabled, we pass -O0 to the compiler.
51 # Otherwise, we use standard optimizations -O2.
52 #
53
54 AM_CFLAGS = \
55         -Wall \
56         -pipe \
57         -fno-common \
58         -ffast-math \
59         -fdiagnostics-show-option \
60         -fno-strict-aliasing \
61         -fvisibility=hidden \
62         -ffunction-sections \
63         -fdata-sections \
64         -fstack-protector
65 AM_CPPFLAGS = \
66         -DBUILD_MODULE_DIR='"$(moduledir)"' \
67         -include $(top_builddir)/config.h \
68         -I $(srcdir)/src
69 AM_LDFLAGS = \
70         -Wl,--as-needed \
71         -Wl,--gc-sections \
72         -Wl,-z,relro \
73         -Wl,-z,now
74
75 if BUILD_ENABLE_DEBUG
76 AM_CFLAGS += -g
77 endif
78
79 if BUILD_ENABLE_OPTIMIZATIONS
80 AM_CFLAGS += -O2
81 else
82 AM_CFLAGS += -O0
83 endif
84
85 #
86 # GIT-HEAD helper
87 # The file ./src/shl_githead.c contains a constant "shl_git_head" which is
88 # defined to the string returned by "git describe". We need to adjust this
89 # string for every build and correctly rebuild any sources that depend on it.
90 # Therefore, you should use this file rarely as it causes rebuilds on every
91 # git-commit.
92 #
93 # We have a helper-script ./src/genversion.sh that takes as argument the source
94 # file and creates it if necessary. It updates it only if the new git-describe
95 # string is different to the old one. So the file is only modified on changes.
96 # Hence, we can use it as normal dependency in this Makefile.
97 # However, we need to run this script on _every_ "make" invocation before any
98 # recipy is executed. To achieve this, we use $(shell ...) and assign it to a
99 # "simply expanded" variable (:=) so the shell command is executed on
100 # variable-declaration and not during expansion.
101 #
102 # Note that we must not clean ./src/shl_githead.c ever! If we would, a
103 # distribution tarball might delete that file and have no way to recreate it.
104 # We could delete it on something like "make maintainerclean", but then again,
105 # it seems unnecessary so lets simply not clean it at all.
106 #
107 # If the helper-script is executed in a directory that is not a git-repository
108 # (like a distribution tarball) and shl_githead.c exists, then it does nothing
109 # as it expects shl_githead.c to be correctly written by "make dist".
110 # However, if shl_githead.c does not exist, it will print a warning and write
111 # an unknown random git-revision.
112 # This guarantees, that shl_githead.c is always present and has the most correct
113 # value that we can get under any conditions.
114 #
115 # The $(emptyvariable) expansion below is used for broken $(shell ...)
116 # syntax-highlighting algorithms in many existing editors.
117 #
118
119 EXTRA_DIST += src/genversion.sh
120 GITHEAD:=$(shell $(emptyvariable)"$(srcdir)/src/genversion.sh" "$(srcdir)/src/shl_githead.c")
121
122 #
123 # Binary File Compiler
124 # This target gets as input a binary file *.bin and produces an ELF/etc. output
125 # object file *.bin.o and the corresponding libtool file *.bin.lo.
126 # Note that we fake the libtool object files as there is no way to make libtool
127 # create it. The comments in the .lo file are mandatory so don't remove them!
128 #
129
130 CLEANFILES += src/*.bin.lo src/*.bin.o
131
132 src/%.bin.lo: src/%.bin
133         $(AM_V_GEN)$(LD) -r -o "src/$*.bin.o" -z noexecstack --format=binary "$<"
134         $(AM_V_at)$(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents "src/$*.bin.o"
135         $(AM_V_at)echo "# $@ - a libtool object file" >"$@"
136         $(AM_V_at)echo "# Generated by $(shell $(LIBTOOL) --version | head -n 1)" >>"$@"
137         $(AM_V_at)echo "#" >>"$@"
138         $(AM_V_at)echo "# Please DO NOT delete this file!" >>"$@"
139         $(AM_V_at)echo "# It is necessary for linking the library." >>"$@"
140         $(AM_V_at)echo >>"$@"
141         $(AM_V_at)echo "# Name of the PIC object." >>"$@"
142         $(AM_V_at)echo "pic_object='$*.bin.o'" >>"$@"
143         $(AM_V_at)echo >>"$@"
144         $(AM_V_at)echo "# Name of the non-PIC object" >>"$@"
145         $(AM_V_at)echo "non_pic_object='$*.bin.o'" >>"$@"
146         $(AM_V_at)echo >>"$@"
147
148 #
149 # Shader Converter
150 # We use a few built-in shader files. To reduce memory-consumption, this helper
151 # removes useless lines from the shaders before they are compiled into an object
152 # file.
153 #
154 # Following regexp are used to remove characters/lines:
155 #  ^/*.*$     Start of multi-line comment
156 #  ^ *.*$     Multi-line comment body
157 #  ^[ \t]*    Indentation whitespace
158 #  \n         Newlines
159 #
160
161 CLEANFILES += src/*.vert.bin src/*.frag.bin
162 SHADER_SED = -e 's/^\/\*.*$$//' -e 's/^ \*.*$$//' -e 's/^[ \t]*//'
163 SHADER_TR = -d "\n"
164
165 src/%.vert.bin: $(top_srcdir)/src/%.vert
166         $(AM_V_at)$(SED) $(SHADER_SED) "$<" | tr $(SHADER_TR) >"$@"
167
168 src/%.frag.bin: $(top_srcdir)/src/%.frag
169         $(AM_V_at)$(SED) $(SHADER_SED) "$<" | tr $(SHADER_TR) >"$@"
170
171 #
172 # SHL - Static Helper Library
173 # The SHL subsystem contains several small code pieces used all over kmscon and
174 # other applications.
175 #
176
177 noinst_LTLIBRARIES += libshl.la
178
179 libshl_la_SOURCES = \
180         src/shl_githead.h \
181         src/shl_githead.c \
182         src/shl_dlist.h \
183         src/shl_array.h \
184         src/shl_hashtable.h \
185         external/htable.h \
186         external/htable.c \
187         src/shl_ring.h \
188         src/shl_timer.h \
189         src/shl_llog.h \
190         src/shl_log.h \
191         src/shl_log.c \
192         src/shl_hook.h \
193         src/shl_misc.h \
194         src/shl_register.h \
195         src/shl_flagset.h \
196         src/shl_gl.h \
197         src/shl_gl_math.c
198 libshl_la_CPPFLAGS = \
199         $(AM_CPPFLAGS) \
200         $(XKBCOMMON_CFLAGS) \
201         -pthread
202 libshl_la_LDFLAGS = \
203         $(AM_LDFLAGS) \
204         -pthread
205 libshl_la_LIBADD = \
206         $(AM_LIBADD) \
207         $(XKBCOMMON_LIBS)
208
209 if BUILD_HAVE_GLES2
210 libshl_la_SOURCES += src/shl_gl_shader.c
211 libshl_la_CPPFLAGS += $(GLES2_CFLAGS)
212 libshl_la_LIBADD += $(GLES2_LIBS)
213 endif
214
215 #
216 # libeloop
217 # This library contains the whole event-loop implementation of kmscon. It is
218 # compiled into a separate object to allow using it in several other programs.
219 #
220
221 noinst_LTLIBRARIES += libeloop.la
222
223 libeloop_la_SOURCES = \
224         src/eloop.h \
225         src/eloop.c
226
227 libeloop_la_LIBADD = libshl.la
228 libeloop_la_CPPFLAGS = $(AM_CPPFLAGS)
229 libeloop_la_LDFLAGS = $(AM_LDFLAGS)
230
231 #
232 # libuterm
233 # The uterm library provides helpers to create terminals in user-space. They
234 # are not limited to text-based terminals but rather provide graphics contexts
235 # so arbitrary output can be displayed. Additionally, they provide VT
236 # abstractions and an input layer
237 #
238
239 noinst_LTLIBRARIES += libuterm.la
240
241 libuterm_la_SOURCES = \
242         src/uterm_input.h \
243         src/uterm_monitor.h \
244         src/uterm_video.h \
245         src/uterm_vt.h \
246         src/uterm_input_internal.h \
247         src/uterm_video_internal.h \
248         src/uterm_systemd_internal.h \
249         src/uterm_video.c \
250         src/uterm_monitor.c \
251         src/uterm_vt.c \
252         src/uterm_input.c \
253         src/uterm_input_uxkb.c
254
255 nodist_libuterm_la_SOURCES =
256
257 libuterm_la_CPPFLAGS = \
258         $(AM_CPPFLAGS) \
259         $(UDEV_CFLAGS) \
260         $(XKBCOMMON_CFLAGS)
261 libuterm_la_LIBADD = \
262         $(UDEV_LIBS) \
263         $(XKBCOMMON_LIBS) \
264         libeloop.la \
265         libshl.la
266 libuterm_la_LDFLAGS = \
267         $(AM_LDFLAGS)
268
269 if BUILD_ENABLE_MULTI_SEAT
270 libuterm_la_SOURCES += src/uterm_systemd.c
271 libuterm_la_CPPFLAGS += $(SYSTEMD_CFLAGS)
272 libuterm_la_LIBADD += $(SYSTEMD_LIBS)
273 endif
274
275 if BUILD_ENABLE_VIDEO_FBDEV
276 libuterm_la_SOURCES += \
277         src/uterm_fbdev_internal.h \
278         src/uterm_fbdev_video.c \
279         src/uterm_fbdev_render.c
280 endif
281
282 if BUILD_ENABLE_VIDEO_DRM2D
283 libuterm_la_SOURCES += \
284         src/uterm_drm2d_internal.h \
285         src/uterm_drm2d_video.c \
286         src/uterm_drm2d_render.c
287 libuterm_la_CPPFLAGS += $(DRM_CFLAGS)
288 libuterm_la_LIBADD += $(DRM_LIBS)
289 endif
290
291 if BUILD_ENABLE_VIDEO_DRM3D
292 libuterm_la_SOURCES += \
293         src/uterm_drm3d_internal.h \
294         src/uterm_drm3d_video.c \
295         src/uterm_drm3d_render.c
296 libuterm_la_CPPFLAGS += \
297         $(DRM_CFLAGS) \
298         $(EGL_CFLAGS) \
299         $(GBM_CFLAGS) \
300         $(GLES2_CFLAGS)
301 libuterm_la_LIBADD += \
302         $(DRM_LIBS) \
303         $(EGL_LIBS) \
304         $(GBM_LIBS) \
305         $(GLES2_LIBS) \
306         src/uterm_drm3d_blend.vert.bin.lo \
307         src/uterm_drm3d_blend.frag.bin.lo \
308         src/uterm_drm3d_blit.vert.bin.lo \
309         src/uterm_drm3d_blit.frag.bin.lo \
310         src/uterm_drm3d_fill.vert.bin.lo \
311         src/uterm_drm3d_fill.frag.bin.lo
312 endif
313
314 # add shared sources only once
315 UTERM_DRM_SHARED_SRC = \
316         src/uterm_drm_shared_internal.h \
317         src/uterm_drm_shared.c
318 if BUILD_ENABLE_VIDEO_DRM2D
319 libuterm_la_SOURCES += $(UTERM_DRM_SHARED_SRC)
320 else
321 if BUILD_ENABLE_VIDEO_DRM3D
322 libuterm_la_SOURCES += $(UTERM_DRM_SHARED_SRC)
323 endif
324 endif
325
326 #
327 # Unifont Generator
328 # This generates the unifont sources from raw hex-encoded font data.
329 #
330
331 UNIFONT = $(top_srcdir)/src/font_unifont_data.hex
332 UNIFONT_BIN = src/font_unifont_data.bin
333 UNIFONT_LT = src/font_unifont_data.bin.lo
334
335 EXTRA_DIST += $(UNIFONT)
336 CLEANFILES += $(UNIFONT_BIN)
337 genunifont_SOURCES = src/genunifont.c
338
339 genunifont$(BUILD_EXEEXT) $(genunifont_OBJECTS): CC = $(CC_FOR_BUILD)
340 genunifont$(BUILD_EXEEXT) $(genunifont_OBJECTS): CFLAGS = $(CFLAGS_FOR_BUILD)
341 genunifont$(BUILD_EXEEXT): LDFLAGS = $(LDFLAGS_FOR_BUILD)
342
343 $(UNIFONT_BIN): $(UNIFONT) genunifont$(BUILD_EXEEXT)
344         $(AM_V_GEN)./genunifont$(BUILD_EXEEXT) $(UNIFONT_BIN) $(UNIFONT)
345
346 #
347 # Kmscon Modules
348 #
349
350 if BUILD_ENABLE_FONT_UNIFONT
351 module_LTLIBRARIES += mod-unifont.la
352 noinst_PROGRAMS += genunifont
353 endif
354
355 mod_unifont_la_SOURCES = \
356         src/kmscon_module_interface.h \
357         src/font_unifont.c \
358         src/kmscon_mod_unifont.c
359 mod_unifont_la_LIBADD = \
360         $(UNIFONT_LT) \
361         libshl.la
362 mod_unifont_la_LDFLAGS = \
363         $(AM_LDFLAGS) \
364         -module \
365         -avoid-version
366
367 if BUILD_ENABLE_FONT_PANGO
368 module_LTLIBRARIES += mod-pango.la
369 endif
370
371 mod_pango_la_SOURCES = \
372         src/kmscon_module_interface.h \
373         src/font_pango.c \
374         src/kmscon_mod_pango.c
375 mod_pango_la_CPPFLAGS = \
376         $(AM_CPPFLAGS) \
377         $(PANGO_CFLAGS) \
378         $(TSM_CFLAGS)
379 mod_pango_la_LIBADD = \
380         $(PANGO_LIBS) \
381         $(TSM_LIBS) \
382         -lpthread \
383         libshl.la
384 mod_pango_la_LDFLAGS = \
385         $(AM_LDFLAGS) \
386         -module \
387         -avoid-version
388
389 if BUILD_ENABLE_RENDERER_BBULK
390 module_LTLIBRARIES += mod-bbulk.la
391 endif
392
393 mod_bbulk_la_SOURCES = \
394         src/kmscon_module_interface.h \
395         src/text_bbulk.c \
396         src/kmscon_mod_bbulk.c
397 mod_bbulk_la_LIBADD = libshl.la
398 mod_bbulk_la_LDFLAGS = \
399         $(AM_LDFLAGS) \
400         -module \
401         -avoid-version
402
403 if BUILD_ENABLE_RENDERER_GLTEX
404 module_LTLIBRARIES += mod-gltex.la
405 endif
406
407 mod_gltex_la_SOURCES = \
408         src/kmscon_module_interface.h \
409         src/text_gltex.c \
410         src/kmscon_mod_gltex.c
411 mod_gltex_la_CPPFLAGS = \
412         $(AM_CPPFLAGS) \
413         $(GLES2_CFLAGS)
414 mod_gltex_la_LIBADD = \
415         $(GLES2_LIBS) \
416         libshl.la \
417         src/text_gltex_atlas.vert.bin.lo \
418         src/text_gltex_atlas.frag.bin.lo
419 mod_gltex_la_LDFLAGS = \
420         $(AM_LDFLAGS) \
421         -module \
422         -avoid-version
423
424 if BUILD_ENABLE_RENDERER_PIXMAN
425 module_LTLIBRARIES += mod-pixman.la
426 endif
427
428 mod_pixman_la_SOURCES = \
429         src/kmscon_module_interface.h \
430         src/text_pixman.c \
431         src/kmscon_mod_pixman.c
432 mod_pixman_la_CPPFLAGS = \
433         $(AM_CPPFLAGS) \
434         $(PIXMAN_CFLAGS)
435 mod_pixman_la_LIBADD = \
436         $(PIXMAN_LIBS) \
437         libshl.la
438 mod_pixman_la_LDFLAGS = \
439         $(AM_LDFLAGS) \
440         -module \
441         -avoid-version
442
443 #
444 # Binaries
445 # These are the sources for the main binaries and test programs. They mostly
446 # consists of a single source file only and include all the libraries that are
447 # built as part of kmscon.
448 #
449
450 bin_PROGRAMS += kmscon
451 check_PROGRAMS += \
452         test_output \
453         test_vt \
454         test_input \
455         test_key
456 MANPAGES += docs/man/kmscon.1
457
458 kmscon_SOURCES = \
459         src/conf.h \
460         src/conf.c \
461         src/pty.h \
462         src/pty.c \
463         src/font.h \
464         src/font.c \
465         src/font_8x16.c \
466         src/text.h \
467         src/text.c \
468         src/text_bblit.c \
469         src/kmscon_module_interface.h \
470         src/kmscon_module.h \
471         src/kmscon_module.c \
472         src/kmscon_terminal.h \
473         src/kmscon_dummy.h \
474         src/kmscon_seat.h \
475         src/kmscon_seat.c \
476         src/kmscon_conf.h \
477         src/kmscon_conf.c \
478         src/kmscon_main.c
479 nodist_kmscon_SOURCES =
480
481 kmscon_CPPFLAGS = \
482         $(AM_CPPFLAGS) \
483         $(XKBCOMMON_CFLAGS) \
484         $(TSM_CFLAGS)
485 kmscon_LDADD = \
486         $(XKBCOMMON_LIBS) \
487         $(TSM_LIBS) \
488         libeloop.la \
489         libuterm.la \
490         libshl.la \
491         -lpthread \
492         -ldl
493 kmscon_LDFLAGS = \
494         $(AM_LDFLAGS) \
495         -rdynamic
496
497 if BUILD_ENABLE_SESSION_DUMMY
498 kmscon_SOURCES += src/kmscon_dummy.c
499 endif
500
501 if BUILD_ENABLE_SESSION_TERMINAL
502 kmscon_SOURCES += src/kmscon_terminal.c
503 endif
504
505 #
506 # Tests
507 #
508
509 test_sources = \
510         src/conf.h \
511         src/conf.c \
512         tests/test_include.h
513 test_cflags = \
514         $(AM_CPPFLAGS) \
515         $(XKBCOMMON_CFLAGS)
516 test_libs = \
517         $(XKBCOMMON_LIBS) \
518         libeloop.la \
519         libshl.la
520
521 test_output_SOURCES = \
522         $(test_sources) \
523         tests/test_output.c
524 test_output_CPPFLAGS = $(test_cflags)
525 test_output_LDADD = \
526         $(test_libs) \
527         libuterm.la
528
529 test_vt_SOURCES = \
530         $(test_sources) \
531         tests/test_vt.c
532 test_vt_CPPFLAGS = $(test_cflags)
533 test_vt_LDADD = \
534         $(test_libs) \
535         libuterm.la
536
537 test_input_SOURCES = \
538         $(test_sources) \
539         tests/test_input.c
540 test_input_CPPFLAGS = $(test_cflags)
541 test_input_LDADD = \
542         $(test_libs) \
543         libuterm.la
544
545 test_key_SOURCES = \
546         $(test_sources) \
547         tests/test_key.c
548 test_key_CPPFLAGS = $(test_cflags)
549 test_key_LDADD = $(test_libs)
550
551 #
552 # Manpages
553 #
554
555 man_MANS =
556 EXTRA_DIST += ${patsubst %.1,%.xml,${patsubst %.3,%.xml,${patsubst %.5,%.xml,${patsubst %.7,%.xml,$(MANPAGES)}}}}
557 CLEANFILES += $(MANPAGES) $(MANPAGES_ALIASES) .man_fixup
558
559 if BUILD_HAVE_XSLTPROC
560 if BUILD_HAVE_MANPAGES_STYLESHEET
561
562 man_MANS += $(MANPAGES) $(MANPAGES_ALIASES)
563
564 XSLTPROC_FLAGS = \
565         --stringparam man.authors.section.enabled 0 \
566         --stringparam man.copyright.section.enabled 0 \
567         --stringparam funcsynopsis.style ansi \
568         --stringparam man.output.quietly 1 \
569         --nonet
570
571 XSLTPROC_PROCESS_MAN = \
572         $(AM_V_GEN)$(MKDIR_P) $(dir $@) && \
573         $(XSLTPROC) -o "$@" $(XSLTPROC_FLAGS) $(BUILD_MANPAGES_STYLESHEET) "$<" && \
574         touch .man_fixup
575
576 # Force .man_fixup if $(MANPAGES) are not built
577 .man_fixup: | $(MANPAGES)
578         @touch .man_fixup
579
580 $(MANPAGES_ALIASES): $(MANPAGES) .man_fixup
581         $(AM_V_GEN)if test -n "$@" ; then $(SED) -i -e 's/^\.so \([a-z_]\+\)\.\([0-9]\)$$/\.so man\2\/\1\.\2/' "$@" ; fi
582
583 docs/man/%.1: docs/man/%.xml
584         $(XSLTPROC_PROCESS_MAN)
585
586 docs/man/%.3: docs/man/%.xml
587         $(XSLTPROC_PROCESS_MAN)
588
589 docs/man/%.5: docs/man/%.xml
590         $(XSLTPROC_PROCESS_MAN)
591
592 docs/man/%.7: docs/man/%.xml
593         $(XSLTPROC_PROCESS_MAN)
594
595 endif # BUILD_HAVE_MANPAGES_STYLESHEET
596 endif # BUILD_HAVE_XSLTPROC
597
598 #
599 # Phony targets
600 #
601
602 .PHONY: $(TPHONY)
603
604 #
605 # Empty .SECONDARY target causes alle intermediate files to be treated as
606 # secondary files. That is, they don't get deleted after make finished.
607 #
608
609 .SECONDARY: