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_GITSTATUS := 0 # add git status to detail view
36 O_NAMEFIRST := 0 # print file name first, add uid and guid to detail view
37 O_RESTOREPREVIEW := 0 # add preview pipe to close and restore preview pane
39 # convert targets to flags for backwards compatibility
40 ifneq ($(filter debug,$(MAKECMDGOALS)),)
43 ifneq ($(filter norl,$(MAKECMDGOALS)),)
46 ifneq ($(filter nolc,$(MAKECMDGOALS)),)
51 ifeq ($(strip $(O_DEBUG)),1)
56 ifeq ($(strip $(O_NORL)),1)
58 else ifeq ($(strip $(O_STATIC)),1)
64 ifeq ($(strip $(O_PCRE)),1)
69 ifeq ($(strip $(O_NOLC)),1)
70 ifeq ($(strip $(O_ICONS)),1)
71 $(info *** Ignoring O_NOLC since O_ICONS is set ***)
72 else ifeq ($(strip $(O_NERD)),1)
73 $(info *** Ignoring O_NOLC since O_NERD is set ***)
74 else ifeq ($(strip $(O_EMOJI)),1)
75 $(info *** Ignoring O_NOLC since O_EMOJI is set ***)
81 ifeq ($(strip $(O_NOMOUSE)),1)
85 ifeq ($(strip $(O_NOBATCH)),1)
89 ifeq ($(strip $(O_NOFIFO)),1)
93 ifeq ($(strip $(O_CTX8)),1)
97 ifeq ($(strip $(O_ICONS)),1)
98 ICONS_INCLUDE = icons-generated-icons-in-term.h
99 CPPFLAGS += -DICONS_IN_TERM -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
102 ifeq ($(strip $(O_NERD)),1)
103 ICONS_INCLUDE = icons-generated-nerd.h
104 CPPFLAGS += -DNERD -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
107 ifeq ($(strip $(O_EMOJI)),1)
108 ICONS_INCLUDE = icons-generated-emoji.h
109 CPPFLAGS += -DEMOJI -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
112 ifeq ($(strip $(O_QSORT)),1)
113 CPPFLAGS += -DTOURBIN_QSORT
116 ifeq ($(strip $(O_BENCH)),1)
120 ifeq ($(strip $(O_NOSSN)),1)
124 ifeq ($(strip $(O_NOUG)),1)
128 ifeq ($(strip $(O_NOX11)),1)
132 ifeq ($(strip $(O_MATCHFLTR)),1)
133 CPPFLAGS += -DMATCHFLTR
136 ifeq ($(strip $(O_NOSORT)),1)
140 ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
141 CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw)
142 LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncursesw)
143 else ifeq ($(shell $(PKG_CONFIG) ncurses && echo 1),1)
144 CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncurses)
145 LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncurses)
147 LDLIBS_CURSES ?= -lncurses
150 CFLAGS += -std=c11 -Wall -Wextra -Wshadow
151 CFLAGS += $(CFLAGS_OPTIMIZATION)
152 CFLAGS += $(CFLAGS_CURSES)
154 LDLIBS += $(LDLIBS_CURSES) -lpthread
156 # static compilation needs libgpm development package
157 ifeq ($(strip $(O_STATIC)),1)
162 DISTFILES = src nnn.1 Makefile README.md LICENSE
166 DESKTOPFILE = misc/desktop/nnn.desktop
167 LOGOSVG = misc/logo/logo.svg
168 LOGO64X64 = misc/logo/logo-64x64.png
170 COLEMAK = patches/colemak
171 GITSTATUS = patches/gitstatus
172 NAMEFIRST = patches/namefirst
173 RESTOREPREVIEW = patches/restorepreview
175 # test if we are on Mac OS X and get X.Y.Z OS version with system binary /usr/bin/sw_vers
176 MACOS_VERSION := $(strip $(shell command -v sw_vers >/dev/null && [ "`sw_vers -productName`" = "Mac OS X" ] && sw_vers -productVersion))
177 # 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
178 ifneq ($(MACOS_VERSION),)
179 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)
181 # 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
182 ifneq ($(MACOS_BELOW_1012),)
183 GETTIME_C = misc/macos-legacy/mach_gettime.c
184 GETTIME_H = misc/macos-legacy/mach_gettime.h
186 HEADERS += $(GETTIME_H)
187 CPPFLAGS += -DMACOS_BELOW_1012
190 ifeq ($(strip $(O_DEBUG)),1)
193 ifeq ($(strip $(O_QSORT)),1)
194 HEADERS += src/qsort.h
196 ifeq ($(strip $(O_EMOJI)),1)
197 HEADERS += src/icons.h src/$(ICONS_INCLUDE)
199 ifeq ($(strip $(O_NERD)),1)
200 HEADERS += src/icons.h src/$(ICONS_INCLUDE)
202 ifeq ($(strip $(O_ICONS)),1)
203 HEADERS += src/icons.h src/$(ICONS_INCLUDE) src/icons-in-terminal.h
208 $(BIN): $(SRC) $(HEADERS) Makefile
209 @$(MAKE) --silent prepatch
210 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(GETTIME_C) $< $(LDLIBS)
211 @$(MAKE) --silent postpatch
213 # targets for backwards compatibility
218 src/$(ICONS_INCLUDE): src/icons-hash.c src/icons.h src/icons-in-terminal.h
219 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DICONS_GENERATE -o src/icons-hash-gen src/icons-hash.c
220 ./src/icons-hash-gen > $@
222 install-desktop: $(DESKTOPFILE)
223 $(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPPREFIX)
224 $(INSTALL) -m 0644 $(DESKTOPFILE) $(DESTDIR)$(DESKTOPPREFIX)
225 $(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps
226 $(INSTALL) -m 0644 $(LOGOSVG) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg
227 $(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps
228 $(INSTALL) -m 0644 $(LOGO64X64) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png
231 $(RM) $(DESTDIR)$(DESKTOPPREFIX)/$(DESKTOPFILE)
232 $(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg
233 $(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png
236 $(INSTALL) -m 0755 -d $(DESTDIR)$(PREFIX)/bin
237 $(INSTALL) -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin
238 $(INSTALL) -m 0755 -d $(DESTDIR)$(MANPREFIX)/man1
239 $(INSTALL) -m 0644 $(BIN).1 $(DESTDIR)$(MANPREFIX)/man1
242 $(RM) $(DESTDIR)$(PREFIX)/bin/$(BIN)
243 $(RM) $(DESTDIR)$(MANPREFIX)/man1/$(BIN).1
253 # regular static binary
254 make O_STATIC=1 strip
255 mv $(BIN) $(BIN)-static
256 # static binary with icons-in-terminal support
257 make O_STATIC=1 O_ICONS=1 strip
258 mv $(BIN) $(BIN)-icons-static
259 # static binary with patched nerd font support
260 make O_STATIC=1 O_NERD=1 strip
261 mv $(BIN) $(BIN)-nerd-static
262 # static binary with emoji support
263 make O_STATIC=1 O_EMOJI=1 strip
264 mv $(BIN) $(BIN)-emoji-static
267 cp misc/musl/musl-static-ubuntu.sh .
268 ./musl-static-ubuntu.sh 1
269 rm ./musl-static-ubuntu.sh
272 find ./plugins/ -type f -not -name "*.md" -exec shellcheck {} +
275 mkdir -p nnn-$(VERSION)
276 $(CP) -r $(DISTFILES) nnn-$(VERSION)
277 tar -cf - nnn-$(VERSION) | gzip > nnn-$(VERSION).tar.gz
278 $(RM) -r nnn-$(VERSION)
281 git archive -o nnn-$(VERSION).tar.gz --format tar.gz --prefix=nnn-$(VERSION)/ v$(VERSION)
282 gpg --detach-sign --yes nnn-$(VERSION).tar.gz
283 rm -f nnn-$(VERSION).tar.gz
285 upload-local: sign static musl
286 $(eval ID=$(shell curl -s 'https://api.github.com/repos/jarun/nnn/releases/tags/v$(VERSION)' | jq .id))
288 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=nnn-$(VERSION).tar.gz.sig' \
289 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/pgp-signature' \
290 --upload-file nnn-$(VERSION).tar.gz.sig
291 # upx compress all static binaries
292 upx -qqq $(BIN)-static
293 upx -qqq $(BIN)-icons-static
294 upx -qqq $(BIN)-nerd-static
295 upx -qqq $(BIN)-emoji-static
296 # upload static binary
297 tar -zcf $(BIN)-static-$(VERSION).x86_64.tar.gz $(BIN)-static
298 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-static-$(VERSION).x86_64.tar.gz' \
299 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
300 --upload-file $(BIN)-static-$(VERSION).x86_64.tar.gz
301 # upload icons-in-terminal compiled static binary
302 tar -zcf $(BIN)-icons-static-$(VERSION).x86_64.tar.gz $(BIN)-icons-static
303 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-icons-static-$(VERSION).x86_64.tar.gz' \
304 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
305 --upload-file $(BIN)-icons-static-$(VERSION).x86_64.tar.gz
306 # upload patched nerd font compiled static binary
307 tar -zcf $(BIN)-nerd-static-$(VERSION).x86_64.tar.gz $(BIN)-nerd-static
308 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-nerd-static-$(VERSION).x86_64.tar.gz' \
309 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
310 --upload-file $(BIN)-nerd-static-$(VERSION).x86_64.tar.gz
311 # upload emoji compiled static binary
312 tar -zcf $(BIN)-emoji-static-$(VERSION).x86_64.tar.gz $(BIN)-emoji-static
313 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-emoji-static-$(VERSION).x86_64.tar.gz' \
314 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
315 --upload-file $(BIN)-emoji-static-$(VERSION).x86_64.tar.gz
316 # upload musl static binary
317 tar -zcf $(BIN)-musl-static-$(VERSION).x86_64.tar.gz $(BIN)-musl-static
318 curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-musl-static-$(VERSION).x86_64.tar.gz' \
319 -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
320 --upload-file $(BIN)-musl-static-$(VERSION).x86_64.tar.gz
323 $(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
326 ./patches/check-patches.sh
329 ifeq ($(strip $(O_NAMEFIRST)),1)
330 patch --forward $(PATCH_OPTS) --strip=1 --input=$(NAMEFIRST)/mainline.diff
331 ifeq ($(strip $(O_GITSTATUS)),1)
332 patch --forward $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/namefirst.diff
334 else ifeq ($(strip $(O_GITSTATUS)),1)
335 patch --forward $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/mainline.diff
337 ifeq ($(strip $(O_RESTOREPREVIEW)),1)
338 patch --forward $(PATCH_OPTS) --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff
340 ifeq ($(strip $(O_COLEMAK)),1)
341 patch --forward $(PATCH_OPTS) --strip=1 --input=$(COLEMAK)/mainline.diff
345 ifeq ($(strip $(O_NAMEFIRST)),1)
346 ifeq ($(strip $(O_GITSTATUS)),1)
347 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/namefirst.diff
349 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(NAMEFIRST)/mainline.diff
350 else ifeq ($(strip $(O_GITSTATUS)),1)
351 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/mainline.diff
353 ifeq ($(strip $(O_RESTOREPREVIEW)),1)
354 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff
356 ifeq ($(strip $(O_COLEMAK)),1)
357 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(COLEMAK)/mainline.diff
362 .PHONY: all install uninstall strip static dist sign upload-local clean install-desktop uninstall-desktop