Makefile 3.82 KB
Newer Older
1
# -*- Mode: makefile-gmake -*-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

.PHONY: clean all debug release pkgconfig install install-dev

# Required packages
PKGS = glib-2.0

#
# Default target
#

all: debug release pkgconfig

#
# Library version
#

18
VERSION_MAJOR = 2
19
VERSION_MINOR = 2
Slava Monich's avatar
Slava Monich committed
20
VERSION_RELEASE = 4
21

22
VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
23
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
24

25 26 27
NAME = wspcodec
LIB_NAME = lib$(NAME)
LIB_SHORTCUT = $(LIB_NAME)-$(VERSION).so
28 29
LIB_SONAME = $(LIB_SHORTCUT)
LIB = $(LIB_SONAME).$(VERSION_RELEASE)
30 31 32 33 34 35 36 37 38 39 40

#
# Sources
#

SRC = wsputil.c

#
# Directories
#

41
SRC_DIR = wspcodec
42 43 44 45 46 47 48 49 50 51 52 53
BUILD_DIR = build
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release

#
# Tools and flags
#

CC = $(CROSS_COMPILE)gcc
LD = $(CC)
WARNINGS = -Wall
INCLUDES = -I$(SRC_DIR)
54
BASE_FLAGS = -fPIC
55 56 57
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
  -MMD -MP $(shell pkg-config --cflags $(PKGS))
FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname=$(LIB_SONAME) \
58 59 60
  $(shell pkg-config --libs $(PKGS))
DEBUG_FLAGS = -g
RELEASE_FLAGS =
61

62
KEEP_SYMBOLS ?= 0
63
ifneq ($(KEEP_SYMBOLS),0)
64
RELEASE_FLAGS += -g
65 66
endif

67 68 69 70 71
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS)
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS)

DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
72

73 74 75 76
#
# Files
#

77
PKGCONFIG = $(BUILD_DIR)/$(LIB_NAME).pc
78 79 80 81 82 83 84 85 86 87 88 89 90 91
DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)

#
# Dependencies
#

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

92 93 94 95
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
$(PKGCONFIG): | $(BUILD_DIR)

96 97 98
#
# Rules
#
99

100 101 102 103 104 105 106 107
DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB)
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)

debug: $(DEBUG_LIB)

release: $(RELEASE_LIB)

clean:
108 109
	rm -f *~ $(SRC_DIR)/*~
	rm -fr $(BUILD_DIR) RPMS installroot
110
	rm -fr debian/tmp debian/$(LIB_NAME) debian/$(LIB_NAME)-dev
111 112
	rm -f documentation.list debian/files debian/*.substvars
	rm -f debian/*.debhelper.log debian/*.debhelper
113
	rm -f debian/*.install debian/*~
114 115 116 117 118 119 120 121 122 123

$(BUILD_DIR):
	mkdir -p $@

$(DEBUG_BUILD_DIR):
	mkdir -p $@

$(RELEASE_BUILD_DIR):
	mkdir -p $@

124
$(DEBUG_LIB): $(DEBUG_OBJS)
125
	$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) -o $@
126

127
$(RELEASE_LIB): $(RELEASE_OBJS)
128
	$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) -o $@
129
ifeq ($(KEEP_SYMBOLS),0)
130
	strip $@
131
endif
132 133

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

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

139 140 141 142
#
# LIBDIR usually gets substituted with arch specific dir
# It's relative in deb build and can be whatever in rpm build.
#
143

144 145 146 147 148 149 150 151 152 153
LIBDIR ?= /usr/lib
ABS_LIBDIR := $(shell echo /$(LIBDIR) | sed -r 's|/+|/|g')

pkgconfig: $(PKGCONFIG)

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

debian/%.install: debian/%.install.in
	sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@
154 155 156 157 158 159
#
# Install
#

INSTALL = install
INSTALL_DIRS = $(INSTALL) -d
160
INSTALL_FILES = $(INSTALL) -m 644
161

162 163 164
INSTALL_LIB_DIR = $(DESTDIR)$(ABS_LIBDIR)
INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/$(NAME)
INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ABS_LIBDIR)/pkgconfig
165

166
INSTALL_ALIAS = $(INSTALL_LIB_DIR)/$(LIB_SHORTCUT)
167

168
install: $(INSTALL_LIB_DIR)
169
	$(INSTALL) -m 755 $(RELEASE_LIB) $(INSTALL_LIB_DIR)
170
	ln -sf $(LIB) $(INSTALL_ALIAS)
171 172 173 174 175 176 177 178 179 180 181 182 183 184

install-dev: install $(INSTALL_INCLUDE_DIR) $(INSTALL_PKGCONFIG_DIR)
	$(INSTALL_FILES) $(SRC_DIR)/wsputil.h $(INSTALL_INCLUDE_DIR)
	$(INSTALL_FILES) $(SRC_DIR)/wspcodec.h $(INSTALL_INCLUDE_DIR)
	$(INSTALL_FILES) $(PKGCONFIG) $(INSTALL_PKGCONFIG_DIR)

$(INSTALL_LIB_DIR):
	$(INSTALL_DIRS) $@

$(INSTALL_INCLUDE_DIR):
	$(INSTALL_DIRS) $@

$(INSTALL_PKGCONFIG_DIR):
	$(INSTALL_DIRS) $@