summaryrefslogtreecommitdiff
path: root/Makefile
blob: c75af67bb4c1725ea9cd33d54060d58ac9fe3e4a (plain)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# Hey Emacs this is a -*- makefile-*-
include Makefile.conf
VERSION=1.101
DATE=15 February 2005
PACKAGE=kexec-tools

pkgdatadir = $(datadir)/$(PACKAGE)
pkglibdir = $(libdir)/$(PACKAGE)
pkgincludedir = $(includedir)/$(PACKAGE)

# You can specify DESTDIR on the command line to do a add
# a prefix to the install so it doesn't really happen
# Useful for building binary packages
DESTDIR =

CPPFLAGS:= -I./include -I./util_lib/include \
	-DVERSION='"$(VERSION)"' -DRELEASE_DATE='"$(DATE)"' \
	$(DEFS) $(EXTRA_CFLAGS)

PREFIX:=$(OBJDIR)/build
SBINDIR=$(PREFIX)/sbin
BINDIR=$(PREFIX)/bin
LIBEXECDIR=$(PREFIX)/libexec
DATADIR=$(PREFIX)/share
SYSCONFDIR=$(PREFIX)/etc
SHAREDSTATEDIR=$(PREFIX)/com
LOCALSTATEDIR=$(PREFIX)/var
LIBDIR=$(PREFIX)/lib
INFODIR=$(PREFIX)/info
MANDIR=$(PREFIX)/man
MAN1DIR=$(MANDIR)/man1
MAN2DIR=$(MANDIR)/man2
MAN3DIR=$(MANDIR)/man3
MAN4DIR=$(MANDIR)/man4
MAN5DIR=$(MANDIR)/man5
MAN6DIR=$(MANDIR)/man6
MAN7DIR=$(MANDIR)/man7
MAN8DIR=$(MANDIR)/man8
INCLUDEDIR=$(PREFIX)/include

PKGDATADIR=$(DATADIR)/$(PACKAGE)
PKGLIBDIR=$(LIBDIR)/$(PACKAGE)
PKGINCLUDEIR=$(INCLUDEDIR)/$(PACKAGE)

MAN_PAGES:= kexec/kexec.8
BINARIES_i386:=  $(SBINDIR)/kexec $(PKGLIBDIR)/kexec_test
BINARIES_x86_64:=$(SBINDIR)/kexec $(PKGLIBDIR)/kexec_test
BINARIES:=$(SBINDIR)/kexec $(SBINDIR)/kdump $(BINARIES_$(ARCH)) 

TARGETS:=$(BINARIES) $(MAN_PAGES)

all: $(TARGETS)

# cc-option
# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
             > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)

# Utility function library
#
include util_lib/Makefile

#
# Stand alone utilities
#
include util/Makefile

#
# purgatory (code between kernels)
#
include purgatory/Makefile

#
# kexec (linux booting linux)
#
include kexec/Makefile


# kdump (read a crashdump from memory)
#
include kdump/Makefile

#
# kexec_test (test program)
#
ifeq ($(ARCH),i386)
include kexec_test/Makefile
endif
ifeq ($(ARCH),x86_64)
include kexec_test/Makefile
endif

GENERATED_SRCS:= ./configure
SPEC=$(OBJDIR)/$(PACKAGE)-$(VERSION).spec
TARBALL=$(OBJDIR)/$(PACKAGE)-$(VERSION).tar.gz
SRCS:=$(shell $(FIND) \
	./AUTHORS ./COPYING ./News ./TODO \
	./Makefile ./Makefile.conf.in ./configure.ac \
	./kexec-tools.spec.in ./config ./doc \
	./include ./kexec ./purgatory ./kexec_test ./kdump ./util ./util_lib \
	! -path '*CVS*' ! -name '*~' ! -name '.*' \
	-type f -print )
SRCS+=$(GENERATED_SRCS)
PSRCS:=$(patsubst ./%,$(PACKAGE)-$(VERSION)/%,$(SRCS))
PSRCS+=$(PACKAGE)-$(VERSION).spec

Makefile.conf: Makefile.conf.in configure
	/bin/sh ./configure

configure: configure.ac
	autoconf
	$(RM) -rf autom4te.cache

tarball: $(TARBALL)

$(TARBALL): $(SRCS) $(SPEC)
	$(MKDIR) -p $(OBJDIR)
	$(RM) -f $(OBJDIR)/$(PACKAGE)-$(VERSION)
	$(LN) -s .. $(OBJDIR)/$(PACKAGE)-$(VERSION)
	(cd $(OBJDIR); $(TAR) -cf - $(PSRCS) | gzip -9) > $@

rpm: $(TARBALL)
	$(MKDIR) -p $(OBJDIR)/RPM $(OBJDIR)/SRPM $(OBJDIR)/BUILD $(OBJDIR)/SPECS \
		$(OBJDIR)/TMP $(OBJDIR)/SOURCES
	unset MAKEFLAGS MAKELEVEL; \
	$(RPMBUILD) -ta \
		--define '_rpmdir $(OBJDIR)/RPM' \
		--define '_srcrpmdir $(OBJDIR)/SRPM' \
		--define '_builddir $(OBJDIR)/BUILD' \
		--define '_specdir $(OBJDIR)/SPECS' \
		--define '_tmppath $(OBJDIR)/TMP' \
		--define '_sourcedir $(OBJDIR)/SOURCES' \
		$(TARBALL)

$(SPEC): kexec-tools.spec.in Makefile
	$(SED) -e 's,^Version: $$,Version: $(VERSION),' $< > $@

echo::
	@echo ARCH=$(ARCH)
	@echo BINARIES=$(BINARIES)
	@echo TARGETS=$(TARGETS)
	@echo CC=$(CC)
	@echo AR=$(AR)
	@echo LD=$(LD)

clean:
	@$(FIND) $(OBJDIR) ! -name '*.d' -type f | $(XARGS) $(RM) rm -f
	@$(RM) -rf rpm
	@$(RM) -f config.log config.status config.cache
	@$(RM) -f $(TARBALL)

dist-clean: clean
	@$(RM) -rf $(OBJDIR)
	@$(FIND) . -type f -name '*~' -o -name '*.orig' | $(XARGS) $(RM) -f
	@$(RM) -f Makefile.conf

maintainer-clean: dist-clean
	@$(RM) -f $(GENERATED_SRCS)


install: $(TARGETS)
	for file in $(TARGETS) ; do \
		if test `$(DIRNAME) $$file` =     "$(SBINDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(sbindir)/; \
			$(INSTALL) -m 555  $$file $(DESTDIR)/$(sbindir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(BINDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(bindir)/; \
			$(INSTALL) -m 555 $$file $(DESTDIR)/$(bindir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(LIBEXECDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(libexecdir)/; \
			$(INSTALL) -m 555 $$file $(DESTDIR)/$(libexecdir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(DATADIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(datadir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(datadir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(SYSCONFDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(sysconfdir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(sysconfdir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(SHAREDSTATEDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(sharedstatedir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(sharedstatedir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(LOCALSTATEDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(localstatedir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(localstatedir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(LIBDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(libdir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(libdir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(INFODIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(infodir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(infodir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(MAN1DIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(mandir)/man1; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(mandir)/man1; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(MAN2DIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(mandir)/man2; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(mandir)/man2; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(MAN3DIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(mandir)/man3/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(mandir)/man3/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(MAN4DIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(mandir)/man4/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(mandir)/man4/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(MAN5DIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(mandir)/man5/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(mandir)/man5/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(MAN6DIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(mandir)/man6/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(mandir)/man6/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(MAN7DIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(mandir)/man7/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(mandir)/man7/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(MAN8DIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(mandir)/man8/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(mandir)/man8/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(INCLUDEDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(includedir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(includedir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(PKGDATADIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(pkgdatadir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(pkgdatadir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(PKGLIBDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(pkglibdir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(pkglibdir)/; \
		fi; \
		if test `$(DIRNAME) $$file` =     "$(PKGINCLUDEDIR)" ; then \
			$(MKDIR) -p     $(DESTDIR)/$(pkgincludedir)/; \
			$(INSTALL) -m 444 $$file $(DESTDIR)/$(pkgincludedir)/; \
		fi; \
	done

.PHONY: echo install all clean dist-clean maintainer-clean tarball rpm