-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
118 lines (97 loc) · 3.42 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
117
118
NAME := dvd-vr
VERSION := 0.9.8b
PREFIX := /usr/local
DESTDIR :=
# Using override to append to user supplied CFLAGS
override CFLAGS+=-std=gnu99 -Wall -Wextra -Wpadded -DVERSION='"$(VERSION)"'
# Use `make DEBUG=1` to build debugging version
ifeq ($(DEBUG),1)
override CFLAGS+=-ggdb
else
override CFLAGS+=-O3 -DNDEBUG
endif
# Use `make UNIVERSAL=1` to build a Mac OS X universal binary
HAVE_MACOSX := $(shell $(CC) -xc -mmacosx-version-min -c - < /dev/null 2>/dev/null && echo 1 || echo 0)
ifeq ($(UNIVERSAL),1)
ifeq ($(HAVE_MACOSX),1)
UNIVERSAL_BINARY := -mmacosx-version-min=10.4 -force_cpusubtype_ALL -arch x86_64 -arch i386 -arch ppc
override CFLAGS+=$(UNIVERSAL_BINARY)
override LDFLAGS+=$(UNIVERSAL_BINARY)
else
$(warning "Warning: Universal binaries are only supported on Mac OS X")
endif
endif
# Use iconv when available
# This is not cached across make invocations unfortunately
H := \#
HAVE_ICONV := $(shell echo '$(H)include <iconv.h>' | $(CC) -xc -E - -o- >/dev/null 2>&1 && echo 1 || echo 0)
ifeq ($(HAVE_ICONV),1)
override CFLAGS+=-DHAVE_ICONV
# Work around const warnings
ICONV_CONST := $(shell (echo '$(H)include <iconv.h>'; echo "size_t iconv(iconv_t,char **,size_t*,char **,size_t*);") | $(CC) -xc -S - -o- >/dev/null 2>&1 || echo const)
override CFLAGS+=-DICONV_CONST="$(ICONV_CONST)"
# Add -liconv where available/required like Mac OS X & CYGWIN for example
NEED_LICONV := $(shell echo "int main(void){}" | $(CC) -xc -liconv - -o liconv_test 2>/dev/null && echo 1 || echo 0; rm -f liconv_test)
ifeq ($(NEED_LICONV),1)
LDFLAGS+=-liconv
endif
else
$(warning "Warning: title translation support disabled as libiconv not installed")
endif
# Strip debugging symbols if not debugging
ifneq ($(DEBUG),1)
LDFLAGS+=-Wl,-S
endif
HOST := $(shell uname | tr '[:lower:]' '[:upper:]')
ifneq (,$(findstring CYGWIN,$(HOST)))
EXEEXT := .exe
endif
BINARY := $(NAME)$(EXEEXT)
SOURCES := *.c
OBJECTS := $(patsubst %.c,%.o,$(wildcard $(SOURCES)))
#first target is the default
$(BINARY): $(OBJECTS)
$(CC) $(LIBS) $(OBJECTS) $(LDFLAGS) -o $@
#Enhance implicit rule for .c -> .o to depend on
#this Makefile itself so that a recompile is done
#if hardcoded settings like version etc. change.
%.o: %.c Makefile
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
.PHONY: all
all: $(BINARY) man
.PHONY: dist
dist: distman clean
mkdir $(NAME)-$(VERSION)
tar --exclude $(NAME)-$(VERSION) --exclude .svn --exclude .git -c . | (cd $(NAME)-$(VERSION) && tar -xp)
tar c $(NAME)-$(VERSION) | gzip -9 > $(NAME)-$(VERSION).tar.gz
-@rm -Rf $(NAME)-$(VERSION)
.PHONY: clean
clean:
-@rm -f *.o $(BINARY) core*
-@rm -Rf $(NAME)-$(VERSION)*
.PHONY: maintainer-clean
maintainer-clean: clean
-@rm -f man/$(NAME).1
.PHONY: distman
distman: $(BINARY) man/$(NAME).x
help2man --no-info --include=man/$(NAME).x ./$(BINARY) > man/$(NAME).1
#copy default if building from repo rather than tarball
#so that we remove the dependence on help2man and perl
man/$(NAME).1:
cp man/$(NAME).man man/$(NAME).1
.PHONY: man
man: | man/$(NAME).1
datadir := $(PREFIX)/share
mandir := $(datadir)/man
man1dir := $(mandir)/man1
bindir := $(PREFIX)/bin
.PHONY: install
install: $(BINARY) man
-@mkdir -p $(DESTDIR)$(bindir)
cp -p $(BINARY) $(DESTDIR)$(bindir)
-@mkdir -p $(DESTDIR)$(man1dir)
gzip -c man/$(NAME).1 > $(DESTDIR)$(man1dir)/$(NAME).1.gz
.PHONY: uninstall
uninstall:
rm $(DESTDIR)$(bindir)/$(BINARY)
rm $(DESTDIR)$(man1dir)/$(NAME).1*