summaryrefslogtreecommitdiff
path: root/Makefile
blob: 8742c0f3b2e4849b52d9608f6419caf4582e0673 (plain)
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
PLUGIN  = inputdev
VERSION = 0.0.1

### The C++ compiler and options:

CXX		?= $(CC)
TAR		?= tar
XZ		?= xz
GZIP		?= gzip
MSGFMT		?= msgfmt
MSGMERGE	?= msgmerge
XGETTEXT	?= xgettext
PKG_CONFIG	?= pkg-config

SYSTEMD_CFLAGS	 = $(shell ${PKG_CONFIG} --cflags libsystemd-daemon || echo "libsystemd_missing")
SYSTEMD_LIBS	 = $(shell ${PKG_CONFIG} --libs libsystemd-daemon || echo "libsystemd_missing")

TAR_FLAGS	 = --owner root --group root --mode a+rX,go-w

AM_CPPFLAGS	 = -DPACKAGE_VERSION=\"${VERSION}\" -DSOCKET_PATH=\"${SOCKET_PATH}\" \
		   -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'

WARN_OPTS	 = -Wall -W -Wno-missing-field-initializers -Wextra

AM_CXXFLAGS	+= $(WARN_OPTS)
AM_CFLAGS	+= $(WARN_OPTS)

ifneq ($(USE_SYSTEMD),)
AM_CPPFLAGS	+= -DVDR_USE_SYSTEMD
AM_CXXFLAGS	+= ${SYSTEMD_CFLAGS}
LIBS		+= ${SYSTEMD_LIBS}
endif

plugin_SOURCES = \
	inputdev.cc \
	inputdev.h \
	plugin.cc \

helper_SOURCES = \
	udevhelper.c

extra_SOURCES = \
	Makefile \
	README.txt \
	contrib/96-vdrkeymap.rules \
	contrib/hama-mce \
	contrib/tt6400-ir \
	contrib/x10-wti

### The directory environment:

VDRDIR ?= ../../..
LIBDIR ?= ../../lib
TMPDIR ?= /tmp

SOCKET_PATH = /var/run/vdr/inputdev

### Allow user defined options to overwrite defaults:

include $(VDRDIR)/Make.global
-include $(VDRDIR)/Make.config

### The version number of VDR's plugin API (taken from VDR's "config.h"):

APIVERSION = $(shell sed -ne '/define APIVERSION/s/^.*"\(.*\)".*$$/\1/p' $(VDRDIR)/config.h)

### The name of the distribution archive:

ARCHIVE = $(PLUGIN)-$(VERSION)
PACKAGE = vdr-$(ARCHIVE).tar

### The object files (add further files here):

_all_sources = $(plugin_SOURCES) $(helper_SOURCES) $(extra_SOURCES)

_objects = \
  $(patsubst %.c,%.o,$(filter %.c,$(plugin_SOURCES))) \
  $(patsubst %.cc,%.o,$(filter %.cc,$(plugin_SOURCES)))

plugin_OBJS = $(call _objects,$(plugin_SOURCES))
helper_OBJS = $(call _objects,$(helper_SOURCES))

OBJS = $(plugin_OBJS) $(helper_OBJS)

### The main target:

all: libvdr-$(PLUGIN).so vdr-inputdev i18n

### Implicit rules:
_buildflags = $(foreach k,CPP $1 LD, $(AM_$kFLAGS) $($kFLAGS) $($kFLAGS_$@))

%.o: %.c
	$(CC) $(call _buildflags,C) -MMD -MP -c $< -o $@

%.o: %.cc
	$(CC) $(call _buildflags,CXX) -MMD -MP -c $< -o $@

%.xz:	%
	@rm -f $@.tmp $@
	$(XZ) -c < $< >$@.tmp
	@mv $@.tmp $@

%.gz:	%
	@rm -f $@.tmp $@
	$(GZIP) -c < $< >$@.tmp
	@mv $@.tmp $@

%.mo: %.po
	$(MSGFMT) -c -o $@ $<


-include $(OBJS:%.o=%.d)

### Internationalization (I18N):

PODIR     = po
LOCALEDIR = $(VDRDIR)/locale
I18Npo    = $(wildcard $(PODIR)/*.po)
I18Nmsgs  = $(addprefix $(LOCALEDIR)/, $(addsuffix /LC_MESSAGES/vdr-$(PLUGIN).mo, $(notdir $(foreach file, $(I18Npo), $(basename $(file))))))
I18Npot   = $(PODIR)/$(PLUGIN).pot

$(I18Npot): $(wildcard *.c *.cc)
	$(XGETTEXT) -C -cTRANSLATORS --no-wrap --no-location -k -ktr -ktrNOOP --package-name=vdr-$(PLUGIN) --package-version=$(VERSION) --msgid-bugs-address='<see README>' -o $@ $^

%.po: $(I18Npot)
	$(MSGMERGE) -U --no-wrap --no-location --backup=none -q $@ $<
	@touch $@

$(I18Nmsgs): $(LOCALEDIR)/%/LC_MESSAGES/vdr-$(PLUGIN).mo: $(PODIR)/%.mo
	@mkdir -p $(dir $@)
	cp $< $@

.PHONY: i18n
i18n: $(I18Nmsgs) $(I18Npot)

### Targets:
vdr-inputdev:	$(helper_SOURCES)
	$(CC) $(call _buildflags,C) $^ -o $@

libvdr-$(PLUGIN).so: $(plugin_OBJS)
	$(CXX) $(AM_LDFLAGS) $(LDFLAGS) $(LDFLAGS_$@) -shared -o $@ $^ $(LIBS)
	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)

dist:  $(PACKAGE).xz $(PACKAGE).gz

_tar_transform = --transform='s!^!$(ARCHIVE)/!'

$(PACKAGE):	$(I18Npo) $(_all_sources)
	$(TAR) cf $@ $(TAR_FLAGS) $(_tar_transform) $(sort $^)

clean:
	@rm -f $(OBJS) libvdr*.so libvdr*.so.* *.d *.tgz core* *~ $(PODIR)/*.mo $(PODIR)/*.pot
	@rm -f vdr-inputdev