nnn

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

Makefile (6289B)


      1 VERSION = $(shell grep -m1 VERSION $(SRC) | cut -f 2 -d'"')
      2 
      3 PREFIX ?= /boot/system/non-packaged
      4 MANPREFIX ?= $(PREFIX)/documentation/man
      5 STRIP ?= strip
      6 PKG_CONFIG ?= pkg-config
      7 INSTALL ?= install
      8 CP ?= cp
      9 
     10 CFLAGS_OPTIMIZATION ?= -O3
     11 
     12 O_DEBUG := 0  # debug binary
     13 O_NORL := 0  # no readline support
     14 O_PCRE := 0  # link with PCRE library
     15 O_NOLC := 0  # no locale support
     16 O_NOMOUSE := 0  # no mouse support
     17 O_NOBATCH := 0  # no built-in batch renamer
     18 O_NOFIFO := 0  # no FIFO previewer support
     19 O_ICONS := 0  # support icons-in-terminal
     20 O_NERD := 0  # support icons-nerdfont
     21 O_QSORT := 0  # use Alexey Tourbin's QSORT implementation
     22 O_BENCH := 0  # benchmark mode (stops at first user input)
     23 O_NOSSN := 0  # disable session support
     24 O_NOUG := 0  # disable user, group name in status bar
     25 O_NOX11 := 0  # disable X11 integration
     26 O_MATCHFLTR := 0  # allow filters without matches
     27 
     28 # User patches
     29 O_GITSTATUS := 0 # add git status to detail view
     30 O_NAMEFIRST := 0 # print file name first, add uid and guid to detail view
     31 
     32 ifeq ($(strip $(O_GITSTATUS)),1)
     33 	LDLIBS += -lgit2
     34 endif
     35 
     36 # convert targets to flags for backwards compatibility
     37 ifneq ($(filter debug,$(MAKECMDGOALS)),)
     38 	O_DEBUG := 1
     39 endif
     40 ifneq ($(filter norl,$(MAKECMDGOALS)),)
     41 	O_NORL := 1
     42 endif
     43 ifneq ($(filter nolc,$(MAKECMDGOALS)),)
     44 	O_NORL := 1
     45 	O_NOLC := 1
     46 endif
     47 
     48 ifeq ($(strip $(O_DEBUG)),1)
     49 	CPPFLAGS += -DDEBUG
     50 	CFLAGS += -g
     51 	LDLIBS += -lrt
     52 endif
     53 
     54 ifeq ($(strip $(O_NORL)),1)
     55 	CPPFLAGS += -DNORL
     56 else ifeq ($(strip $(O_STATIC)),1)
     57 	CPPFLAGS += -DNORL
     58 else
     59 	LDLIBS += -lreadline
     60 endif
     61 
     62 ifeq ($(strip $(O_PCRE)),1)
     63 	CPPFLAGS += -DPCRE
     64 	LDLIBS += -lpcre
     65 endif
     66 
     67 ifeq ($(strip $(O_NOLC)),1)
     68 	ifeq ($(strip $(O_ICONS)),1)
     69 $(info *** Ignoring O_NOLC since O_ICONS is set ***)
     70 	else ifeq ($(strip $(O_NERD)),1)
     71 $(info *** Ignoring O_NOLC since O_NERD is set ***)
     72 	else
     73 		CPPFLAGS += -DNOLC
     74 	endif
     75 endif
     76 
     77 ifeq ($(strip $(O_NOMOUSE)),1)
     78 	CPPFLAGS += -DNOMOUSE
     79 endif
     80 
     81 ifeq ($(strip $(O_NOBATCH)),1)
     82 	CPPFLAGS += -DNOBATCH
     83 endif
     84 
     85 ifeq ($(strip $(O_NOFIFO)),1)
     86 	CPPFLAGS += -DNOFIFO
     87 endif
     88 
     89 ifeq ($(strip $(O_ICONS)),1)
     90 	CPPFLAGS += -DICONS
     91 endif
     92 
     93 ifeq ($(strip $(O_NERD)),1)
     94 	CPPFLAGS += -DNERD
     95 endif
     96 
     97 ifeq ($(strip $(O_QSORT)),1)
     98 	CPPFLAGS += -DTOURBIN_QSORT
     99 endif
    100 
    101 ifeq ($(strip $(O_BENCH)),1)
    102 	CPPFLAGS += -DBENCH
    103 endif
    104 
    105 ifeq ($(strip $(O_NOSSN)),1)
    106 	CPPFLAGS += -DNOSSN
    107 endif
    108 
    109 ifeq ($(strip $(O_NOUG)),1)
    110 	CPPFLAGS += -DNOUG
    111 endif
    112 
    113 ifeq ($(strip $(O_NOX11)),1)
    114 	CPPFLAGS += -DNOX11
    115 endif
    116 
    117 ifeq ($(strip $(O_MATCHFLTR)),1)
    118 	CPPFLAGS += -DMATCHFLTR
    119 endif
    120 
    121 ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
    122 	CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw)
    123 	LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs   ncursesw)
    124 else ifeq ($(shell $(PKG_CONFIG) ncurses && echo 1),1)
    125 	CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncurses)
    126 	LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs   ncurses)
    127 else
    128 	LDLIBS_CURSES ?= -lncurses
    129 endif
    130 
    131 ifeq ($(shell uname -s), Haiku)
    132 	LDLIBS_HAIKU ?= -lstdc++ -lgnu -lbe
    133 	SRC_HAIKU ?= misc/haiku/nm.cpp
    134 	OBJS_HAIKU ?= misc/haiku/nm.o
    135 endif
    136 
    137 CFLAGS += -std=c11 -Wall -Wextra -Wshadow
    138 CFLAGS += $(CFLAGS_OPTIMIZATION)
    139 CFLAGS += $(CFLAGS_CURSES)
    140 
    141 LDLIBS += $(LDLIBS_CURSES) -lpthread $(LDLIBS_HAIKU)
    142 # static compilation needs libgpm development package
    143 ifeq ($(strip $(O_STATIC)),1)
    144 	LDFLAGS += -static
    145 	LDLIBS += -lgpm
    146 endif
    147 
    148 DISTFILES = src nnn.1 Makefile README.md LICENSE
    149 SRC = src/nnn.c
    150 HEADERS = src/nnn.h
    151 BIN = nnn
    152 OBJS := nnn.o $(OBJS_HAIKU)
    153 
    154 GITSTATUS = patches/gitstatus
    155 NAMEFIRST = patches/namefirst
    156 
    157 all: $(BIN)
    158 
    159 ifeq ($(shell uname -s), Haiku)
    160 $(OBJS_HAIKU): $(SRC_HAIKU)
    161 	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
    162 endif
    163 
    164 nnn.o: $(SRC) $(HEADERS)
    165 	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
    166 
    167 $(BIN): $(OBJS)
    168 	@$(MAKE) --silent prepatch
    169 	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
    170 	@$(MAKE) --silent postpatch
    171 
    172 # targets for backwards compatibility
    173 debug: $(BIN)
    174 norl: $(BIN)
    175 nolc: $(BIN)
    176 
    177 install: all
    178 	$(INSTALL) -m 0755 -d $(DESTDIR)$(PREFIX)/bin
    179 	$(INSTALL) -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin
    180 	$(INSTALL) -m 0755 -d $(DESTDIR)$(MANPREFIX)/man1
    181 	$(INSTALL) -m 0644 $(BIN).1 $(DESTDIR)$(MANPREFIX)/man1
    182 
    183 uninstall:
    184 	$(RM) $(DESTDIR)$(PREFIX)/bin/$(BIN)
    185 	$(RM) $(DESTDIR)$(MANPREFIX)/man1/$(BIN).1
    186 
    187 strip: $(BIN)
    188 	$(STRIP) $^
    189 
    190 static:
    191 	# regular static binary
    192 	make O_STATIC=1 strip
    193 	mv $(BIN) $(BIN)-static
    194 
    195 dist:
    196 	mkdir -p nnn-$(VERSION)
    197 	$(CP) -r $(DISTFILES) nnn-$(VERSION)
    198 	mkdir -p nnn-$(VERSION)/misc
    199 	$(CP) -r misc/haiku nnn-$(VERSION)/misc
    200 	tar -cf - nnn-$(VERSION) | gzip > nnn-$(VERSION).tar.gz
    201 	$(RM) -r nnn-$(VERSION)
    202 
    203 sign:
    204 	git archive -o nnn-$(VERSION).tar.gz --format tar.gz --prefix=nnn-$(VERSION)/ v$(VERSION)
    205 	gpg --detach-sign --yes nnn-$(VERSION).tar.gz
    206 	rm -f nnn-$(VERSION).tar.gz
    207 
    208 upload-local: sign static
    209 	$(eval ID=$(shell curl -s 'https://api.github.com/repos/jarun/nnn/releases/tags/v$(VERSION)' | jq .id))
    210 	# upload sign file
    211 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=nnn-$(VERSION).tar.gz.sig' \
    212 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/pgp-signature' \
    213 	    --upload-file nnn-$(VERSION).tar.gz.sig
    214 	tar -zcf $(BIN)-static-$(VERSION).x86_64.tar.gz $(BIN)-static
    215 	# upload static binary
    216 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-static-$(VERSION).x86_64.tar.gz' \
    217 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    218 	    --upload-file $(BIN)-static-$(VERSION).x86_64.tar.gz
    219 
    220 clean:
    221 	$(RM) -f $(BIN) nnn-$(VERSION).tar.gz *.sig $(BIN)-static $(BIN)-static-$(VERSION).x86_64.tar.gz
    222 
    223 prepatch:
    224 ifeq ($(strip $(O_NAMEFIRST)),1)
    225 	patch --forward --strip=1 --input=$(NAMEFIRST)/mainline.diff
    226 ifeq ($(strip $(O_GITSTATUS)),1)
    227 	patch --forward --strip=1 --input=$(GITSTATUS)/namefirst.diff
    228 endif
    229 else ifeq ($(strip $(O_GITSTATUS)),1)
    230 	patch --forward --strip=1 --input=$(GITSTATUS)/mainline.diff
    231 endif
    232 
    233 postpatch:
    234 ifeq ($(strip $(O_NAMEFIRST)),1)
    235 ifeq ($(strip $(O_GITSTATUS)),1)
    236 	patch --reverse --strip=1 --input=$(GITSTATUS)/namefirst.diff
    237 endif
    238 	patch --reverse --strip=1 --input=$(NAMEFIRST)/mainline.diff
    239 else ifeq ($(strip $(O_GITSTATUS)),1)
    240 	patch --reverse --strip=1 --input=$(GITSTATUS)/mainline.diff
    241 endif
    242 
    243 skip: ;
    244 
    245 .PHONY: all install uninstall strip static dist sign upload-local clean