forked from ravachol/kew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
154 lines (124 loc) · 4.87 KB
/
Makefile
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
154
CC ?= gcc
CXX ?= g++
PKG_CONFIG ?= pkg-config
# To disable libnotify, run:
# make USE_LIBNOTIFY=0
# To disable faad2, run:
# make USE_FAAD=0
# Detect system and architecture
UNAME_S := $(shell uname -s)
ARCH := $(shell uname -m)
# Default USE_LIBNOTIFY to auto-detect if not set by user
ifeq ($(origin USE_LIBNOTIFY), undefined)
ifeq ($(UNAME_S), Darwin)
USE_LIBNOTIFY = 0
else ifneq ($(shell $(PKG_CONFIG) --exists libnotify && echo yes), yes)
USE_LIBNOTIFY = 0
else
USE_LIBNOTIFY = 1
endif
endif
# Adjust the PREFIX for macOS and Linux
ifeq ($(UNAME_S), Darwin)
ifeq ($(ARCH), arm64)
PREFIX ?= /usr/local
PKG_CONFIG_PATH := /opt/homebrew/lib/pkgconfig:/opt/homebrew/share/pkgconfig:$(PKG_CONFIG_PATH)
else
PREFIX ?= /usr/local
PKG_CONFIG_PATH := /usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:$(PKG_CONFIG_PATH)
endif
else
PREFIX ?= /usr
PKG_CONFIG_PATH := /usr/lib/pkgconfig:/usr/share/pkgconfig:$(PKG_CONFIG_PATH)
endif
# Default USE_FAAD to auto-detect if not set by user
ifeq ($(origin USE_FAAD), undefined)
USE_FAAD = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --exists faad && echo 1 || echo 0)
ifeq ($(USE_FAAD), 0)
# If pkg-config fails, try to find libfaad dynamically in common paths
USE_FAAD = $(shell [ -f /usr/lib/libfaad.so ] || [ -f /usr/local/lib/libfaad.so ] || \
[ -f /opt/local/lib/libfaad.so ] || [ -f /opt/homebrew/lib/libfaad.dylib ] || \
[ -f /opt/homebrew/opt/faad2/lib/libfaad.dylib ] || \
[ -f /usr/local/lib/libfaad.dylib ] || [ -f /lib/x86_64-linux-gnu/libfaad.so.2 ] && echo 1 || echo 0)
endif
endif
# Compiler flags
CFLAGS = -I/usr/include -I/opt/homebrew/include -I/usr/local/include -I/usr/lib -Iinclude/minimp4 \
-I/usr/include/chafa -I/usr/lib/chafa/include -I/usr/include/ogg -I/usr/include/opus \
-I/usr/include/stb -Iinclude/imgtotxt/ext -Iinclude/imgtotxt -I/usr/include/glib-2.0 \
-I/usr/lib/glib-2.0/include -Iinclude/miniaudio -I/usr/include/gdk-pixbuf-2.0 -O2
CFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags gio-2.0 chafa fftw3f opus opusfile vorbis ogg glib-2.0 taglib)
CFLAGS += -fstack-protector-strong -Wformat -Werror=format-security -fPIE -D_FORTIFY_SOURCE=2
CFLAGS += -Wall -Wextra -Wpointer-arith -flto
# Compiler flags for C++ code (inherits from CFLAGS)
CXXFLAGS = $(CFLAGS) -std=c++11
# Libraries
LIBS = -L/usr/lib -lm -lopusfile -lglib-2.0 -lpthread $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs gio-2.0 chafa fftw3f opus opusfile ogg vorbis vorbisfile glib-2.0 taglib)
LIBS += -lstdc++
LDFLAGS = -logg -lz -flto
ifeq ($(UNAME_S), Linux)
CFLAGS += -fPIE
CXXFLAGS += -fPIE
LDFLAGS += -pie -Wl,-z,relro -s
endif
# Conditionally add libnotify if USE_LIBNOTIFY is enabled
ifeq ($(USE_LIBNOTIFY), 1)
CFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnotify)
LIBS += -lnotify
DEFINES += -DUSE_LIBNOTIFY
endif
# Conditionally add faad2 support if USE_FAAD is enabled
ifeq ($(USE_FAAD), 1)
ifeq ($(ARCH), arm64)
CFLAGS += -I/opt/homebrew/opt/faad2/include
LIBS += -L/opt/homebrew/opt/faad2/lib -lfaad
else
CFLAGS += -I/usr/local/include
LIBS += -L/usr/local/lib -lfaad
endif
DEFINES += -DUSE_FAAD
endif
ifeq ($(origin CC),default)
CC := gcc
endif
ifneq ($(findstring gcc,$(CC)),)
ifeq ($(UNAME_S), Linux)
LIBS += -latomic
endif
endif
OBJDIR = src/obj
SRCS = src/common_ui.c src/sound.c src/directorytree.c src/soundcommon.c src/m4a.c src/search_ui.c src/playlist_ui.c src/player.c \
src/soundbuiltin.c src/mpris.c src/playerops.c src/utils.c src/file.c src/chafafunc.c src/cache.c src/songloader.c \
src/playlist.c src/term.c src/settings.c src/visuals.c src/kew.c
OBJS = $(SRCS:src/%.c=$(OBJDIR)/%.o)
# Add the C++ wrapper to the list of object files
WRAPPER_SRC = src/tagLibWrapper.cpp
WRAPPER_OBJ = $(OBJDIR)/tagLibWrapper.o
MAN_PAGE = kew.1
MAN_DIR ?= $(PREFIX)/share/man
all: kew
$(OBJDIR)/%.o: src/%.c Makefile | $(OBJDIR)
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
# Compile the C++ wrapper with g++
$(WRAPPER_OBJ): $(WRAPPER_SRC) Makefile | $(OBJDIR)
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(OBJDIR)/write_ascii.o: include/imgtotxt/write_ascii.c Makefile | $(OBJDIR)
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
$(OBJDIR):
mkdir -p $(OBJDIR)
# Link all objects together
kew: $(OBJDIR)/write_ascii.o $(OBJS) $(WRAPPER_OBJ) Makefile
$(CC) -o kew $(OBJDIR)/write_ascii.o $(OBJS) $(WRAPPER_OBJ) $(LIBS) $(LDFLAGS)
.PHONY: install
install: all
mkdir -p $(DESTDIR)$(MAN_DIR)/man1
mkdir -p $(DESTDIR)$(PREFIX)/bin
install -m 0755 kew $(DESTDIR)$(PREFIX)/bin/kew
install -m 0644 docs/kew.1 $(DESTDIR)$(MAN_DIR)/man1/kew.1
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/kew
rm -f $(DESTDIR)$(MAN_DIR)/man1/kew.1
.PHONY: clean
clean:
rm -rf $(OBJDIR) kew