-
Notifications
You must be signed in to change notification settings - Fork 3
/
rules.mk
217 lines (175 loc) · 5.55 KB
/
rules.mk
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#
# Common Makefile definitions
#
PWD = $(shell echo `pwd`)
INSTALL = /usr/bin/install
DOXYGEN = `which doxygen`
# Name of the rpm spec file
SPECFILENAME = ppc64-diag.spec
# resolves the root directory at which this build is occurring
ROOT_DIR = \
$(shell \
while [ `pwd` != "/" ]; \
do \
if [ -f `pwd`/$(SPECFILENAME) ]; \
then \
echo `pwd`; \
break; \
fi; \
cd ..; \
done;)
# Full path to the rpm specfile
SPECFILE = $(ROOT_DIR)/$(SPECFILENAME)
# Find the correct command to build RPM's
RPM = \
$(shell \
if [ -a /bin/rpmbuild ]; then \
echo "/bin/rpmbuild"; \
elif [ -a /usr/bin/rpmbuild ]; then \
echo "/usr/bin/rpmbuild"; \
elif [ -a /bin/rpm ]; then \
echo "/bin/rpm"; \
elif [ -a /usr/bin/rpm ]; then \
echo "/usr/bin/rpmbuild"; \
else \
echo "rpm seems to be non-existant"; \
fi;)
# Pull the version, release and project name info from the spec file
VERSION := $(shell echo `grep "Version:" $(SPECFILE) | cut -f2`)
RELEASE := $(shell echo `grep "Release:" $(SPECFILE) | cut -f2`)
PROJECT := $(shell echo `grep "Name:" $(SPECFILE) | cut -f2`)
# Generate the Major, Minor and Revision numbers from the version
VERSION_LIST := $(subst ., ,$(VERSION))
MAJOR_NO := $(word 1,$(VERSION_LIST))
MINOR_NO := $(word 2,$(VERSION_LIST))
REVISION_NO := $(word 3,$(VERSION_LIST))
# Set this if you want to install to a base directory other than /
DESTDIR ?=
# Standard base directory names
BIN_DIR = /usr/bin
SBIN_DIR = /usr/sbin
LIB_DIR = /usr/lib
INC_DIR = /usr/include
DOC_DIR = /usr/share/doc/packages/$(PROJECT)
MAN_DIR = /usr/share/man/man8
SYSTEMD_DIR = /usr/lib/systemd/system
LIBEXEC_DIR = /usr/libexec/$(PROJECT)
# Shipdir is where we put all the files to build an rpm
SHIPDIR = /tmp/$(PROJECT)-buildroot
# Source tarball name and build directory
TARBALL = $(PROJECT)-$(VERSION).tar.gz
TARBALL_FILES = Makefile rules.mk COPYING $(SPECFILENAME)
TB_DIR = $(PROJECT)-$(VERSION)
COMMON_DIR = $(ROOT_DIR)/common
# Build a tarball of the source code
BUILD_TARBALL = \
$(shell \
echo CVS > ./ignore; \
mkdir $(TB_DIR); \
cp -R $(COMMON_DIR) $(TB_DIR); \
cp -R $(SUBDIRS) $(TARBALL_FILES) $(TB_DIR); \
tar -zcf $(TARBALL) -X ./ignore $(TB_DIR);)
# Current build directory
WORK_DIR = $(patsubst /%,%,$(subst $(ROOT_DIR),,$(PWD)))
# You should always build with -Wall
CFLAGS += -Wall
# Uncomment this for debug builds
CFLAGS += -g -DDEBUG
# Build with common directory included
CFLAGS += -I$(COMMON_DIR)
# Include ncurses directory
CFLAGS += -I $(INC_DIR)/ncurses
# Build with version string
AM_CFLAGS = -DVERSION='"$(VERSION)"'
# You should always build with -Wall
CXXFLAGS += -Wall
# Uncomment this for debug builds
CXXFLAGS += -g -DDEBUG
# Build with common directory included
CXXFLAGS += -I$(COMMON_DIR)
# Build with version string
AM_CXXFLAGS = -DVERSION='"$(VERSION)"'
# If you wish to have a log of installed files, define the file here
INSTALL_LOG ?= $(ROOT_DIR)/install.log
#
# install_files - Install file(s) in the given location
#
# $1 - files to be installed
# $2 - permissions to install file with
# $3 - directory to install file to
define install_files
$(INSTALL) -d -m 755 $3;
$(foreach f,$1, \
echo "Installing $(patsubst /%,%,$(WORK_DIR)/$f)"; \
$(INSTALL) -m $2 $f $3; \
$(if $(INSTALL_LOG),echo $3/$f >> $(INSTALL_LOG);,))
endef
#
# The following are wrappers for calls to install_files for
# installing files in known locations (i.e. /usr/bin). The args
# to each of the wrappers are the same.
#
# $1 - files to be installed
# $2 - prefix to install path for the files
#
define install_bin
$(call install_files,$1,755,$2/$(BIN_DIR))
endef
define install_sbin
$(call install_files,$1,744,$2/$(SBIN_DIR))
endef
define install_lib
$(call install_files,$1,755,$2/$(LIB_DIR))
endef
define install_inc
$(call install_files,$1,644,$2/$(INC_DIR))
endef
define install_doc
$(call install_files,$1,644,$2/$(DOC_DIR))
endef
define install_man
$(call install_files,$1,644,$2/$(MAN_DIR))
endef
#
# uninstall_files - Uninstall file(s)
#
# $1 - files to be uninstalled
# $2 - the directory the files to uninstall live in
define uninstall_files
$(foreach f,$1, \
echo "Un-installing $(patsubst /%,%,$(WORK_DIR)/$f)"; \
rm -f $2/$f;)
endef
#
# The following are wrappers for calls to uninstall_files for
# removing files in known locations (i.e. /usr/bin). The args
# to each of the wrappers are the same.
#
# $1 - files to be uninstalled
# $2 - prefix to uninstall path for the files
#
define uninstall_bin
$(call uninstall_files,$1,$2/$(BIN_DIR))
endef
define uninstall_sbin
$(call uninstall_files,$1,$2/$(SBIN_DIR))
endef
define uninstall_lib
$(call uninstall_files,$1,$2/$(LIB_DIR))
endef
define uninstall_inc
$(call uninstall_files,$1,$2/$(INC_DIR))
endef
define uninstall_doc
$(call uninstall_files,$1,$2/$(DOC_DIR))
endef
define uninstall_man
$(call uninstall_files,$1,$2/$(MAN_DIR))
endef
# Define "CLEAN" as rm plus any files defined in this file that
# the actual Makefile may not (or have to) know about
CLEAN = @echo ""
# Default target for building object files
%.o: %.c
@echo "CC $(WORK_DIR)/$@"
@$(CC) -c $(AM_CFLAGS) $(CFLAGS) $(CPPFLAGS) $<