sistema_progs

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

Makefile (10002B)


      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 := 0  # support icons-nerdfont
     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_MATCHFLTR := 0  # allow filters without matches
     30 O_NOSORT := 0  # disable sorting entries on dir load
     31 
     32 # User patches
     33 O_GITSTATUS := 0 # add git status to detail view
     34 O_NAMEFIRST := 0 # print file name first, add uid and guid to detail view
     35 O_RESTOREPREVIEW := 0 # add preview pipe to close and restore preview pane
     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 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_CTX8)),1)
     90 	CPPFLAGS += -DCTX8
     91 endif
     92 
     93 ifeq ($(strip $(O_ICONS)),1)
     94 	CPPFLAGS += -DICONS
     95 endif
     96 
     97 ifeq ($(strip $(O_NERD)),1)
     98 	CPPFLAGS += -DNERD
     99 endif
    100 
    101 ifeq ($(strip $(O_QSORT)),1)
    102 	CPPFLAGS += -DTOURBIN_QSORT
    103 endif
    104 
    105 ifeq ($(strip $(O_BENCH)),1)
    106 	CPPFLAGS += -DBENCH
    107 endif
    108 
    109 ifeq ($(strip $(O_NOSSN)),1)
    110 	CPPFLAGS += -DNOSSN
    111 endif
    112 
    113 ifeq ($(strip $(O_NOUG)),1)
    114 	CPPFLAGS += -DNOUG
    115 endif
    116 
    117 ifeq ($(strip $(O_NOX11)),1)
    118 	CPPFLAGS += -DNOX11
    119 endif
    120 
    121 ifeq ($(strip $(O_MATCHFLTR)),1)
    122 	CPPFLAGS += -DMATCHFLTR
    123 endif
    124 
    125 ifeq ($(strip $(O_NOSORT)),1)
    126 	CPPFLAGS += -DNOSORT
    127 endif
    128 
    129 ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
    130 	CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw)
    131 	LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs   ncursesw)
    132 else ifeq ($(shell $(PKG_CONFIG) ncurses && echo 1),1)
    133 	CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncurses)
    134 	LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs   ncurses)
    135 else
    136 	LDLIBS_CURSES ?= -lncurses
    137 endif
    138 
    139 CFLAGS += -std=c11 -Wall -Wextra -Wshadow
    140 CFLAGS += $(CFLAGS_OPTIMIZATION)
    141 CFLAGS += $(CFLAGS_CURSES)
    142 
    143 LDLIBS += $(LDLIBS_CURSES) -lpthread
    144 
    145 # static compilation needs libgpm development package
    146 ifeq ($(strip $(O_STATIC)),1)
    147 	LDFLAGS += -static
    148 	LDLIBS += -lgpm
    149 endif
    150 
    151 DISTFILES = src nnn.1 Makefile README.md LICENSE
    152 SRC = src/nnn.c
    153 HEADERS = src/nnn.h
    154 BIN = nnn
    155 DESKTOPFILE = misc/desktop/nnn.desktop
    156 LOGOSVG = misc/logo/logo.svg
    157 LOGO64X64 = misc/logo/logo-64x64.png
    158 
    159 GITSTATUS = patches/gitstatus
    160 NAMEFIRST = patches/namefirst
    161 RESTOREPREVIEW = patches/restorepreview
    162 
    163 # test if we are on Mac OS X and get X.Y.Z OS version with system binary /usr/bin/sw_vers
    164 MACOS_VERSION := $(strip $(shell command -v sw_vers >/dev/null && [ "`sw_vers -productName`" = "Mac OS X" ] && sw_vers -productVersion))
    165 # 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
    166 ifneq ($(MACOS_VERSION),)
    167 	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)
    168 endif
    169 # 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
    170 ifneq ($(MACOS_BELOW_1012),)
    171 	GETTIME_C = misc/macos-legacy/mach_gettime.c
    172 	GETTIME_H = misc/macos-legacy/mach_gettime.h
    173 	SRC += $(GETTIME_C)
    174 	HEADERS += $(GETTIME_H)
    175 	CPPFLAGS += -DMACOS_BELOW_1012
    176 endif
    177 
    178 all: $(BIN)
    179 
    180 $(BIN): $(SRC) $(HEADERS) Makefile
    181 	@$(MAKE) --silent prepatch
    182 	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(GETTIME_C) $< $(LDLIBS)
    183 	@$(MAKE) --silent postpatch
    184 
    185 # targets for backwards compatibility
    186 debug: $(BIN)
    187 norl: $(BIN)
    188 nolc: $(BIN)
    189 
    190 install-desktop: $(DESKTOPFILE)
    191 	$(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPPREFIX)
    192 	$(INSTALL) -m 0644 $(DESKTOPFILE) $(DESTDIR)$(DESKTOPPREFIX)
    193 	$(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps
    194 	$(INSTALL) -m 0644 $(LOGOSVG) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg
    195 	$(INSTALL) -m 0755 -d $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps
    196 	$(INSTALL) -m 0644 $(LOGO64X64) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png
    197 
    198 uninstall-desktop:
    199 	$(RM) $(DESTDIR)$(DESKTOPPREFIX)/$(DESKTOPFILE)
    200 	$(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/scalable/apps/nnn.svg
    201 	$(RM) $(DESTDIR)$(DESKTOPICONPREFIX)/64x64/apps/nnn.png
    202 
    203 install: all
    204 	$(INSTALL) -m 0755 -d $(DESTDIR)$(PREFIX)/bin
    205 	$(INSTALL) -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin
    206 	$(INSTALL) -m 0755 -d $(DESTDIR)$(MANPREFIX)/man1
    207 	$(INSTALL) -m 0644 $(BIN).1 $(DESTDIR)$(MANPREFIX)/man1
    208 
    209 uninstall:
    210 	$(RM) $(DESTDIR)$(PREFIX)/bin/$(BIN)
    211 	$(RM) $(DESTDIR)$(MANPREFIX)/man1/$(BIN).1
    212 
    213 strip: $(BIN)
    214 	$(STRIP) $^
    215 
    216 upx: $(BIN)
    217 	$(STRIP) $^
    218 	upx -qqq $^
    219 
    220 static:
    221 	# regular static binary
    222 	make O_STATIC=1 strip
    223 	mv $(BIN) $(BIN)-static
    224 	# static binary with icons-in-terminal support
    225 	make O_STATIC=1 O_ICONS=1 strip
    226 	mv $(BIN) $(BIN)-icons-static
    227 	# static binary with patched nerd font support
    228 	make O_STATIC=1 O_NERD=1 strip
    229 	mv $(BIN) $(BIN)-nerd-static
    230 
    231 musl:
    232 	cp misc/musl/musl-static-ubuntu.sh .
    233 	./musl-static-ubuntu.sh 1
    234 	rm ./musl-static-ubuntu.sh
    235 
    236 dist:
    237 	mkdir -p nnn-$(VERSION)
    238 	$(CP) -r $(DISTFILES) nnn-$(VERSION)
    239 	tar -cf - nnn-$(VERSION) | gzip > nnn-$(VERSION).tar.gz
    240 	$(RM) -r nnn-$(VERSION)
    241 
    242 sign:
    243 	git archive -o nnn-$(VERSION).tar.gz --format tar.gz --prefix=nnn-$(VERSION)/ v$(VERSION)
    244 	gpg --detach-sign --yes nnn-$(VERSION).tar.gz
    245 	rm -f nnn-$(VERSION).tar.gz
    246 
    247 upload-local: sign static musl
    248 	$(eval ID=$(shell curl -s 'https://api.github.com/repos/jarun/nnn/releases/tags/v$(VERSION)' | jq .id))
    249 	# upload sign file
    250 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=nnn-$(VERSION).tar.gz.sig' \
    251 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/pgp-signature' \
    252 	    --upload-file nnn-$(VERSION).tar.gz.sig
    253 	# upx compress all static binaries
    254 	upx -qqq $(BIN)-static
    255 	upx -qqq $(BIN)-icons-static
    256 	upx -qqq $(BIN)-nerd-static
    257 	# upload static binary
    258 	tar -zcf $(BIN)-static-$(VERSION).x86_64.tar.gz $(BIN)-static
    259 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-static-$(VERSION).x86_64.tar.gz' \
    260 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    261 	    --upload-file $(BIN)-static-$(VERSION).x86_64.tar.gz
    262 	# upload icons-in-terminal compiled static binary
    263 	tar -zcf $(BIN)-icons-static-$(VERSION).x86_64.tar.gz $(BIN)-icons-static
    264 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-icons-static-$(VERSION).x86_64.tar.gz' \
    265 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    266 	    --upload-file $(BIN)-icons-static-$(VERSION).x86_64.tar.gz
    267 	# upload patched nerd font compiled static binary
    268 	tar -zcf $(BIN)-nerd-static-$(VERSION).x86_64.tar.gz $(BIN)-nerd-static
    269 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-nerd-static-$(VERSION).x86_64.tar.gz' \
    270 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    271 	    --upload-file $(BIN)-nerd-static-$(VERSION).x86_64.tar.gz
    272 	# upload musl static binary
    273 	tar -zcf $(BIN)-musl-static-$(VERSION).x86_64.tar.gz $(BIN)-musl-static
    274 	curl -XPOST 'https://uploads.github.com/repos/jarun/nnn/releases/$(ID)/assets?name=$(BIN)-musl-static-$(VERSION).x86_64.tar.gz' \
    275 	    -H 'Authorization: token $(NNN_SIG_UPLOAD_TOKEN)' -H 'Content-Type: application/x-sharedlib' \
    276 	    --upload-file $(BIN)-musl-static-$(VERSION).x86_64.tar.gz
    277 
    278 clean:
    279 	$(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)-musl-static $(BIN)-musl-static-$(VERSION).x86_64.tar.gz
    280 
    281 prepatch:
    282 ifeq ($(strip $(O_NAMEFIRST)),1)
    283 	patch --forward --strip=1 --input=$(NAMEFIRST)/mainline.diff
    284 ifeq ($(strip $(O_GITSTATUS)),1)
    285 	patch --forward --strip=1 --input=$(GITSTATUS)/namefirst.diff
    286 endif
    287 else ifeq ($(strip $(O_GITSTATUS)),1)
    288 	patch --forward --strip=1 --input=$(GITSTATUS)/mainline.diff
    289 endif
    290 ifeq ($(strip $(O_RESTOREPREVIEW)),1)
    291 	patch --forward --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff
    292 endif
    293 
    294 postpatch:
    295 ifeq ($(strip $(O_NAMEFIRST)),1)
    296 ifeq ($(strip $(O_GITSTATUS)),1)
    297 	patch --reverse --strip=1 --input=$(GITSTATUS)/namefirst.diff
    298 endif
    299 	patch --reverse --strip=1 --input=$(NAMEFIRST)/mainline.diff
    300 else ifeq ($(strip $(O_GITSTATUS)),1)
    301 	patch --reverse --strip=1 --input=$(GITSTATUS)/mainline.diff
    302 endif
    303 ifeq ($(strip $(O_RESTOREPREVIEW)),1)
    304 	patch --reverse --strip=1 --input=$(RESTOREPREVIEW)/mainline.diff
    305 endif
    306 
    307 skip: ;
    308 
    309 .PHONY: all install uninstall strip static dist sign upload-local clean install-desktop uninstall-desktop