File: Makefile

package info (click to toggle)
xininfo 0.14.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 80 kB
  • ctags: 59
  • sloc: ansic: 324; makefile: 87
file content (116 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download
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
QUIET?=@
CFLAGS?=-Wall -Wextra -O3 -g
VERSION?=0.14.11

PROGRAM=xininfo

MANPAGE_SOURCE=$(PROGRAM).markdown
MANPAGE=$(PROGRAM).1

PREFIX?=$(DESTDIR)/usr
BIN_DIR?=$(PREFIX)/bin


SOURCE_DIR=source
CONFIG_DIR=config
DOC_DIR=doc
BUILD_DIR=build

SOURCES=$(wildcard $(SOURCE_DIR)/*.c $(CONFIG_DIR)/*.c )
OBJECTS=$(SOURCES:%.c=$(BUILD_DIR)/%.o)
HEADERS=$(wildcard include/*.h)
OTHERS=Makefile LICENSE doc/xininfo.1 doc/xininfo.markdown

INSTALL_PROGRAM=$(BIN_DIR)/$(PROGRAM)
INSTALL_MANPAGE=$(PREFIX)/share/man/man1/$(MANPAGE)


DIST_TARGET=$(BUILD_DIR)/$(PROGRAM)-$(VERSION).tar.xz


CFLAGS+=-std=c99
CFLAGS+=-Iinclude/
CFLAGS+=-DVERSION="\"$(VERSION)\"" -DMANPAGE_PATH="\"$(INSTALL_MANPAGE)\""

LDADD=-lm
# Check deps.
ifeq (${DEBUG},1)
CFLAGS+=-DTIMING=1 -g3
LDADD+=-lrt
endif

CLANG=$(shell which clang)

ifneq (${CLANG},${EMPTY})
    $(info Using clang compiler: ${CLANG})
    CC=${CLANG}
endif


##
# Check dependencies
##
PKG_CONFIG?=$(shell which pkg-config)
ifeq (${PKG_CONFIG},${EMPTY})
$(error Failed to find pkg-config. Please install pkg-config)
endif

CFLAGS+=$(shell ${PKG_CONFIG} --cflags x11 xinerama xrandr )
LDADD+=$(shell ${PKG_CONFIG} --libs x11 xinerama  xrandr )

ifeq (${LDADD},${EMPTY})
$(error Failed to find the required dependencies: x11, xinerama )
endif


all: $(BUILD_DIR)/$(PROGRAM)

$(BUILD_DIR):
	$(info Creating build dir)
	$(QUIET)mkdir -p $@
	$(QUIET)mkdir -p $@/$(SOURCE_DIR)
	$(QUIET)mkdir -p $@/$(CONFIG_DIR)
	$(QUIET)mkdir -p $@/$(DOC_DIR)

# Objects depend on header files and makefile too.
$(BUILD_DIR)/%.o: %.c Makefile $(HEADERS) | $(BUILD_DIR)
	$(info Compiling $< -> $@)
	$(QUIET) $(CC) $(CFLAGS) -c -o $@ $<

$(BUILD_DIR)/$(PROGRAM): $(OBJECTS)
	$(info Linking   $@)
	$(QUIET)$(CC) -o $@ $^  $(LDADD) $(LDFLAGS)

$(BUILD_DIR)/$(DOC_DIR)/$(MANPAGE): $(DOC_DIR)/$(MANPAGE_SOURCE)
	$(info geerate manpage $^-> $@)
	$(QUIET)md2man-roff $^ > $@

$(INSTALL_PROGRAM): $(BUILD_DIR)/$(PROGRAM)
	$(info Install   $^ -> $@ )
	$(QUIET)install -Dm 755 $^ $@

$(INSTALL_MANPAGE): $(BUILD_DIR)/$(DOC_DIR)/$(MANPAGE)
	$(info Install   $^ -> $@ )
	$(QUIET)install -Dm 755 $^ $@

install: $(INSTALL_PROGRAM) $(INSTALL_MANPAGE)

clean:
	$(info Clean build dir)
	$(QUIET)rm -rf $(BUILD_DIR)


indent:
	@astyle --style=linux -S -C -D -N -H -L -W3 -f $(SOURCES) $(HEADERS)

dist: $(DIST_TARGET)

$(BUILD_DIR)/$(PROGRAM)-$(VERSION): $(SOURCES) $(HEADERS) $(OTHERS) | $(BUILD_DIR)
	$(info Create release directory)
	$(QUIET)mkdir -p $@
	$(QUIET)cp -a --parents $^ $@


$(DIST_TARGET): $(BUILD_DIR)/$(PROGRAM)-$(VERSION)
	$(info Creating release tarball: $@)
	$(QUIET) tar -C $(BUILD_DIR) -cavvJf $@ $(PROGRAM)-$(VERSION)