-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathMakefile
116 lines (87 loc) · 3.45 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (c) 2014–2019, Eddie Antonio Santos <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Outputs
BIN = imgcat
MAN = docs/imgcat.1
# Variables for installing
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man/man1
# Build
DISTRIBUTION = $(BIN)-$(PACKAGE_VERSION)
GENERATED_FILES = config.mk src/cimg_config.h src/config.h
# config.mk is generated by ./configure and defines:
# - PACKAGE_VERSION - semver version number
# - CXXSTD -- what flag to use to compile C++11. Useful for older versions of g++
# - INCLUDE_FLAGS - what c compiler flags should be used for included libraries
# - LIBS - what ld flags for linking to libraries
# - PANDOC - pandoc(1), if it exists
include config.mk
CFLAGS += -std=c11 -Wall $(INCLUDE_FLAGS)
CXXFLAGS += $(CXXSTD) -Wall $(INCLUDE_FLAGS)
# the -M* options produce .d files in addition to .o files,
# to keep track of header dependencies (see: $(DEPS)).
OUTPUT_OPTION = -MMD -MP -o $@
# Use the C++ compiler to link, because we're using one C++ file!
LD = $(CXX)
# CImg requires pthread, for some reason
LDLIBS = $(LIBS) -ltermcap -lm -lpthread
# Get the source files.
SOURCES = $(wildcard src/*.c) $(wildcard src/*.cc)
OBJS = $(addsuffix .o,$(basename $(SOURCES)))
DEPS = $(OBJS:.o=.d)
################################ Phony rules #################################
.PHONY: all clean clean-all dist install test
all: $(BIN) $(MAN)
clean:
$(RM) $(BIN) $(OBJS) $(DEPS)
clean-all: clean
$(RM) $(GENERATED_FILES)
dist: $(DISTRIBUTION).tar.gz
install: $(BIN) $(MAN)
install -d $(BINDIR) $(MANDIR)
install -s $(BIN) $(BINDIR)
install -m 644 $(MAN) $(MANDIR)
test: $(BIN)
tests/run $<
############################## Specific targets ##############################
# Create the main executable:
$(BIN): $(OBJS)
$(LD) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
# Use ./configure to generate all requisite files
$(GENERATED_FILES): configure VERSION
./$<
# XXX: The CImg.h file uses arr['char'] as subscripts, which Clang doesn't
# like, so enable this flag JUST for the file that includes it!
src/load_image.o: CXXFLAGS+=-Wno-char-subscripts -I./CImg
src/load_image.o:
# Automatically clone CImg if not found:
CImg/CImg.h:
git submodule update --init
$(DISTRIBUTION):
mkdir -p $(DISTRIBUTION)/
cp -r src Makefile configure README.md LICENSE VERSION $(DISTRIBUTION)/
mkdir -p $(DISTRIBUTION)/CImg
cp CImg/CImg.h $(DISTRIBUTION)/CImg/
mkdir -p $(DISTRIBUTION)/docs
cp $(MAN) $(DISTRIBUTION)/$(MAN)
$(DISTRIBUTION).tar.gz: $(DISTRIBUTION)
tar czvf $@ $^
.PHONY: $(DISTRIBUTION)
# Dependency files (generated by -M in compilation)
-include $(DEPS)
############################### Pattern rules ################################
%.1: %.1.md
$(PANDOC) --standalone --to=man $(PANDOCFLAGS) \
-Vdate='$(shell date +'%B %d, %Y')' $< -o $@