-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile.in
151 lines (129 loc) · 5.02 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# GNUMakefile.in: gwm's global makefile.
# Copyright (C) 2023 streaksu
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Nuke built-in rules and variables
override MAKEFLAGS += -rR
# Misc autoconf variable imports.
override SRCDIR := @SRCDIR@
override BUILDDIR := @BUILDDIR@
override PACKAGE_VERSION := @PACKAGE_VERSION@
override PACKAGE_TARNAME := @PACKAGE_TARNAME@
override OUTPUT := bin/$(PACKAGE_TARNAME)
override WERROR_FLAG := @WERROR_FLAG@
# Autoconf dir variables.
override prefix := @prefix@
override exec_prefix := @exec_prefix@
override bindir := @bindir@
override sysconfdir := @sysconfdir@
# Macros to make our build system still work from within paths with spaces
# or other special characters.
override SPACE := $(subst ,, )
MKESCAPE = $(subst $(SPACE),\ ,$(1))
SHESCAPE = $(subst ','\'',$(1))
OBJESCAPE = $(subst .a ,.a' ',$(subst .o ,.o' ',$(call SHESCAPE,$(1))))
# File lists.
override CXXFILES := $(shell cd '$(call SHESCAPE,$(SRCDIR))' && find . -type f -name '*.cpp')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/,$(CXXFILES:.cpp=.o))
override HEADER_DEPS := $(CXXFILES:.cpp=.d)
# DEFAULT_VAR definition.
define DEFAULT_VAR =
ifeq ($(origin $1),default)
override $(1) := $(2)
endif
ifeq ($(origin $1),undefined)
override $(1) := $(2)
endif
endef
# Overridable generator executables.
$(eval $(call DEFAULT_VAR,CXX,@CXX@))
# Non-overridable generator executables.
override NATIVE_STRIP := @NATIVE_STRIP@
override MKDIR_P := @MKDIR_P@
override INSTALL := @INSTALL@
override INSTALL_PROGRAM := @INSTALL_PROGRAM@
override INSTALL_DATA := @INSTALL_DATA@
# User command flags.
$(eval $(call DEFAULT_VAR,CXXFLAGS,@CXXFLAGS@))
$(eval $(call DEFAULT_VAR,CPPFLAGS,@CPPFLAGS@))
$(eval $(call DEFAULT_VAR,LDFLAGS,@LDFLAGS@))
$(eval $(call DEFAULT_VAR,LIBS,@LIBS@))
# Needed command flags.
override CXXFLAGS += \
-Wall \
-Wextra \
$(WERROR_FLAG) \
-std=gnu++20
override CPPFLAGS := \
-I'$(call SHESCAPE,$(SRCDIR))/source' \
$(CPPFLAGS) \
-DPACKAGE_VERSION=\"$(PACKAGE_VERSION)\" \
-MMD \
-MP
# Default target.
.PHONY: all
all: $(OUTPUT)
# Link rules for the final executable.
$(OUTPUT): $(OBJ)
$(MKDIR_P) bin
$(CXX) $(CXXFLAGS) $(LDFLAGS) '$(call OBJESCAPE,$^)' $(LIBS) -o $@
# Include header dependencies.
-include $(HEADER_DEPS)
# Compilation rules for *.cpp files.
$(call MKESCAPE,$(BUILDDIR))/%.o: $(call MKESCAPE,$(SRCDIR))/%.cpp
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
# Remove object files and the final executable.
.PHONY: clean
clean:
rm -rf bin $(OBJ) $(HEADER_DEPS)
# 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 -Jcf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)".tar.xz "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"
tar -zcf "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)".tar.gz "$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)"
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
# Install files and executables to the final locations.
.PHONY: install
install: all
$(INSTALL) -d '$(call SHESCAPE,$(DESTDIR)$(bindir))'
$(INSTALL) -d '$(call SHESCAPE,$(DESTDIR)$(sysconfdir))'
$(INSTALL_PROGRAM) $(OUTPUT) '$(call SHESCAPE,$(DESTDIR)$(bindir))/'
$(INSTALL_DATA) '$(call SHESCAPE,$(SRCDIR))/assets'/* '$(call SHESCAPE,$(DESTDIR)$(sysconfdir))/'
# Install and strip executables.
.PHONY: install-strip
install-strip: install
$(NATIVE_STRIP) '$(call SHESCAPE,$(DESTDIR)$(bindir))'/"$$(basename '$(OUTPUT)')"
# Uninstall previously installed files and executables.
.PHONY: uninstall
uninstall:
rm -f '$(call SHESCAPE,$(DESTDIR)$(bindir))'/"$$(basename '$(OUTPUT)')"