sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

Makefile (6377B)


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