summaryrefslogtreecommitdiff
path: root/Makefile.in
blob: 6080fdfe6c1c8bd7918721589089d303116a816c (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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Makefile.in for building crosstool-NG
# This file serves as source for the ./configure operation

# This series of test is here because GNU make 3.81 will *not* use MAKEFLAGS
# to set additional flags in the current Makfile ( see:
# http://savannah.gnu.org/bugs/?20501 ), although the make manual says it
# should ( see: http://www.gnu.org/software/make/manual/make.html#Options_002fRecursion )
# so we have to work it around by calling ourselves back if needed

# So why do we need not to use the built rules and variables? Because we
# need to generate scripts/crosstool-NG.sh from scripts/crosstool-NG.sh.in
# and there is a built-in implicit rule '%.sh:' that has neither a pre-requisite
# nor a command associated, and that built-in implicit rule takes precedence
# over our non-built-in implicit rule '%: %.in', below.

# CT_MAKEFLAGS will be used later, below...

# Do not print directories as we descend into them
ifeq ($(filter --no-print-directory,$(MAKEFLAGS)),)
CT_MAKEFLAGS += --no-print-directory
endif

# Use neither builtin rules, nor builtin variables
# Note: dual test, because if -R and -r are given on the command line
# (who knows?), MAKEFLAGS contains 'Rr' instead of '-Rr', while adding
# '-Rr' to MAKEFLAGS adds it literaly ( and does not add 'Rr' )
ifeq ($(filter Rr,$(MAKEFLAGS)),)
ifeq ($(filter -Rr,$(MAKEFLAGS)),)
CT_MAKEFLAGS += -Rr
endif # No -Rr
endif # No Rr

# Remove any suffix rules
.SUFFIXES:

all: Makefile build

###############################################################################
# Configuration variables

VERSION:= @@VERSION@@
BINDIR := @@BINDIR@@
LIBDIR := @@LIBDIR@@
DOCDIR := @@DOCDIR@@
MANDIR := @@MANDIR@@
DATE   := @@DATE@@
LOCAL  := @@LOCAL@@

# Paths found by ./configure
install:= @@install@@
bash   := @@bash@@
grep   := @@grep@@
make   := @@make@@
sed    := @@sed@@

###############################################################################
# Sanity checks

# Check if Makefile is up to date:
Makefile: Makefile.in
	@echo "$< did changed: you must re-run './configure'"
	@false

# If installing with DESTDIR, check it's an absolute path
ifneq ($(strip $(DESTDIR)),)
  ifneq ($(DESTDIR),$(abspath /$(DESTDIR)))
    $(error DESTDIR is not an absolute PATH: '$(DESTDIR)')
  endif
endif

###############################################################################
# Global make rules

# If any extra MAKEFLAGS were added, re-run ourselves
# See top of file for an explanation of why this is needed...
ifneq ($(strip $(CT_MAKEFLAGS)),)

MAKEFLAGS += $(CT_MAKEFLAGS)
build install clean distclean uninstall:
	@$(MAKE) $@

else
# There were no additional MAKEFLAGS to add, do the job

TARGETS := bin lib doc man

build: $(patsubst %,build-%,$(TARGETS))

install: build real-install

clean: $(patsubst %,clean-%,$(TARGETS))

distclean: clean
	@echo "  RM     'Makefile'"
	@rm -f Makefile

uninstall: real-uninstall

###############################################################################
# Specific make rules

#--------------------------------------
# Build rules

build-bin: ct-ng scripts/crosstool-NG.sh scripts/saveSample.sh scripts/showTuple.sh
	@chmod 755 $^

build-lib: paths.mk

build-doc:

build-man: docs/ct-ng.1.gz

docs/ct-ng.1.gz: docs/ct-ng.1
	@echo "  GZIP   '$@'"
	@gzip -c9 $< >$@

%: %.in Makefile
	@echo "  SED    '$@'"
	@$(sed) -r -e 's,@@CT_BINDIR@@,$(BINDIR),g;'    \
	           -e 's,@@CT_LIBDIR@@,$(LIBDIR),g;'    \
	           -e 's,@@CT_DOCDIR@@,$(DOCDIR),g;'    \
	           -e 's,@@CT_MANDIR@@,$(MANDIR),g;'    \
	           -e 's,@@CT_VERSION@@,$(VERSION),g;'	\
	           -e 's,@@CT_DATE@@,$(DATE),g;'        \
	           -e 's,@@CT_make@@,$(make),g;'        \
	           -e 's,@@CT_bash@@,$(bash),g;'        \
	           $@.in >$@

# We create a script fragment that is parseable from inside a Makefile,
# but also from inside a shell script, hence the reason why we don't
# use := to set variables, although that will incur a (very small)
# penalty from the Makefile that includes it (due to re-evaluation at
# each call).
paths.mk:
	@echo "  GEN    '$@'"
	@(echo "export install=$(install)"; \
	  echo "export bash=$(bash)";       \
	  echo "export grep=$(grep)";       \
	  echo "export make=$(make)";       \
	  echo "export sed=$(sed)";         \
	 ) >paths.mk

#--------------------------------------
# Clean rules

clean-bin:
	@echo "  RM     'ct-ng'"
	@rm -f ct-ng
	@echo "  RM     'scripts/crosstool-NG.sh'"
	@rm -f scripts/crosstool-NG.sh
	@echo "  RM     'scripts/saveSample.sh'"
	@rm -f scripts/saveSample.sh
	@echo "  RM     'scripts/showTuple.sh'"
	@rm -f scripts/showTuple.sh

clean-lib:
	@echo "  RM     'paths.mk'"
	@rm -f paths.mk

clean-doc:

clean-man:
	@echo "  RM     'docs/ct-ng.1'"
	@rm -f docs/ct-ng.1
	@echo "  RM     'docs/ct-ng.1.gz'"
	@rm -f docs/ct-ng.1.gz

#--------------------------------------
# Check for --local setup

ifeq ($(strip $(LOCAL)),y)

real-install:
	@true

real-uninstall:
	@true

else

#--------------------------------------
# Install rules

real-install: $(patsubst %,install-%,$(TARGETS)) install-post

install-bin: $(DESTDIR)$(BINDIR)
	@echo "  INST   'ct-ng'"
	@$(install) -m 755 ct-ng "$(DESTDIR)$(BINDIR)/ct-ng"

# If one is hacking crosstool-NG, the patch set might change between any two
# installations of the same VERSION, thus the patches must be removed prior
# to being installed. It is simpler to remove the whole lib/ directory, as it
# is the goal of the install-lib rule to install the lib/ directory...
install-lib: uninstall-lib $(DESTDIR)$(LIBDIR) install-lib-main install-lib-samples

install-lib-main: $(DESTDIR)$(LIBDIR)
	@for src_dir in config kconfig patches scripts; do  \
	     echo "  INST   '$${src_dir}/'";                \
	     tar cf - --exclude='*.sh.in' $${src_dir}       \
	     |(cd "$(DESTDIR)$(LIBDIR)"; tar xf -);         \
	 done
	@chmod a+x $(DESTDIR)$(LIBDIR)/scripts/crosstool-NG.sh
	@chmod a+x $(DESTDIR)$(LIBDIR)/scripts/saveSample.sh
	@rm -f "$(DESTDIR)$(LIBDIR)/scripts/addToolVersion.sh"
	@echo "  INST   'steps.mk'"
	@$(install) -m 644 steps.mk "$(DESTDIR)$(LIBDIR)/steps.mk"
	@echo "  INST   'paths.mk'"
	@$(install) -m 644 paths.mk "$(DESTDIR)$(LIBDIR)/paths.mk"

# Samples need a little love:
#  - change every occurrence of CT_TOP_DIR to CT_LIB_DIR
install-lib-samples: $(DESTDIR)$(LIBDIR) install-lib-main
	@echo "  INST   'samples/'"
	@tar cf - samples |(cd "$(DESTDIR)$(LIBDIR)"; tar xf -)
	@for samp_file in "$(DESTDIR)$(LIBDIR)/samples/"*"/crosstool.config"; do                    \
	     $(sed) -r -i -e 's,\$$\{CT_TOP_DIR\},\$$\{CT_LIB_DIR\},g;' $${samp_file};           \
	     $(sed) -r -i -e 's,^(CT_WORK_DIR)=.*,\1="\$${CT_TOP_DIR}/targets",;' $${samp_file}; \
	 done

install-doc: $(DESTDIR)$(DOCDIR)
	@for doc_file in docs/CREDITS docs/overview.txt; do             \
	     echo "  INST   '$${doc_file}'";                            \
	     $(install) -m 644 "$${doc_file}" "$(DESTDIR)$(DOCDIR)"; \
	 done

install-man: $(DESTDIR)$(MANDIR)
	@echo "  INST   'ct-ng.1.gz'"
	@$(install) -m 644 docs/ct-ng.1.gz "$(DESTDIR)$(MANDIR)"

$(sort $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(MANDIR)):
	@echo "  MKDIR  '$@'"
	@$(install) -m 755 -d "$@"

install-post:
	@echo
	@echo "For auto-completion, do not forget to install 'ct-ng.comp'"
	@echo "into you 'bash_completion.d'"

#--------------------------------------
# Uninstall rules

real-uninstall: $(patsubst %,uninstall-%,$(TARGETS))

uninstall-bin:
	@echo "  RM     '$(DESTDIR)$(BINDIR)/ct-ng'"
	@rm -f "$(DESTDIR)$(BINDIR)/ct-ng"

uninstall-lib:
	@echo "  RMDIR  '$(DESTDIR)$(LIBDIR)/'"
	@rm -rf "$(DESTDIR)$(LIBDIR)"

uninstall-doc:
	@echo "  RMDIR  '$(DESTDIR)$(DOCDIR)/'"
	@rm -rf "$(DESTDIR)$(DOCDIR)"

uninstall-man:
	@echo "  RM     '$(DESTDIR)$(MANDIR)/ct-ng.1.gz'"
	@rm -f "$(DESTDIR)$(MANDIR)/ct-ng.1"{,.gz}

endif # Not --local

endif # No extra MAKEFLAGS were added