Makefile 5 KB
Newer Older
Slava Monich's avatar
Slava Monich committed
1 2
# -*- Mode: makefile-gmake -*-

Slava Monich's avatar
Slava Monich committed
3
.PHONY: clean all debug release pkgconfig install install-dev
Slava Monich's avatar
Slava Monich committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

#
# Required packages
#

PKGS = glib-2.0 gio-2.0 gio-unix-2.0 libglibutil

#
# Default target
#

all: debug release pkgconfig

#
# Library version
#

VERSION_MAJOR = 1
VERSION_MINOR = 0
Slava Monich's avatar
Slava Monich committed
23
VERSION_RELEASE = 10
Slava Monich's avatar
Slava Monich committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

# Version for pkg-config
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)

NAME = mce-glib
LIB_NAME = lib$(NAME)
LIB_DEV_SYMLINK = $(LIB_NAME).so
LIB_SYMLINK1 = $(LIB_DEV_SYMLINK).$(VERSION_MAJOR)
LIB_SYMLINK2 = $(LIB_SYMLINK1).$(VERSION_MINOR)
LIB_SONAME = $(LIB_SYMLINK1)
LIB = $(LIB_SONAME).$(VERSION_MINOR).$(VERSION_RELEASE)

#
# Sources
#

SRC = \
41
  mce_battery.c \
42
  mce_charger.c \
Slava Monich's avatar
Slava Monich committed
43
  mce_display.c \
44 45
  mce_proxy.c \
  mce_tklock.c
Slava Monich's avatar
Slava Monich committed
46
GEN_SRC = \
47 48
  com.nokia.mce.request.c \
  com.nokia.mce.signal.c
Slava Monich's avatar
Slava Monich committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

#
# Directories
#

SRC_DIR = src
INCLUDE_DIR = include
BUILD_DIR = build
GEN_DIR = $(BUILD_DIR)
SPEC_DIR = spec
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release

#
# Tools and flags
#

66
CC ?= $(CROSS_COMPILE)gcc
Slava Monich's avatar
Slava Monich committed
67
LD = $(CC)
68
DEFINES += -DGLIB_DISABLE_DEPRECATION_WARNINGS
Slava Monich's avatar
Slava Monich committed
69 70 71 72 73
WARNINGS = -Wall -Wno-unused-parameter -Wno-multichar
INCLUDES = -I$(INCLUDE_DIR) -I$(GEN_DIR)
BASE_FLAGS = -fPIC $(CFLAGS)
FULL_CFLAGS = $(BASE_FLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \
  $(shell pkg-config --cflags $(PKGS))
74 75
FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) \
  -Wl,--version-script=$(LIB_NAME).map
Slava Monich's avatar
Slava Monich committed
76 77 78
DEBUG_FLAGS = -g
RELEASE_FLAGS =

79
KEEP_SYMBOLS ?= 0
Slava Monich's avatar
Slava Monich committed
80 81 82 83 84 85
ifneq ($(KEEP_SYMBOLS),0)
RELEASE_FLAGS += -g
endif

DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
86 87
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS)
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS)
Slava Monich's avatar
Slava Monich committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101

#
# Files
#

PKGCONFIG = \
  $(BUILD_DIR)/$(LIB_NAME).pc
DEBUG_OBJS = \
  $(GEN_SRC:%.c=$(DEBUG_BUILD_DIR)/%.o) \
  $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
RELEASE_OBJS = \
  $(GEN_SRC:%.c=$(RELEASE_BUILD_DIR)/%.o) \
  $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
GEN_FILES = $(GEN_SRC:%=$(GEN_DIR)/%)
102
LIBS = $(shell pkg-config --libs $(PKGS))
Slava Monich's avatar
Slava Monich committed
103 104 105 106 107 108 109 110 111 112 113 114 115
.PRECIOUS: $(GEN_FILES)

#
# Dependencies
#

DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
endif

116 117 118 119 120
DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB)
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)
DEBUG_LINK = $(DEBUG_BUILD_DIR)/$(LIB_SONAME)
RELEASE_LINK = $(RELEASE_BUILD_DIR)/$(LIB_SONAME)

Slava Monich's avatar
Slava Monich committed
121
$(GEN_FILES): | $(GEN_DIR)
Slava Monich's avatar
Slava Monich committed
122 123
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) $(GEN_FILES)
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) $(GEN_FILES)
124 125 126
$(PKGCONFIG): | $(BUILD_DIR)
$(DEBUG_LINK): | $(DEBUG_LIB)
$(RELEASE_LINK): | $(RELEASE_LIB)
Slava Monich's avatar
Slava Monich committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

#
# Rules
#

debug: $(DEBUG_LIB) $(DEBUG_LINK)

release: $(RELEASE_LIB) $(RELEASE_LINK)

clean:
	rm -f *~ $(SRC_DIR)/*~ $(INCLUDE_DIR)/*~ rpm/*~
	rm -fr $(BUILD_DIR) RPMS installroot
	rm -fr debian/tmp debian/lib$(NAME) debian/lib$(NAME)-dev
	rm -f documentation.list debian/files debian/*.substvars
	rm -f debian/*.debhelper.log debian/*.debhelper debian/*~
142
	rm -f debian/*.install
Slava Monich's avatar
Slava Monich committed
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

$(GEN_DIR):
	mkdir -p $@

$(DEBUG_BUILD_DIR):
	mkdir -p $@

$(RELEASE_BUILD_DIR):
	mkdir -p $@

$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
	gdbus-codegen --generate-c-code $(@:%.c=%) $<

$(DEBUG_BUILD_DIR)/%.o : $(GEN_DIR)/%.c
	$(CC) -c -I. $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(RELEASE_BUILD_DIR)/%.o : $(GEN_DIR)/%.c
	$(CC) -c -I. $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
	$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
	$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

168
$(DEBUG_LIB): $(DEBUG_OBJS)
169
	$(LD) $(DEBUG_LDFLAGS) -o $@ $^ $(LIBS)
Slava Monich's avatar
Slava Monich committed
170

171
$(RELEASE_LIB): $(RELEASE_OBJS)
172
	$(LD) $(RELEASE_LDFLAGS) -o $@ $^ $(LIBS)
Slava Monich's avatar
Slava Monich committed
173 174 175 176 177 178 179 180 181 182
ifeq ($(KEEP_SYMBOLS),0)
	strip $@
endif

$(DEBUG_LINK):
	ln -sf $(LIB) $@

$(RELEASE_LINK):
	ln -sf $(LIB) $@

183 184 185 186 187 188
# This one could be substituted with arch specific dir
LIBDIR ?= /usr/lib
ABS_LIBDIR := $(shell echo /$(LIBDIR) | sed -r 's|/+|/|g')

pkgconfig: $(PKGCONFIG)

189
$(PKGCONFIG): $(LIB_NAME).pc.in Makefile
190 191 192 193
	sed -e 's|@version@|$(PCVERSION)|g' -e 's|@libdir@|$(ABS_LIBDIR)|g' $< > $@

debian/%.install: debian/%.install.in
	sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@
Slava Monich's avatar
Slava Monich committed
194 195 196 197 198 199 200

#
# Install
#

INSTALL = install
INSTALL_DIRS = $(INSTALL) -d
201
INSTALL_FILES = $(INSTALL) -m 644
Slava Monich's avatar
Slava Monich committed
202

203
INSTALL_LIB_DIR = $(DESTDIR)$(ABS_LIBDIR)
Slava Monich's avatar
Slava Monich committed
204
INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/$(LIB_NAME)
205
INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ABS_LIBDIR)/pkgconfig
Slava Monich's avatar
Slava Monich committed
206 207

install: $(INSTALL_LIB_DIR)
208
	$(INSTALL) -m 755 $(RELEASE_LIB) $(INSTALL_LIB_DIR)
Slava Monich's avatar
Slava Monich committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
	ln -sf $(LIB) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK2)
	ln -sf $(LIB_SYMLINK2) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK1)

install-dev: install $(INSTALL_INCLUDE_DIR) $(INSTALL_PKGCONFIG_DIR)
	$(INSTALL_FILES) $(INCLUDE_DIR)/*.h $(INSTALL_INCLUDE_DIR)
	$(INSTALL_FILES) $(PKGCONFIG) $(INSTALL_PKGCONFIG_DIR)
	ln -sf $(LIB_SYMLINK1) $(INSTALL_LIB_DIR)/$(LIB_DEV_SYMLINK)

$(INSTALL_LIB_DIR):
	$(INSTALL_DIRS) $@

$(INSTALL_INCLUDE_DIR):
	$(INSTALL_DIRS) $@

$(INSTALL_PKGCONFIG_DIR):
	$(INSTALL_DIRS) $@