nnn

mirror of https://github.com/jarun/nnn
Log | Files | Refs | README | LICENSE

Makefile (13320B)


      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 := 1  # no readline support
     16 O_PCRE2 := 0  # link with PCRE2 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_ICONS := 0  # support icons-in-terminal
     22 O_NERD := 0  # support icons-nerdfont
     23 O_EMOJI := 0  # support emoji
     24 O_QSORT := 0  # use Alexey Tourbin's QSORT implementation
     25 O_BENCH := 0  # benchmark mode (stops at first user input)
     26 O_NOSSN := 0  # disable session support
     27 O_NOUG := 0  # disable user, group name in status bar
     28 O_NOX11 := 0  # disable X11 integration
     29 O_NOSORT := 0  # disable sorting entries on dir load
     30 O_DIMFILTERED := 1  # dim characters matching filter (default: enabled)
     31 
     32 # User patches
     33 O_COLEMAK := 0 # change key bindings to colemak compatible layout
     34 O_GITSTATUS := 0 # add git status to detail view
     35 O_NAMEFIRST := 0 # print file name first, add uid and guid to detail view
     36 O_RESTOREPREVIEW := 0 # add preview pipe to close and restore preview pane
     37 
     38 T_ICONS := 0 # test if multiple icons options are set and fail
     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_PCRE2)),1)
     66 	CPPFLAGS += -DPCRE2
     67 	LDLIBS += -lpcre2-8
     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_ICONS)),1)
     95 	ICONS_INCLUDE = icons-generated-icons-in-term.h
     96 	CPPFLAGS += -DICONS_IN_TERM -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
     97 ifeq ($(strip $(T_ICONS)),1)
     98 $(error Choose only one system for icons (O_ICONS, O_NERD or O_EMOJI))
     99 endif
    100 	T_ICONS := 1
    101 endif
    102 
    103 ifeq ($(strip $(O_NERD)),1)
    104 	ICONS_INCLUDE = icons-generated-nerd.h
    105 	CPPFLAGS += -DNERD -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
    106 ifeq ($(strip $(T_ICONS)),1)
    107 $(error Choose only one system for icons (O_ICONS, O_NERD or O_EMOJI))
    108 endif
    109 	T_ICONS := 1
    110 endif
    111 
    112 ifeq ($(strip $(O_EMOJI)),1)
    113 	ICONS_INCLUDE = icons-generated-emoji.h
    114 	CPPFLAGS += -DEMOJI -DICONS_INCLUDE=\"$(ICONS_INCLUDE)\"
    115 ifeq ($(strip $(T_ICONS)),1)
    116 $(error Choose only one system for icons (O_ICONS, O_NERD or O_EMOJI))
    117 endif
    118 	T_ICONS := 1
    119 endif
    120 
    121 ifeq ($(strip $(O_QSORT)),1)
    122 	CPPFLAGS += -DTOURBIN_QSORT
    123 endif
    124 
    125 ifeq ($(strip $(O_BENCH)),1)
    126 	CPPFLAGS += -DBENCH
    127 endif
    128 
    129 ifeq ($(strip $(O_NOSSN)),1)
    130 	CPPFLAGS += -DNOSSN
    131 endif
    132 
    133 ifeq ($(strip $(O_NOUG)),1)
    134 	CPPFLAGS += -DNOUG
    135 endif
    136 
    137 ifeq ($(strip $(O_NOX11)),1)
    138 	CPPFLAGS += -DNOX11
    139 endif
    140 
    141 ifeq ($(strip $(O_NOSORT)),1)
    142 	CPPFLAGS += -DNOSORT
    143 endif
    144 
    145 ifeq ($(strip $(O_DIMFILTERED)),1)
    146 	CPPFLAGS += -DDIM_FILTERED
    147 endif
    148 
    149 ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
    150 	CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw)
    151 	LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs   ncursesw)
    152 else ifeq ($(shell $(PKG_CONFIG) ncurses && echo 1),1)
    153 	CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncurses)
    154 	LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs   ncurses)
    155 else
    156 	LDLIBS_CURSES ?= -lncurses
    157 endif
    158 
    159 CFLAGS += -std=c11 -Wall -Wextra -Wshadow
    160 CFLAGS += $(CFLAGS_OPTIMIZATION)
    161 CFLAGS += $(CFLAGS_CURSES)
    162 
    163 LDLIBS += $(LDLIBS_CURSES) -lpthread
    164 
    165 # For the icon hashtable generator
    166 HOST_CC ?= $(CC)
    167 HOST_CFLAGS ?= $(CFLAGS)
    168 
    169 # static compilation needs libgpm development package
    170 ifeq ($(strip $(O_STATIC)),1)
    171 	LDFLAGS += -static
    172 	LDLIBS += -lgpm
    173 endif
    174 
    175 DISTFILES = src nnn.1 Makefile README.md LICENSE
    176 SRC = src/nnn.c
    177 HEADERS = src/nnn.h
    178 BIN = nnn
    179 DESKTOPFILE = misc/desktop/nnn.desktop
    180 LOGOSVG = misc/logo/logo.svg
    181 LOGO64X64 = misc/logo/logo-64x64.png
    182 
    183 COLEMAK = patches/colemak
    184 GITSTATUS = patches/gitstatus
    185 NAMEFIRST = patches/namefirst
    186 RESTOREPREVIEW = patches/restorepreview
    187 
    188 # test if we are on Mac OS X and get X.Y.Z OS version with system binary /usr/bin/sw_vers
    189 MACOS_VERSION := $(strip $(shell command -v sw_vers >/dev/null && [ "`sw_vers -productName`" = "Mac OS X" ] && sw_vers -productVersion))
    190 # 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
    191 ifneq ($(MACOS_VERSION),)
    192 	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)
    193 endif
    194 # 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
    195 ifneq ($(MACOS_BELOW_1012),)
    196 	GETTIME_C = misc/macos-legacy/mach_gettime.c
    197 	GETTIME_H = misc/macos-legacy/mach_gettime.h
    198 	SRC += $(GETTIME_C)
    199 	HEADERS += $(GETTIME_H)
    200 	CPPFLAGS += -DMACOS_BELOW_1012
    201 endif
    202 
    203 ifeq ($(strip $(O_DEBUG)),1)
    204 	HEADERS += src/dbg.h
    205 endif
    206 ifeq ($(strip $(O_QSORT)),1)
    207 	HEADERS += src/qsort.h
    208 endif
    209 ifeq ($(strip $(O_EMOJI)),1)
    210 	HEADERS += src/icons.h src/$(ICONS_INCLUDE)
    211 endif
    212 ifeq ($(strip $(O_NERD)),1)
    213 	HEADERS += src/icons.h src/$(ICONS_INCLUDE)
    214 endif
    215 ifeq ($(strip $(O_ICONS)),1)
    216 	HEADERS += src/icons.h src/$(ICONS_INCLUDE) src/icons-in-terminal.h
    217 endif
    218 
    219 all: $(BIN)
    220 
    221 $(BIN): $(SRC) $(HEADERS) Makefile
    222 	@$(MAKE) --silent prepatch
    223 	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(GETTIME_C) $< $(LDLIBS)
    224 	@$(MAKE) --silent postpatch
    225 
    226 # targets for backwards compatibility
    227 debug: $(BIN)
    228 norl: $(BIN)
    229 nolc: $(BIN)
    230 
    231 src/$(ICONS_INCLUDE): src/icons-hash.c src/icons.h src/icons-in-terminal.h
    232 	$(HOST_CC) $(HOST_CFLAGS) $(CPPFLAGS) -DICONS_GENERATE -o src/icons-hash-gen src/icons-hash.c
    233 	./src/icons-hash-gen > $@
    234 
    235 install-desktop: $(DESKTOPFILE)
    236 	$(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPPREFIX)
    237 	$(INSTALL) -m 0644 $(DESKTOPFILE) $(DESTDIR)$(DESKTOPPREFIX)
    238 	$(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps
    239 	$(INSTALL) -m 0644 $(LOGOSVG) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg
    240 	$(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps
    241 	$(INSTALL) -m 0644 $(LOGO64X64) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png
    242 
    243 uninstall-desktop:
    244 	$(RM) $(DESTDIR)$(DESKTOPPREFIX)/$(DESKTOPFILE)
    245 	$(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg
    246 	$(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png
    247 
    248 install: all
    249 	$(INSTALL) -m 0755 -d $(DESTDIR)$(PREFIX)/bin
    250 	$(INSTALL) -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin
    251 	$(INSTALL) -m 0755 -d $(DESTDIR)$(MANPREFIX)/man1
    252 	$(INSTALL) -m 0644 $(BIN).1 $(DESTDIR)$(MANPREFIX)/man1
    253 
    254 uninstall:
    255 	$(RM) $(DESTDIR)$(PREFIX)/bin/$(BIN)
    256 	$(RM) $(DESTDIR)$(MANPREFIX)/man1/$(BIN).1
    257 
    258 strip: $(BIN)
    259 	$(STRIP) $^
    260 
    261 upx: $(BIN)
    262 	$(STRIP) $^
    263 	upx -qqq $^
    264 
    265 static:
    266 	# regular static binary
    267 	make O_STATIC=1 strip
    268 	mv $(BIN) $(BIN)-static
    269 	# static binary with icons-in-terminal support
    270 	make O_STATIC=1 O_ICONS=1 strip
    271 	mv $(BIN) $(BIN)-icons-static
    272 	# static binary with patched nerd font support
    273 	make O_STATIC=1 O_NERD=1 strip
    274 	mv $(BIN) $(BIN)-nerd-static
    275 	# static binary with emoji support
    276 	make O_STATIC=1 O_EMOJI=1 strip
    277 	mv $(BIN) $(BIN)-emoji-static
    278 
    279 musl:
    280 	cp misc/musl/musl-static-ubuntu.sh .
    281 	./musl-static-ubuntu.sh 1
    282 	rm ./musl-static-ubuntu.sh
    283 
    284 shellcheck:
    285 	find ./plugins/ -type f -not -name "*.md" -exec shellcheck {} +
    286 
    287 dist:
    288 	mkdir -p nnn-$(VERSION)
    289 	$(CP) -r $(DISTFILES) nnn-$(VERSION)
    290 	tar -cf - nnn-$(VERSION) | gzip > nnn-$(VERSION).tar.gz
    291 	$(RM) -r nnn-$(VERSION)
    292 
    293 sign:
    294 	git archive -o nnn-$(VERSION).tar.gz --format tar.gz --prefix=nnn-$(VERSION)/ v$(VERSION)
    295 	gpg --detach-sign --yes nnn-$(VERSION).tar.gz
    296 	rm -f nnn-$(VERSION).tar.gz
    297 
    298 upload-local: sign static musl
    299 	$(eval ID=$(shell curl -s 'https://api.github.com/repos/jarun/nnn/releases/tags/v$(VERSION)' | jq .id))
    300 	$(eval PKG_STATIC=$(BIN)-static)
    301 	$(eval PKG_ICONS=$(BIN)-icons-static)
    302 	$(eval PKG_NERD=$(BIN)-nerd-static)
    303 	$(eval PKG_EMOJI=$(BIN)-emoji-static)
    304 	$(eval PKG_MUSL=$(BIN)-musl-static)
    305 	$(eval PKG_MUSL_EMOJI=$(BIN)-musl-emoji-static)
    306 	$(eval ARCH=x86_64)
    307 
    308 	# upload sign file
    309 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=nnn-$(VERSION).tar.gz.sig' \
    310 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/pgp-signature' \
    311 	    --upload-file nnn-$(VERSION).tar.gz.sig
    312 
    313 	# upx compress all static binaries
    314 	upx -qqq $(PKG_STATIC)
    315 	upx -qqq $(PKG_ICONS)
    316 	upx -qqq $(PKG_NERD)
    317 	upx -qqq $(PKG_EMOJI)
    318 	upx -qqq $(PKG_MUSL)
    319 	upx -qqq $(PKG_MUSL_EMOJI)
    320 
    321 	# upload static binary
    322 	tar -zcf $(PKG_STATIC)-$(VERSION).$(ARCH).tar.gz $(PKG_STATIC)
    323 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(PKG_STATIC)-$(VERSION).$(ARCH).tar.gz' \
    324 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    325 	    --upload-file $(PKG_STATIC)-$(VERSION).$(ARCH).tar.gz
    326 
    327 	# upload icons-in-terminal compiled static binary
    328 	tar -zcf $(PKG_ICONS)-$(VERSION).$(ARCH).tar.gz $(PKG_ICONS)
    329 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(PKG_ICONS)-$(VERSION).$(ARCH).tar.gz' \
    330 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    331 	    --upload-file $(PKG_ICONS)-$(VERSION).$(ARCH).tar.gz
    332 
    333 	# upload patched nerd font compiled static binary
    334 	tar -zcf $(PKG_NERD)-$(VERSION).$(ARCH).tar.gz $(PKG_NERD)
    335 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(PKG_NERD)-$(VERSION).$(ARCH).tar.gz' \
    336 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    337 	    --upload-file $(PKG_NERD)-$(VERSION).$(ARCH).tar.gz
    338 
    339 	# upload emoji compiled static binary
    340 	tar -zcf $(PKG_EMOJI)-$(VERSION).$(ARCH).tar.gz $(PKG_EMOJI)
    341 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(PKG_EMOJI)-$(VERSION).$(ARCH).tar.gz' \
    342 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    343 	    --upload-file $(PKG_EMOJI)-$(VERSION).$(ARCH).tar.gz
    344 
    345 	# upload musl static binary
    346 	tar -zcf $(PKG_MUSL)-$(VERSION).$(ARCH).tar.gz $(PKG_MUSL)
    347 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(PKG_MUSL)-$(VERSION).$(ARCH).tar.gz' \
    348 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    349 	    --upload-file $(PKG_MUSL)-$(VERSION).$(ARCH).tar.gz
    350 
    351 	# upload musl emoji static binary
    352 	tar -zcf $(PKG_MUSL_EMOJI)-$(VERSION).$(ARCH).tar.gz $(PKG_MUSL_EMOJI)
    353 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(PKG_MUSL_EMOJI)-$(VERSION).$(ARCH).tar.gz' \
    354 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    355 	    --upload-file $(PKG_MUSL_EMOJI)-$(VERSION).$(ARCH).tar.gz
    356 
    357 clean:
    358 	$(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 $(BIN)-musl-emoji-static $(BIN)-musl-emoji-static-$(VERSION).x86_64.tar.gz src/icons-hash-gen src/icons-generated-*.h
    359 
    360 checkpatches:
    361 	./patches/check-patches.sh
    362 
    363 prepatch:
    364 ifeq ($(strip $(O_NAMEFIRST)),1)
    365 	patch --forward $(PATCH_OPTS) --strip=1 --input=$(NAMEFIRST)/mainline.diff
    366 ifeq ($(strip $(O_GITSTATUS)),1)
    367 	patch --forward $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/namefirst.diff
    368 endif
    369 else ifeq ($(strip $(O_GITSTATUS)),1)
    370 	patch --forward $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/mainline.diff
    371 endif
    372 ifeq ($(strip $(O_RESTOREPREVIEW)),1)
    373 	patch --forward $(PATCH_OPTS) --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff
    374 endif
    375 ifeq ($(strip $(O_COLEMAK)),1)
    376 	patch --forward $(PATCH_OPTS) --strip=1 --input=$(COLEMAK)/mainline.diff
    377 endif
    378 
    379 postpatch:
    380 ifeq ($(strip $(O_NAMEFIRST)),1)
    381 ifeq ($(strip $(O_GITSTATUS)),1)
    382 	patch --reverse $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/namefirst.diff
    383 endif
    384 	patch --reverse $(PATCH_OPTS) --strip=1 --input=$(NAMEFIRST)/mainline.diff
    385 else ifeq ($(strip $(O_GITSTATUS)),1)
    386 	patch --reverse $(PATCH_OPTS) --strip=1 --input=$(GITSTATUS)/mainline.diff
    387 endif
    388 ifeq ($(strip $(O_RESTOREPREVIEW)),1)
    389 	patch --reverse $(PATCH_OPTS) --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff
    390 endif
    391 ifeq ($(strip $(O_COLEMAK)),1)
    392 	patch --reverse $(PATCH_OPTS) --strip=1 --input=$(COLEMAK)/mainline.diff
    393 endif
    394 
    395 skip: ;
    396 
    397 .PHONY: all install uninstall strip static dist sign upload-local clean install-desktop uninstall-desktop