1 VERSION = $(shell grep -m1 VERSION $(SRC) | cut -f 2 -d'"')
4 MANPREFIX ?= $(PREFIX)/share/man
5 DESKTOPPREFIX ?= $(PREFIX)/share/applications
6 DESKTOPICONPREFIX ?= $(PREFIX)/share/icons/hicolor
8 PKG_CONFIG ?= pkg-config
12 CFLAGS_OPTIMIZATION ?= -O3
14 O_DEBUG := 0 # debug binary
15 O_NORL := 0 # no readline support
16 O_PCRE := 0 # link with PCRE library
17 O_NOLC := 0 # no locale support
18 O_NOMOUSE := 0 # no mouse support
19 O_NOBATCH := 0 # no built-in batch renamer
20 O_NOFIFO := 0 # no FIFO previewer support
21 O_CTX8 := 0 # enable 8 contexts
22 O_ICONS := 0 # support icons-in-terminal
23 O_NERD := 0 # support icons-nerdfont
24 O_EMOJI := 0 # support emoji
25 O_QSORT := 0 # use Alexey Tourbin's QSORT implementation
26 O_BENCH := 0 # benchmark mode (stops at first user input)
27 O_NOSSN := 0 # disable session support
28 O_NOUG := 0 # disable user, group name in status bar
29 O_NOX11 := 0 # disable X11 integration
30 O_MATCHFLTR := 0 # allow filters without matches
31 O_NOSORT := 0 # disable sorting entries on dir load
34 O_COLEMAK := 0 # change key bindings to colemak compatible layout
35 O_COLEMAK-DH := 0 # change key bindings to colemak-dh compatible layout
36 O_GITSTATUS := 0 # add git status to detail view
37 O_NAMEFIRST := 0 # print file name first, add uid and guid to detail view
38 O_RESTOREPREVIEW := 0 # add preview pipe to close and restore preview pane
40 # convert targets to flags for backwards compatibility
41 ifneq ($(filter debug,$(MAKECMDGOALS)),)
44 ifneq ($(filter norl,$(MAKECMDGOALS)),)
47 ifneq ($(filter nolc,$(MAKECMDGOALS)),)
52 ifeq ($(strip $(O_DEBUG)),1)
57 ifeq ($(strip $(O_NORL)),1)
59 else ifeq ($(strip $(O_STATIC)),1)
65 ifeq ($(strip $(O_PCRE)),1)
70 ifeq ($(strip $(O_NOLC)),1)
71 ifeq ($(strip $(O_ICONS)),1)
72 $(info *** Ignoring O_NOLC since O_ICONS is set ***)
73 else ifeq ($(strip $(O_NERD)),1)
74 $(info *** Ignoring O_NOLC since O_NERD is set ***)
75 else ifeq ($(strip $(O_EMOJI)),1)
76 $(info *** Ignoring O_NOLC since O_EMOJI is set ***)
82 ifeq ($(strip $(O_NOMOUSE)),1)
86 ifeq ($(strip $(O_NOBATCH)),1)
90 ifeq ($(strip $(O_NOFIFO)),1)
94 ifeq ($(strip $(O_CTX8)),1)
98 ifeq ($(strip $(O_ICONS)),1)
99 ICONS_INCLUDE = icons-generated-icons-in-term.h
100 CPPFLAGS += -DICONS_IN_TERM -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
103 ifeq ($(strip $(O_NERD)),1)
104 ICONS_INCLUDE = icons-generated-nerd.h
105 CPPFLAGS += -DNERD -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
108 ifeq ($(strip $(O_EMOJI)),1)
109 ICONS_INCLUDE = icons-generated-emoji.h
110 CPPFLAGS += -DEMOJI -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
113 ifeq ($(strip $(O_QSORT)),1)
114 CPPFLAGS += -DTOURBIN_QSORT
117 ifeq ($(strip $(O_BENCH)),1)
121 ifeq ($(strip $(O_NOSSN)),1)
125 ifeq ($(strip $(O_NOUG)),1)
129 ifeq ($(strip $(O_NOX11)),1)
133 ifeq ($(strip $(O_MATCHFLTR)),1)
134 CPPFLAGS += -DMATCHFLTR
137 ifeq ($(strip $(O_NOSORT)),1)
141 ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
142 CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw)
143 LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncursesw)
144 else ifeq ($(shell $(PKG_CONFIG) ncurses && echo 1),1)
145 CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncurses)
146 LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncurses)
148 LDLIBS_CURSES ?= -lncurses
151 CFLAGS += -std=c11 -Wall -Wextra -Wshadow
152 CFLAGS += $(CFLAGS_OPTIMIZATION)
153 CFLAGS += $(CFLAGS_CURSES)
155 LDLIBS += $(LDLIBS_CURSES) -lpthread
157 # static compilation needs libgpm development package
158 ifeq ($(strip $(O_STATIC)),1)
163 DISTFILES = src nnn.1 Makefile README.md LICENSE
167 DESKTOPFILE = misc/desktop/nnn.desktop
168 LOGOSVG = misc/logo/logo.svg
169 LOGO64X64 = misc/logo/logo-64x64.png
171 COLEMAK = patches/colemak
172 COLEMAK-DH = patches/colemak-dh
173 GITSTATUS = patches/gitstatus
174 NAMEFIRST = patches/namefirst
175 RESTOREPREVIEW = patches/restorepreview
177 # test if we are on Mac OS X and get X.Y.Z OS version with system binary /usr/bin/sw_vers
178 MACOS_VERSION := $(strip $(shell command -v sw_vers >/dev/null && [ "`sw_vers -productName`" = "Mac OS X" ] && sw_vers -productVersion))
179 # if Mac OS X detected, test if its version is below 10.12.0 relying on "sort -c" returning "disorder" message if the input is not sorted
180 ifneq ($(MACOS_VERSION),)
181 MACOS_BELOW_1012 := $(if $(strip $(shell printf '10.12.0\n%s' "$(MACOS_VERSION)" | sort -ct. -k1,1n -k2,2n -k3,3n 2>&1)),1)
183 # if Mac OS X version is below 10.12.0, compile in the replacement clock_gettime and define MACOS_BELOW_1012 so that it's included in nnn.c
184 ifneq ($(MACOS_BELOW_1012),)
185 GETTIME_C = misc/macos-legacy/mach_gettime.c
186 GETTIME_H = misc/macos-legacy/mach_gettime.h
188 HEADERS += $(GETTIME_H)
189 CPPFLAGS += -DMACOS_BELOW_1012
192 ifeq ($(strip $(O_DEBUG)),1)
195 ifeq ($(strip $(O_QSORT)),1)
196 HEADERS += src/qsort.h
198 ifeq ($(strip $(O_EMOJI)),1)
199 HEADERS += src/icons.h src/$(ICONS_INCLUDE)
201 ifeq ($(strip $(O_NERD)),1)
202 HEADERS += src/icons.h src/$(ICONS_INCLUDE)
204 ifeq ($(strip $(O_ICONS)),1)
205 HEADERS += src/icons.h src/$(ICONS_INCLUDE) src/icons-in-terminal.h
210 $(BIN): $(SRC) $(HEADERS) Makefile
211 @$(MAKE) --silent prepatch
212 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(GETTIME_C) $< $(LDLIBS)
213 @$(MAKE) --silent postpatch
215 # targets for backwards compatibility
220 src/$(ICONS_INCLUDE): src/icons-hash.c src/icons.h src/icons-in-terminal.h
221 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DICONS_GENERATE -o src/icons-hash-gen src/icons-hash.c
222 ./src/icons-hash-gen > $@
224 install-desktop: $(DESKTOPFILE)
225 $(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPPREFIX)
226 $(INSTALL) -m 0644 $(DESKTOPFILE) $(DESTDIR)$(DESKTOPPREFIX)
227 $(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps
228 $(INSTALL) -m 0644 $(LOGOSVG) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg
229 $(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps
230 $(INSTALL) -m 0644 $(LOGO64X64) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png
233 $(RM) $(DESTDIR)$(DESKTOPPREFIX)/$(DESKTOPFILE)
234 $(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg
235 $(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png
238 $(INSTALL) -m 0755 -d $(DESTDIR)$(PREFIX)/bin
239 $(INSTALL) -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin
240 $(INSTALL) -m 0755 -d $(DESTDIR)$(MANPREFIX)/man1
241 $(INSTALL) -m 0644 $(BIN).1 $(DESTDIR)$(MANPREFIX)/man1
244 $(RM) $(DESTDIR)$(PREFIX)/bin/$(BIN)
245 $(RM) $(DESTDIR)$(MANPREFIX)/man1/$(BIN).1
255 # regular static binary
256 make O_STATIC=1 strip
257 mv $(BIN) $(BIN)-static
258 # static binary with icons-in-terminal support
259 make O_STATIC=1 O_ICONS=1 strip
260 mv $(BIN) $(BIN)-icons-static
261 # static binary with patched nerd font support
262 make O_STATIC=1 O_NERD=1 strip
263 mv $(BIN) $(BIN)-nerd-static
264 # static binary with emoji support
265 make O_STATIC=1 O_EMOJI=1 strip
266 mv $(BIN) $(BIN)-emoji-static
269 cp misc/musl/musl-static-ubuntu.sh .
270 ./musl-static-ubuntu.sh 1
271 rm ./musl-static-ubuntu.sh
274 find ./plugins/ -type f -not -name "*.md" -exec shellcheck {} +
277 mkdir -p nnn-$(VERSION)
278 $(CP) -r $(DISTFILES) nnn-$(VERSION)
279 tar -cf - nnn-$(VERSION) | gzip > nnn-$(VERSION).tar.gz
280 $(RM) -r nnn-$(VERSION)
283 git archive -o nnn-$(VERSION).tar.gz --format tar.gz --prefix=nnn-$(VERSION)/ v$(VERSION)
284 gpg --detach-sign --yes nnn-$(VERSION).tar.gz
285 rm -f nnn-$(VERSION).tar.gz
287 upload-local: sign static musl
288 $(eval ID=$(shell curl -s 'https://api.github.com/repos/jarun/nnn/releases/tags/v$(VERSION)' | jq .id))
290 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=nnn-$(VERSION).tar.gz.sig' \
291 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/pgp-signature' \
292 --upload-file nnn-$(VERSION).tar.gz.sig
293 # upx compress all static binaries
294 upx -qqq $(BIN)-static
295 upx -qqq $(BIN)-icons-static
296 upx -qqq $(BIN)-nerd-static
297 upx -qqq $(BIN)-emoji-static
298 # upload static binary
299 tar -zcf $(BIN)-static-$(VERSION).x86_64.tar.gz $(BIN)-static
300 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-static-$(VERSION).x86_64.tar.gz' \
301 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
302 --upload-file $(BIN)-static-$(VERSION).x86_64.tar.gz
303 # upload icons-in-terminal compiled static binary
304 tar -zcf $(BIN)-icons-static-$(VERSION).x86_64.tar.gz $(BIN)-icons-static
305 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-icons-static-$(VERSION).x86_64.tar.gz' \
306 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
307 --upload-file $(BIN)-icons-static-$(VERSION).x86_64.tar.gz
308 # upload patched nerd font compiled static binary
309 tar -zcf $(BIN)-nerd-static-$(VERSION).x86_64.tar.gz $(BIN)-nerd-static
310 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-nerd-static-$(VERSION).x86_64.tar.gz' \
311 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
312 --upload-file $(BIN)-nerd-static-$(VERSION).x86_64.tar.gz
313 # upload emoji compiled static binary
314 tar -zcf $(BIN)-emoji-static-$(VERSION).x86_64.tar.gz $(BIN)-emoji-static
315 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-emoji-static-$(VERSION).x86_64.tar.gz' \
316 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
317 --upload-file $(BIN)-emoji-static-$(VERSION).x86_64.tar.gz
318 # upload musl static binary
319 tar -zcf $(BIN)-musl-static-$(VERSION).x86_64.tar.gz $(BIN)-musl-static
320 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-musl-static-$(VERSION).x86_64.tar.gz' \
321 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
322 --upload-file $(BIN)-musl-static-$(VERSION).x86_64.tar.gz
325 $(RM) -f $(BIN) nnn-$(VERSION).tar.gz *.sig $(BIN)-static $(BIN)-static-$(VERSION).x86_64.tar.gz $(BIN)-icons-static $(BIN)-icons-static-$(VERSION).x86_64.tar.gz $(BIN)-nerd-static $(BIN)-nerd-static-$(VERSION).x86_64.tar.gz $(BIN)-emoji-static $(BIN)-emoji-static-$(VERSION).x86_64.tar.gz $(BIN)-musl-static $(BIN)-musl-static-$(VERSION).x86_64.tar.gz src/icons-hash-gen src/icons-generated-*.h
328 ./patches/check-patches.sh
331 ifeq ($(strip $(O_NAMEFIRST)),1)
332 patch --forward $(PATCH_OPTS) --strip=1 --input=$(NAMEFIRST)/mainline.diff
333 ifeq ($(strip $(O_GITSTATUS)),1)
334 patch --forward $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/namefirst.diff
336 else ifeq ($(strip $(O_GITSTATUS)),1)
337 patch --forward $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/mainline.diff
339 ifeq ($(strip $(O_RESTOREPREVIEW)),1)
340 patch --forward $(PATCH_OPTS) --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff
342 ifeq ($(strip $(O_COLEMAK)),1)
343 patch --forward $(PATCH_OPTS) --strip=1 --input=$(COLEMAK)/mainline.diff
345 ifeq ($(strip $(O_COLEMAK-DH)),1)
346 patch --forward $(PATCH_OPTS) --strip=1 --input=$(COLEMAK-DH)/mainline.diff
350 ifeq ($(strip $(O_NAMEFIRST)),1)
351 ifeq ($(strip $(O_GITSTATUS)),1)
352 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/namefirst.diff
354 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(NAMEFIRST)/mainline.diff
355 else ifeq ($(strip $(O_GITSTATUS)),1)
356 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/mainline.diff
358 ifeq ($(strip $(O_RESTOREPREVIEW)),1)
359 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff
361 ifeq ($(strip $(O_COLEMAK)),1)
362 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(COLEMAK)/mainline.diff
364 ifeq ($(strip $(O_COLEMAK-DH)),1)
365 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(COLEMAK-DH)/mainline.diff
370 .PHONY: all install uninstall strip static dist sign upload-local clean install-desktop uninstall-desktop