]> git.sur5r.net Git - i3/i3status/blob - Makefile
Add testcase for #304
[i3/i3status] / Makefile
1 TOPDIR=$(shell pwd)
2
3 ifndef PREFIX
4   PREFIX=/usr
5 endif
6 ifndef MANPREFIX
7   MANPREFIX=$(PREFIX)
8 endif
9 ifndef SYSCONFDIR
10   ifeq ($(PREFIX),/usr)
11     SYSCONFDIR=/etc
12   else
13     SYSCONFDIR=$(PREFIX)/etc
14   endif
15 endif
16
17 PKG_CONFIG ?= pkg-config
18 CFLAGS+=-Wall -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
19 CFLAGS+=-g
20 CFLAGS+=-std=gnu99
21 CFLAGS+=-pedantic
22 CPPFLAGS+=-DSYSCONFDIR=\"$(SYSCONFDIR)\"
23 CPPFLAGS+=-DVERSION=\"${I3STATUS_VERSION}\"
24 CFLAGS+=-Iinclude
25 LIBS+=-lconfuse
26 LIBS+=-lyajl
27 LIBS+=-lpulse
28 LIBS+=-lm
29 LIBS+=-lpthread
30
31 ifeq ($(wildcard .git),)
32   # not in git repository
33   VERSION := $(shell [ -f $(TOPDIR)/I3STATUS_VERSION ] && cat $(TOPDIR)/I3STATUS_VERSION | cut -d '-' -f 1)
34   I3STATUS_VERSION := '$(shell [ -f $(TOPDIR)/I3STATUS_VERSION ] && cat $(TOPDIR)/I3STATUS_VERSION)'
35 else
36   VERSION:=$(shell git describe --tags --abbrev=0)
37   I3STATUS_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1))"
38 endif
39 OS:=$(shell uname)
40
41 ifeq ($(OS),Linux)
42 CPPFLAGS+=-DLINUX
43 CPPFLAGS+=-D_GNU_SOURCE
44 CFLAGS += $(shell $(PKG_CONFIG) --cflags libnl-genl-3.0)
45 LIBS += $(shell $(PKG_CONFIG) --libs libnl-genl-3.0)
46 LIBS+=-lasound
47 endif
48
49 ifeq ($(OS),GNU/kFreeBSD)
50 LIBS+=-lbsd
51 endif
52
53 ifneq (, $(filter $(OS), DragonFly FreeBSD OpenBSD))
54 CFLAGS+=-I/usr/local/include/
55 LDFLAGS+=-L/usr/local/lib/
56 endif
57
58 ifeq ($(OS),NetBSD)
59 LIBS+=-lprop
60 endif
61
62 # This probably applies for any pkgsrc based system
63 ifneq (, $(filter $(OS), NetBSD DragonFly))
64 CFLAGS+=-I/usr/pkg/include/
65 LDFLAGS+=-L/usr/pkg/lib/
66 endif
67
68 V ?= 0
69 ifeq ($(V),0)
70 # Don’t print command lines which are run
71 .SILENT:
72 endif
73
74 CFLAGS+=$(EXTRA_CFLAGS)
75
76 # Fallback for libyajl 1 which did not include yajl_version.h. We need
77 # YAJL_MAJOR from that file to decide which code path should be used.
78 CFLAGS += -idirafter yajl-fallback
79
80 OBJS:=$(sort $(wildcard src/*.c *.c))
81 OBJS:=$(OBJS:.c=.o)
82
83 ifeq ($(OS),OpenBSD)
84 OBJS:=$(filter-out src/pulse.o, $(OBJS))
85 LIBS:=$(filter-out -lpulse, $(LIBS))
86 endif
87
88 ifeq ($(OS),DragonFly)
89 OBJS:=$(filter-out src/pulse.o, $(OBJS))
90 LIBS:=$(filter-out -lpulse, $(LIBS)) -lpthread
91 endif
92
93 src/%.o: src/%.c include/i3status.h
94         $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
95         @echo " CC $<"
96
97 %.o: %.c include/%.h
98         $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
99         @echo " CC $<"
100
101 all: i3status manpage
102
103 i3status: ${OBJS}
104         $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
105         @echo " LD $@"
106
107 test: i3status
108         LC_ALL=C ./travis/run-tests.pl
109
110 clean:
111         rm -f *.o src/*.o
112
113 distclean: clean
114         rm -f i3status man/i3status.1
115
116 manpage:
117         $(MAKE) -C man
118
119 install:
120         install -m 755 -d $(DESTDIR)$(PREFIX)/bin
121         install -m 755 -d $(DESTDIR)$(SYSCONFDIR)
122         install -m 755 -d $(DESTDIR)$(MANPREFIX)/share/man/man1
123         install -m 755 i3status $(DESTDIR)$(PREFIX)/bin/i3status
124         install -m 644 i3status.conf $(DESTDIR)$(SYSCONFDIR)/i3status.conf
125         install -m 644 man/i3status.1 $(DESTDIR)$(MANPREFIX)/share/man/man1
126
127 release:
128         [ -f i3status-${VERSION} ] || rm -rf i3status-${VERSION}
129         mkdir i3status-${VERSION}
130         find . -maxdepth 1 -type f \( -regex ".*\.\(c\|conf\|h\)" -or -name "README.md" -or -name "Makefile" -or -name "LICENSE" -or -name "CHANGELOG" \) -exec cp '{}' i3status-${VERSION} \;
131         mkdir i3status-${VERSION}/src
132         mkdir i3status-${VERSION}/man
133         find src -maxdepth 1 -type f \( -regex ".*\.\(c\|h\)" \) -exec cp '{}' i3status-${VERSION}/src \;
134         find man -maxdepth 1 -type f \( -regex ".*\.\(1\|man\|conf\)" -or -name "Makefile" \) -exec cp '{}' i3status-${VERSION}/man \;
135         cp -r include i3status-${VERSION}
136         cp -r yajl-fallback i3status-${VERSION}
137         cp -r contrib i3status-${VERSION}
138         echo ${I3STATUS_VERSION} > i3status-${VERSION}/I3STATUS_VERSION
139         tar cjf i3status-${VERSION}.tar.bz2 i3status-${VERSION}
140         rm -rf i3status-${VERSION}