Makefile (12539B)
1 VERSION = $(shell grep -m1 VERSION $(SRC) | cut -f 2 -d'"') 2 3 PREFIX ?= /usr/local 4 MANPREFIX ?= $(PREFIX)/share/man 5 DESKTOPPREFIX ?= $(PREFIX)/share/applications 6 DESKTOPICONPREFIX ?= $(PREFIX)/share/icons/hicolor 7 STRIP ?= strip 8 PKG_CONFIG ?= pkg-config 9 INSTALL ?= install 10 CP ?= cp 11 12 CFLAGS_OPTIMIZATION ?= -O3 13 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 := 1 # 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 32 33 # User patches 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 39 40 # convert targets to flags for backwards compatibility 41 ifneq ($(filter debug,$(MAKECMDGOALS)),) 42 O_DEBUG := 1 43 endif 44 ifneq ($(filter norl,$(MAKECMDGOALS)),) 45 O_NORL := 1 46 endif 47 ifneq ($(filter nolc,$(MAKECMDGOALS)),) 48 O_NORL := 1 49 O_NOLC := 1 50 endif 51 52 ifeq ($(strip $(O_DEBUG)),1) 53 CPPFLAGS += -DDEBUG 54 CFLAGS += -g3 55 endif 56 57 ifeq ($(strip $(O_NORL)),1) 58 CPPFLAGS += -DNORL 59 else ifeq ($(strip $(O_STATIC)),1) 60 CPPFLAGS += -DNORL 61 else 62 LDLIBS += -lreadline 63 endif 64 65 ifeq ($(strip $(O_PCRE)),1) 66 CPPFLAGS += -DPCRE 67 LDLIBS += -lpcre 68 endif 69 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 ***) 77 else 78 CPPFLAGS += -DNOLC 79 endif 80 endif 81 82 ifeq ($(strip $(O_NOMOUSE)),1) 83 CPPFLAGS += -DNOMOUSE 84 endif 85 86 ifeq ($(strip $(O_NOBATCH)),1) 87 CPPFLAGS += -DNOBATCH 88 endif 89 90 ifeq ($(strip $(O_NOFIFO)),1) 91 CPPFLAGS += -DNOFIFO 92 endif 93 94 ifeq ($(strip $(O_CTX8)),1) 95 CPPFLAGS += -DCTX8 96 endif 97 98 ifeq ($(strip $(O_ICONS)),1) 99 ICONS_INCLUDE = icons-generated-icons-in-term.h 100 CPPFLAGS += -DICONS_IN_TERM -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\" 101 endif 102 103 ifeq ($(strip $(O_NERD)),1) 104 ICONS_INCLUDE = icons-generated-nerd.h 105 CPPFLAGS += -DNERD -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\" 106 endif 107 108 ifeq ($(strip $(O_EMOJI)),1) 109 ICONS_INCLUDE = icons-generated-emoji.h 110 CPPFLAGS += -DEMOJI -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\" 111 endif 112 113 ifeq ($(strip $(O_QSORT)),1) 114 CPPFLAGS += -DTOURBIN_QSORT 115 endif 116 117 ifeq ($(strip $(O_BENCH)),1) 118 CPPFLAGS += -DBENCH 119 endif 120 121 ifeq ($(strip $(O_NOSSN)),1) 122 CPPFLAGS += -DNOSSN 123 endif 124 125 ifeq ($(strip $(O_NOUG)),1) 126 CPPFLAGS += -DNOUG 127 endif 128 129 ifeq ($(strip $(O_NOX11)),1) 130 CPPFLAGS += -DNOX11 131 endif 132 133 ifeq ($(strip $(O_MATCHFLTR)),1) 134 CPPFLAGS += -DMATCHFLTR 135 endif 136 137 ifeq ($(strip $(O_NOSORT)),1) 138 CPPFLAGS += -DNOSORT 139 endif 140 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) 147 else 148 LDLIBS_CURSES ?= -lncurses 149 endif 150 151 CFLAGS += -std=c11 -Wall -Wextra -Wshadow 152 CFLAGS += $(CFLAGS_OPTIMIZATION) 153 CFLAGS += $(CFLAGS_CURSES) 154 155 LDLIBS += $(LDLIBS_CURSES) -lpthread 156 157 # static compilation needs libgpm development package 158 ifeq ($(strip $(O_STATIC)),1) 159 LDFLAGS += -static 160 LDLIBS += -lgpm 161 endif 162 163 DISTFILES = src nnn.1 Makefile README.md LICENSE 164 SRC = src/nnn.c 165 HEADERS = src/nnn.h 166 BIN = nnn 167 DESKTOPFILE = misc/desktop/nnn.desktop 168 LOGOSVG = misc/logo/logo.svg 169 LOGO64X64 = misc/logo/logo-64x64.png 170 171 COLEMAK = patches/colemak 172 COLEMAK-DH = patches/colemak-dh 173 GITSTATUS = patches/gitstatus 174 NAMEFIRST = patches/namefirst 175 RESTOREPREVIEW = patches/restorepreview 176 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) 182 endif 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 187 SRC += $(GETTIME_C) 188 HEADERS += $(GETTIME_H) 189 CPPFLAGS += -DMACOS_BELOW_1012 190 endif 191 192 ifeq ($(strip $(O_DEBUG)),1) 193 HEADERS += src/dbg.h 194 endif 195 ifeq ($(strip $(O_QSORT)),1) 196 HEADERS += src/qsort.h 197 endif 198 ifeq ($(strip $(O_EMOJI)),1) 199 HEADERS += src/icons.h src/$(ICONS_INCLUDE) 200 endif 201 ifeq ($(strip $(O_NERD)),1) 202 HEADERS += src/icons.h src/$(ICONS_INCLUDE) 203 endif 204 ifeq ($(strip $(O_ICONS)),1) 205 HEADERS += src/icons.h src/$(ICONS_INCLUDE) src/icons-in-terminal.h 206 endif 207 208 all: $(BIN) 209 210 $(BIN): $(SRC) $(HEADERS) Makefile 211 @$(MAKE) --silent prepatch 212 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(GETTIME_C) $< $(LDLIBS) 213 @$(MAKE) --silent postpatch 214 215 # targets for backwards compatibility 216 debug: $(BIN) 217 norl: $(BIN) 218 nolc: $(BIN) 219 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 > $@ 223 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 231 232 uninstall-desktop: 233 $(RM) $(DESTDIR)$(DESKTOPPREFIX)/$(DESKTOPFILE) 234 $(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg 235 $(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png 236 237 install: all 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 242 243 uninstall: 244 $(RM) $(DESTDIR)$(PREFIX)/bin/$(BIN) 245 $(RM) $(DESTDIR)$(MANPREFIX)/man1/$(BIN).1 246 247 strip: $(BIN) 248 $(STRIP) $^ 249 250 upx: $(BIN) 251 $(STRIP) $^ 252 upx -qqq $^ 253 254 static: 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 267 268 musl: 269 cp misc/musl/musl-static-ubuntu.sh . 270 ./musl-static-ubuntu.sh 1 271 rm ./musl-static-ubuntu.sh 272 273 shellcheck: 274 find ./plugins/ -type f -not -name "*.md" -exec shellcheck {} + 275 276 dist: 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) 281 282 sign: 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 286 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)) 289 # upload sign file 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 323 324 clean: 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 326 327 checkpatches: 328 ./patches/check-patches.sh 329 330 prepatch: 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 335 endif 336 else ifeq ($(strip $(O_GITSTATUS)),1) 337 patch --forward $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/mainline.diff 338 endif 339 ifeq ($(strip $(O_RESTOREPREVIEW)),1) 340 patch --forward $(PATCH_OPTS) --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff 341 endif 342 ifeq ($(strip $(O_COLEMAK)),1) 343 patch --forward $(PATCH_OPTS) --strip=1 --input=$(COLEMAK)/mainline.diff 344 endif 345 ifeq ($(strip $(O_COLEMAK-DH)),1) 346 patch --forward $(PATCH_OPTS) --strip=1 --input=$(COLEMAK-DH)/mainline.diff 347 endif 348 349 postpatch: 350 ifeq ($(strip $(O_NAMEFIRST)),1) 351 ifeq ($(strip $(O_GITSTATUS)),1) 352 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/namefirst.diff 353 endif 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 357 endif 358 ifeq ($(strip $(O_RESTOREPREVIEW)),1) 359 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff 360 endif 361 ifeq ($(strip $(O_COLEMAK)),1) 362 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(COLEMAK)/mainline.diff 363 endif 364 ifeq ($(strip $(O_COLEMAK-DH)),1) 365 patch --reverse $(PATCH_OPTS) --strip=1 --input=$(COLEMAK-DH)/mainline.diff 366 endif 367 368 skip: ; 369 370 .PHONY: all install uninstall strip static dist sign upload-local clean install-desktop uninstall-desktop