-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile.in
134 lines (116 loc) · 4.83 KB
/
GNUmakefile.in
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Nuke built-in rules and variables.
MAKEFLAGS += -rR
.SUFFIXES:
# Convenience macro to reliably declare user overridable variables.
override USER_VARIABLE = $(if $(filter $(origin $(1)),default undefined),$(eval override $(1) := $(2)))
# Import some autoconf variables as make variables.
# Those beginning with DEFAULT_ are user overridable.
override SRCDIR := @SRCDIR@
override PACKAGE_VERSION := @PACKAGE_VERSION@
override PACKAGE_TARNAME := @PACKAGE_TARNAME@
override OUTPUT := bin/$(PACKAGE_TARNAME)
override WERROR_FLAG := @WERROR_FLAG@
override DEFAULT_CC := @CC@
$(call USER_VARIABLE,CC,$(DEFAULT_CC))
override DEFAULT_CFLAGS := @CFLAGS@
$(call USER_VARIABLE,CFLAGS,$(DEFAULT_CFLAGS))
override PKGCONF_CFLAGS := @PKGCONF_CFLAGS@
override DEFAULT_CPPFLAGS := @CPPFLAGS@
$(call USER_VARIABLE,CPPFLAGS,$(DEFAULT_CPPFLAGS))
override PKGCONF_CPPFLAGS := @PKGCONF_CPPFLAGS@
override DEFAULT_LDFLAGS := @LDFLAGS@
$(call USER_VARIABLE,LDFLAGS,$(DEFAULT_LDFLAGS))
override DEFAULT_LIBS := @LIBS@
$(call USER_VARIABLE,LIBS,$(DEFAULT_LIBS))
override PKGCONF_LIBS := @PKGCONF_LIBS@
override STRIP := @STRIP@
override MKDIR_P := @MKDIR_P@
override INSTALL := @INSTALL@
override INSTALL_PROGRAM := @INSTALL_PROGRAM@
override prefix := @prefix@
override exec_prefix := @exec_prefix@
override bindir := @bindir@
# Macros to make our build system still work from within paths with spaces
# or other special characters.
override SPACE := $(subst ,, )
override MKESCAPE = $(subst $(SPACE),\ ,$(1))
override SHESCAPE = $(subst ','\'',$(1))
# Internal C flags that should not be changed by the user.
override CFLAGS += \
-Wall \
-Wextra \
$(WERROR_FLAG) \
-std=gnu11 \
$(PKGCONF_CFLAGS)
# Internal C preprocessor flags that should not be changed by the user.
override CPPFLAGS := \
$(PKGCONF_CPPFLAGS) \
-I'$(call SHESCAPE,$(SRCDIR))/src' \
$(CPPFLAGS) \
-MMD \
-MP
# Internal library flags that should not be changed by the user.
override LIBS += \
$(PKGCONF_LIBS)
# Use "find" to glob all *.c files in the tree and obtain the
# object and header dependency file names.
override CFILES := $(shell cd '$(call SHESCAPE,$(SRCDIR))/src' && find -L * -type f -name '*.c' | LC_ALL=C sort)
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o))
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d))
# Default target.
.PHONY: all
all: $(OUTPUT)
# Link rules for the final executable.
$(OUTPUT): GNUmakefile $(OBJ)
$(MKDIR_P) "$$(dirname $@)"
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) $(LIBS) -o $@
# Include header dependencies.
-include $(HEADER_DEPS)
# Compilation rules for *.c files.
obj/%.c.o: $(call MKESCAPE,$(SRCDIR))/src/%.c GNUmakefile
$(MKDIR_P) "$$(dirname $@)"
$(CC) $(CFLAGS) $(CPPFLAGS) -c '$(call SHESCAPE,$<)' -o $@
# Remove object files and the final executable.
.PHONY: clean
clean:
rm -rf bin obj
# Remove files generated by configure.
.PHONY: distclean
distclean: clean
rm -rf config.log config.status GNUmakefile
# Create a release tarball.
.PHONY: dist
dist:
rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"
$(MKDIR_P) "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"
cp -rp '$(call SHESCAPE,$(SRCDIR))'/.git "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"/
cd "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)" && git checkout .
cd "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)" && ./bootstrap
rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"/.git
rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"/.gitignore
rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"/.github
rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"/autom4te.cache
echo "$(PACKAGE_VERSION)" >"$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"/version
tar -cf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar" "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"
gzip < "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar" > "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.gz"
( bzip2 < "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar" > "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2" || rm "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2" )
( xz < "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar" > "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.xz" || rm "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.xz" )
rm "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar"
rm -rf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"
# Remove ALL generated files.
.PHONY: maintainer-clean
maintainer-clean: distclean
cd '$(call SHESCAPE,$(SRCDIR))' && rm -rf configure build-aux *'~' autom4te.cache aclocal.m4
# Install files and executables to the final locations.
.PHONY: install
install: all
$(INSTALL) -d '$(call SHESCAPE,$(DESTDIR)$(bindir))'
$(INSTALL_PROGRAM) $(OUTPUT) '$(call SHESCAPE,$(DESTDIR)$(bindir))/'
# Install and strip executables.
.PHONY: install-strip
install-strip: install
$(STRIP) '$(call SHESCAPE,$(DESTDIR)$(bindir))'/"$$(basename '$(OUTPUT)')"
# Uninstall previously installed files and executables.
.PHONY: uninstall
uninstall:
rm -rf '$(call SHESCAPE,$(DESTDIR)$(bindir))'/"$$(basename '$(OUTPUT)')"