build: link eloop statically
[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)echo "# $@ - a libtool object file" >"$@"
135         $(AM_V_at)echo "# Generated by $(shell $(LIBTOOL) --version | head -n 1)" >>"$@"
136         $(AM_V_at)echo "#" >>"$@"
137         $(AM_V_at)echo "# Please DO NOT delete this file!" >>"$@"
138         $(AM_V_at)echo "# It is necessary for linking the library." >>"$@"
139         $(AM_V_at)echo >>"$@"
140         $(AM_V_at)echo "# Name of the PIC object." >>"$@"
141         $(AM_V_at)echo "pic_object='$*.bin.o'" >>"$@"
142         $(AM_V_at)echo >>"$@"
143         $(AM_V_at)echo "# Name of the non-PIC object" >>"$@"
144         $(AM_V_at)echo "non_pic_object='$*.bin.o'" >>"$@"
145         $(AM_V_at)echo >>"$@"
146
147 #
148 # SHL - Static Helper Library
149 # The SHL subsystem contains several small code pieces used all over kmscon and
150 # other applications.
151 #
152
153 noinst_LTLIBRARIES += libshl.la
154
155 libshl_la_SOURCES = \
156         src/shl_githead.h \
157         src/shl_githead.c \
158         src/shl_dlist.h \
159         src/shl_array.h \
160         src/shl_hashtable.h \
161         external/htable.h \
162         external/htable.c \
163         src/shl_ring.h \
164         src/shl_timer.h \
165         src/shl_llog.h \
166         src/shl_log.h \
167         src/shl_log.c \
168         src/shl_hook.h \
169         src/shl_misc.h \
170         src/shl_register.h \
171         src/shl_flagset.h
172 libshl_la_CPPFLAGS = \
173         $(AM_CPPFLAGS) \
174         $(XKBCOMMON_CFLAGS) \
175         -pthread
176 libshl_la_LDFLAGS = \
177         $(AM_LDFLAGS) \
178         -pthread
179 libshl_la_LIBADD = \
180         $(AM_LIBADD) \
181         $(XKBCOMMON_LIBS)
182
183 #
184 # libeloop
185 # This library contains the whole event-loop implementation of kmscon. It is
186 # compiled into a separate object to allow using it in several other programs.
187 #
188
189 noinst_LTLIBRARIES += libeloop.la
190
191 libeloop_la_SOURCES = \
192         src/eloop.h \
193         src/eloop.c
194
195 libeloop_la_LIBADD = libshl.la
196 libeloop_la_CPPFLAGS = $(AM_CPPFLAGS)
197 libeloop_la_LDFLAGS = $(AM_LDFLAGS)
198
199 #
200 # libuterm
201 # The uterm library provides helpers to create terminals in user-space. They
202 # are not limited to text-based terminals but rather provide graphics contexts
203 # so arbitrary output can be displayed. Additionally, they provide VT
204 # abstractions and an input layer
205 #
206
207 noinst_LTLIBRARIES += libuterm.la
208
209 libuterm_la_SOURCES = \
210         src/uterm_input.h \
211         src/uterm_monitor.h \
212         src/uterm_video.h \
213         src/uterm_vt.h \
214         src/uterm_input_internal.h \
215         src/uterm_video_internal.h \
216         src/uterm_systemd_internal.h \
217         src/uterm_video.c \
218         src/uterm_monitor.c \
219         src/uterm_vt.c \
220         src/uterm_input.c \
221         src/uterm_input_uxkb.c
222
223 nodist_libuterm_la_SOURCES =
224
225 libuterm_la_CPPFLAGS = \
226         $(AM_CPPFLAGS) \
227         $(XKBCOMMON_CFLAGS)
228 libuterm_la_LIBADD = \
229         $(XKBCOMMON_LIBS) \
230         libeloop.la \
231         libshl.la
232 libuterm_la_LDFLAGS = \
233         $(AM_LDFLAGS)
234
235 if BUILD_ENABLE_MULTI_SEAT
236 libuterm_la_SOURCES += src/uterm_systemd.c
237 libuterm_la_CPPFLAGS += $(SYSTEMD_CFLAGS)
238 libuterm_la_LIBADD += $(SYSTEMD_LIBS)
239 endif
240
241 if BUILD_ENABLE_HOTPLUG
242 libuterm_la_CPPFLAGS += $(UDEV_CFLAGS)
243 libuterm_la_LIBADD += $(UDEV_LIBS)
244 endif
245
246 if BUILD_ENABLE_VIDEO_FBDEV
247 libuterm_la_SOURCES += \
248         src/uterm_fbdev_internal.h \
249         src/uterm_fbdev_video.c \
250         src/uterm_fbdev_render.c
251 endif
252
253 if BUILD_ENABLE_VIDEO_DRM2D
254 libuterm_la_SOURCES += \
255         src/uterm_drm2d_internal.h \
256         src/uterm_drm2d_video.c \
257         src/uterm_drm2d_render.c
258 libuterm_la_CPPFLAGS += $(DRM_CFLAGS)
259 libuterm_la_LIBADD += $(DRM_LIBS)
260 endif
261
262 if BUILD_ENABLE_VIDEO_DRM3D
263 noinst_PROGRAMS += genshader
264 libuterm_la_SOURCES += \
265         src/uterm_drm3d_internal.h \
266         src/uterm_drm3d_video.c \
267         src/uterm_drm3d_render.c \
268         src/static_gl.h \
269         src/static_gl_math.c \
270         src/static_gl_shader.c
271 nodist_libuterm_la_SOURCES += src/static_shaders.c
272 libuterm_la_CPPFLAGS += \
273         $(DRM_CFLAGS) \
274         $(EGL_CFLAGS) \
275         $(GBM_CFLAGS) \
276         $(GLES2_CFLAGS)
277 libuterm_la_LIBADD += \
278         $(DRM_LIBS) \
279         $(EGL_LIBS) \
280         $(GBM_LIBS) \
281         $(GLES2_LIBS)
282 endif
283
284 # add shared sources only once
285 UTERM_DRM_SHARED_SRC = \
286         src/uterm_drm_shared_internal.h \
287         src/uterm_drm_shared.c
288 if BUILD_ENABLE_VIDEO_DRM2D
289 libuterm_la_SOURCES += $(UTERM_DRM_SHARED_SRC)
290 else
291 if BUILD_ENABLE_VIDEO_DRM3D
292 libuterm_la_SOURCES += $(UTERM_DRM_SHARED_SRC)
293 endif
294 endif
295
296 #
297 # Shaders
298 # As there is no need to modify shaders at run-time, we statically compile them
299 # into object files. As autotools would ignore them, we need to add them to
300 # EXTRA_DIST.
301 # The program that converts the shaders into C-source files is "genshader". It's
302 # pretty simple and just creates a string with the shader source as content.
303 #
304
305 SHADERS = \
306         $(srcdir)/src/static_fill.vert \
307         $(srcdir)/src/static_fill.frag \
308         $(srcdir)/src/static_blend.vert \
309         $(srcdir)/src/static_blend.frag \
310         $(srcdir)/src/static_blit.vert \
311         $(srcdir)/src/static_blit.frag \
312         $(srcdir)/src/static_gltex.vert \
313         $(srcdir)/src/static_gltex.frag
314
315 EXTRA_DIST += $(SHADERS)
316 CLEANFILES += src/static_shaders.c
317 genshader_SOURCES = src/genshader.c
318
319 # TODO: Using $(BUILD_EXEEXT) breaks if it doesn't equal $(EXEEXT). But stupid
320 # automake doesn't allow $(EXEEXT) so lets just rely on both being the same.
321
322 src/static_shaders.c: $(SHADERS) genshader$(BUILD_EXEEXT)
323         $(AM_V_GEN)./genshader$(BUILD_EXEEXT) src/static_shaders.c $(SHADERS)
324
325 genshader$(BUILD_EXEEXT) $(genshader_OBJECTS): CC = $(CC_FOR_BUILD)
326 genshader$(BUILD_EXEEXT) $(genshader_OBJECTS): CFLAGS = $(CFLAGS_FOR_BUILD)
327 genshader$(BUILD_EXEEXT): LDFLAGS = $(LDFLAGS_FOR_BUILD)
328
329 #
330 # Unifont Generator
331 # This generates the unifont sources from raw hex-encoded font data.
332 #
333
334 UNIFONT = $(top_srcdir)/src/font_unifont_data.hex
335 UNIFONT_BIN = src/font_unifont_data.bin
336 UNIFONT_LT = src/font_unifont_data.bin.lo
337
338 EXTRA_DIST += $(UNIFONT)
339 CLEANFILES += $(UNIFONT_BIN)
340 genunifont_SOURCES = src/genunifont.c
341
342 genunifont$(BUILD_EXEEXT) $(genunifont_OBJECTS): CC = $(CC_FOR_BUILD)
343 genunifont$(BUILD_EXEEXT) $(genunifont_OBJECTS): CFLAGS = $(CFLAGS_FOR_BUILD)
344 genunifont$(BUILD_EXEEXT): LDFLAGS = $(LDFLAGS_FOR_BUILD)
345
346 $(UNIFONT_BIN): $(UNIFONT) genunifont$(BUILD_EXEEXT)
347         $(AM_V_GEN)./genunifont$(BUILD_EXEEXT) $(UNIFONT_BIN) $(UNIFONT)
348
349 #
350 # Kmscon Modules
351 #
352
353 if BUILD_ENABLE_FONT_UNIFONT
354 module_LTLIBRARIES += mod-unifont.la
355 noinst_PROGRAMS += genunifont
356 endif
357
358 mod_unifont_la_SOURCES = \
359         src/kmscon_module_interface.h \
360         src/font_unifont.c \
361         src/kmscon_mod_unifont.c
362 mod_unifont_la_LIBADD = \
363         $(UNIFONT_LT) \
364         libshl.la
365 mod_unifont_la_LDFLAGS = \
366         $(AM_LDFLAGS) \
367         -module \
368         -avoid-version
369
370 if BUILD_ENABLE_FONT_PANGO
371 module_LTLIBRARIES += mod-pango.la
372 endif
373
374 mod_pango_la_SOURCES = \
375         src/kmscon_module_interface.h \
376         src/font_pango.c \
377         src/kmscon_mod_pango.c
378 mod_pango_la_CPPFLAGS = \
379         $(AM_CPPFLAGS) \
380         $(PANGO_CFLAGS) \
381         $(TSM_CFLAGS)
382 mod_pango_la_LIBADD = \
383         $(PANGO_LIBS) \
384         $(TSM_LIBS) \
385         -lpthread \
386         libshl.la
387 mod_pango_la_LDFLAGS = \
388         $(AM_LDFLAGS) \
389         -module \
390         -avoid-version
391
392 if BUILD_ENABLE_RENDERER_BBULK
393 module_LTLIBRARIES += mod-bbulk.la
394 endif
395
396 mod_bbulk_la_SOURCES = \
397         src/kmscon_module_interface.h \
398         src/text_bbulk.c \
399         src/kmscon_mod_bbulk.c
400 mod_bbulk_la_LIBADD = libshl.la
401 mod_bbulk_la_LDFLAGS = \
402         $(AM_LDFLAGS) \
403         -module \
404         -avoid-version
405
406 if BUILD_ENABLE_RENDERER_GLTEX
407 module_LTLIBRARIES += mod-gltex.la
408 noinst_PROGRAMS += genshader
409 endif
410
411 mod_gltex_la_SOURCES = \
412         src/kmscon_module_interface.h \
413         src/text_gltex.c \
414         src/static_gl.h \
415         src/static_gl_math.c \
416         src/static_gl_shader.c \
417         src/kmscon_mod_gltex.c
418 nodist_mod_gltex_la_SOURCES = \
419         src/static_shaders.c
420 mod_gltex_la_CPPFLAGS = \
421         $(AM_CPPFLAGS) \
422         $(GLES2_CFLAGS)
423 mod_gltex_la_LIBADD = \
424         $(GLES2_LIBS) \
425         libshl.la
426 mod_gltex_la_LDFLAGS = \
427         $(AM_LDFLAGS) \
428         -module \
429         -avoid-version
430
431 if BUILD_ENABLE_RENDERER_PIXMAN
432 module_LTLIBRARIES += mod-pixman.la
433 endif
434
435 mod_pixman_la_SOURCES = \
436         src/kmscon_module_interface.h \
437         src/text_pixman.c \
438         src/kmscon_mod_pixman.c
439 mod_pixman_la_CPPFLAGS = \
440         $(AM_CPPFLAGS) \
441         $(PIXMAN_CFLAGS)
442 mod_pixman_la_LIBADD = \
443         $(PIXMAN_LIBS) \
444         libshl.la
445 mod_pixman_la_LDFLAGS = \
446         $(AM_LDFLAGS) \
447         -module \
448         -avoid-version
449
450 #
451 # Binaries
452 # These are the sources for the main binaries and test programs. They mostly
453 # consists of a single source file only and include all the libraries that are
454 # built as part of kmscon.
455 #
456
457 if BUILD_ENABLE_KMSCON
458 bin_PROGRAMS += kmscon
459 check_PROGRAMS += \
460         test_output \
461         test_vt \
462         test_input \
463         test_key
464 MANPAGES += docs/man/kmscon.1
465 endif
466
467 kmscon_SOURCES = \
468         src/conf.h \
469         src/conf.c \
470         src/pty.h \
471         src/pty.c \
472         src/font.h \
473         src/font.c \
474         src/font_8x16.c \
475         src/text.h \
476         src/text.c \
477         src/text_bblit.c \
478         src/kmscon_module_interface.h \
479         src/kmscon_module.h \
480         src/kmscon_module.c \
481         src/kmscon_terminal.h \
482         src/kmscon_dummy.h \
483         src/kmscon_seat.h \
484         src/kmscon_seat.c \
485         src/kmscon_conf.h \
486         src/kmscon_conf.c \
487         src/kmscon_main.c
488 nodist_kmscon_SOURCES =
489
490 kmscon_CPPFLAGS = \
491         $(AM_CPPFLAGS) \
492         $(XKBCOMMON_CFLAGS) \
493         $(TSM_CFLAGS)
494 kmscon_LDADD = \
495         $(XKBCOMMON_LIBS) \
496         $(TSM_LIBS) \
497         libeloop.la \
498         libuterm.la \
499         libshl.la \
500         -lpthread \
501         -ldl
502 kmscon_LDFLAGS = \
503         $(AM_LDFLAGS) \
504         -rdynamic
505
506 if BUILD_ENABLE_SESSION_DUMMY
507 kmscon_SOURCES += src/kmscon_dummy.c
508 endif
509
510 if BUILD_ENABLE_SESSION_TERMINAL
511 kmscon_SOURCES += src/kmscon_terminal.c
512 endif
513
514 #
515 # Tests
516 #
517
518 test_sources = \
519         src/conf.h \
520         src/conf.c \
521         tests/test_include.h
522 test_cflags = \
523         $(AM_CPPFLAGS) \
524         $(XKBCOMMON_CFLAGS)
525 test_libs = \
526         $(XKBCOMMON_LIBS) \
527         libeloop.la \
528         libshl.la
529
530 test_output_SOURCES = \
531         $(test_sources) \
532         tests/test_output.c
533 test_output_CPPFLAGS = $(test_cflags)
534 test_output_LDADD = \
535         $(test_libs) \
536         libuterm.la
537
538 test_vt_SOURCES = \
539         $(test_sources) \
540         tests/test_vt.c
541 test_vt_CPPFLAGS = $(test_cflags)
542 test_vt_LDADD = \
543         $(test_libs) \
544         libuterm.la
545
546 test_input_SOURCES = \
547         $(test_sources) \
548         tests/test_input.c
549 test_input_CPPFLAGS = $(test_cflags)
550 test_input_LDADD = \
551         $(test_libs) \
552         libuterm.la
553
554 test_key_SOURCES = \
555         $(test_sources) \
556         tests/test_key.c
557 test_key_CPPFLAGS = $(test_cflags)
558 test_key_LDADD = $(test_libs)
559
560 #
561 # Manpages
562 #
563
564 man_MANS =
565 EXTRA_DIST += ${patsubst %.1,%.xml,${patsubst %.3,%.xml,${patsubst %.5,%.xml,${patsubst %.7,%.xml,$(MANPAGES)}}}}
566 CLEANFILES += $(MANPAGES) $(MANPAGES_ALIASES) .man_fixup
567
568 if BUILD_HAVE_XSLTPROC
569 if BUILD_HAVE_MANPAGES_STYLESHEET
570
571 man_MANS += $(MANPAGES) $(MANPAGES_ALIASES)
572
573 XSLTPROC_FLAGS = \
574         --stringparam man.authors.section.enabled 0 \
575         --stringparam man.copyright.section.enabled 0 \
576         --stringparam funcsynopsis.style ansi \
577         --stringparam man.output.quietly 1 \
578         --nonet
579
580 XSLTPROC_PROCESS_MAN = \
581         $(AM_V_GEN)$(MKDIR_P) $(dir $@) && \
582         $(XSLTPROC) -o "$@" $(XSLTPROC_FLAGS) $(BUILD_MANPAGES_STYLESHEET) "$<" && \
583         touch .man_fixup
584
585 # Force .man_fixup if $(MANPAGES) are not built
586 .man_fixup: | $(MANPAGES)
587         @touch .man_fixup
588
589 $(MANPAGES_ALIASES): $(MANPAGES) .man_fixup
590         $(AM_V_GEN)if test -n "$@" ; then $(SED) -i -e 's/^\.so \([a-z_]\+\)\.\([0-9]\)$$/\.so man\2\/\1\.\2/' "$@" ; fi
591
592 docs/man/%.1: docs/man/%.xml
593         $(XSLTPROC_PROCESS_MAN)
594
595 docs/man/%.3: docs/man/%.xml
596         $(XSLTPROC_PROCESS_MAN)
597
598 docs/man/%.5: docs/man/%.xml
599         $(XSLTPROC_PROCESS_MAN)
600
601 docs/man/%.7: docs/man/%.xml
602         $(XSLTPROC_PROCESS_MAN)
603
604 endif # BUILD_HAVE_MANPAGES_STYLESHEET
605 endif # BUILD_HAVE_XSLTPROC
606
607 #
608 # Phony targets
609 #
610
611 .PHONY: $(TPHONY)