1 # Makefile.in for building crosstool-NG
2 # This file serves as source for the ./configure operation
4 # This series of test is here because GNU make 3.81 will *not* use MAKEFLAGS
5 # to set additional flags in the current Makfile ( see:
6 # http://savannah.gnu.org/bugs/?20501 ), although the make manual says it
7 # should ( see: http://www.gnu.org/software/make/manual/make.html#Options_002fRecursion )
8 # so we have to work it around by calling ourselves back if needed
10 # So why do we need not to use the built rules and variables? Because we
11 # need to generate scripts/crosstool-NG.sh from scripts/crosstool-NG.sh.in
12 # and there is a built-in implicit rule '%.sh:' that has neither a pre-requisite
13 # nor a command associated, and that built-in implicit rule takes precedence
14 # over our non-built-in implicit rule '%: %.in', below.
16 # CT_MAKEFLAGS will be used later, below...
18 # Do not print directories as we descend into them
19 ifeq ($(filter --no-print-directory,$(MAKEFLAGS)),)
20 CT_MAKEFLAGS += --no-print-directory
23 # Use neither builtin rules, nor builtin variables
24 # Note: dual test, because if -R and -r are given on the command line
25 # (who knows?), MAKEFLAGS contains 'Rr' instead of '-Rr', while adding
26 # '-Rr' to MAKEFLAGS adds it literaly ( and does not add 'Rr' )
27 ifeq ($(filter Rr,$(MAKEFLAGS)),)
28 ifeq ($(filter -Rr,$(MAKEFLAGS)),)
33 # Remove any suffix rules
38 ###############################################################################
39 # Configuration variables
49 # Paths found by ./configure
61 # config options to push down to kconfig
64 ###############################################################################
65 # Non-configure variables
67 MAN_SUBDIR := /man$(MAN_SECTION)
69 ###############################################################################
72 # Check if Makefile is up to date:
74 @echo "$< did changed: you must re-run './configure'"
77 # If installing with DESTDIR, check it's an absolute path
78 ifneq ($(strip $(DESTDIR)),)
79 ifneq ($(DESTDIR),$(abspath /$(DESTDIR)))
80 $(error DESTDIR is not an absolute PATH: '$(DESTDIR)')
84 ###############################################################################
87 # If any extra MAKEFLAGS were added, re-run ourselves
88 # See top of file for an explanation of why this is needed...
89 ifneq ($(strip $(CT_MAKEFLAGS)),)
91 # Somehow, the new auto-completion for make in the recent distributions
92 # trigger a behavior where our Makefile calls itself recursively, in a
93 # never-ending loop (except on lack of ressources, swap, PIDs...)
94 # Avoid this situation by cutting the recursion short at the first
96 # This has the side effect of only showing the real targets, and hiding our
98 ifneq ($(MAKELEVEL),0)
99 $(error Recursion detected, bailing out...)
102 MAKEFLAGS += $(CT_MAKEFLAGS)
103 build install clean distclean uninstall:
107 # There were no additional MAKEFLAGS to add, do the job
109 TARGETS := bin lib doc man
111 build: $(patsubst %,build-%,$(TARGETS))
113 install: build real-install
115 clean: $(patsubst %,clean-%,$(TARGETS))
118 @echo " RM 'Makefile'"
121 uninstall: real-uninstall
123 ###############################################################################
124 # Specific make rules
126 #--------------------------------------
129 build-bin: ct-ng scripts/crosstool-NG.sh scripts/saveSample.sh scripts/showTuple.sh
132 build-lib: paths.mk config/configure.in
136 build-man: docs/ct-ng.1.gz
138 docs/ct-ng.1.gz: docs/ct-ng.1
144 @$(sed) -r -e 's,@@CT_BINDIR@@,$(BINDIR),g;' \
145 -e 's,@@CT_LIBDIR@@,$(LIBDIR),g;' \
146 -e 's,@@CT_DOCDIR@@,$(DOCDIR),g;' \
147 -e 's,@@CT_MANDIR@@,$(MANDIR),g;' \
148 -e 's,@@CT_VERSION@@,$(VERSION),g;' \
149 -e 's,@@CT_DATE@@,$(DATE),g;' \
150 -e 's,@@CT_make@@,$(make),g;' \
151 -e 's,@@CT_bash@@,$(bash),g;' \
154 # We create a script fragment that is parseable from inside a Makefile,
155 # but also from inside a shell script, hence the reason why we don't
156 # use := to set variables, although that will incur a (very small)
157 # penalty from the Makefile that includes it (due to re-evaluation at
161 @(echo "export install=$(install)"; \
162 echo "export bash=$(bash)"; \
163 echo "export grep=$(grep)"; \
164 echo "export make=$(make)"; \
165 echo "export sed=$(sed)"; \
166 echo "export libtool=$(libtool)"; \
167 echo "export objcopy=$(objcopy)"; \
168 echo "export objdump=$(objdump)"; \
169 echo "export readelf=$(readelf)"; \
170 echo "export patch=$(patch)"; \
173 config/configure.in: FORCE
175 @{ printf "# Generated file, do not edit\n"; \
176 printf "# Default values as found by ./configure\n"; \
177 for var in $(KCONFIG); do \
179 printf "config CONFIGURE_$${var%%=*}\n"; \
181 if [ "$${var#*=}" = "y" ]; then \
182 printf " default y\n"; \
189 #--------------------------------------
195 @echo " RM 'scripts/crosstool-NG.sh'"
196 @rm -f scripts/crosstool-NG.sh
197 @echo " RM 'scripts/saveSample.sh'"
198 @rm -f scripts/saveSample.sh
199 @echo " RM 'scripts/showTuple.sh'"
200 @rm -f scripts/showTuple.sh
203 @echo " RM 'paths.mk'"
205 @echo " RM 'config/configure.in'"
206 @rm -f config/configure.in
211 @echo " RM 'docs/ct-ng.1'"
213 @echo " RM 'docs/ct-ng.1.gz'"
214 @rm -f docs/ct-ng.1.gz
216 #--------------------------------------
217 # Check for --local setup
219 ifeq ($(strip $(LOCAL)),y)
229 #--------------------------------------
232 real-install: $(patsubst %,install-%,$(TARGETS)) install-post
234 install-bin: $(DESTDIR)$(BINDIR)
235 @echo " INST 'ct-ng'"
236 @$(install) -m 755 ct-ng "$(DESTDIR)$(BINDIR)/ct-ng"
238 # If one is hacking crosstool-NG, the patch set might change between any two
239 # installations of the same VERSION, thus the patches must be removed prior
240 # to being installed. It is simpler to remove the whole lib/ directory, as it
241 # is the goal of the install-lib rule to install the lib/ directory...
242 install-lib: uninstall-lib $(DESTDIR)$(LIBDIR) install-lib-main install-lib-samples
244 LIB_SUB_DIR := config contrib kconfig patches scripts
245 $(patsubst %,install-lib-%-copy,$(LIB_SUB_DIR)): $(DESTDIR)$(LIBDIR)
246 @echo " INSTDIR '$(patsubst install-lib-%-copy,%,$(@))/'"
247 @tar cf - --exclude='*.sh.in' $(patsubst install-lib-%-copy,%,$(@)) \
248 |(cd "$(DESTDIR)$(LIBDIR)"; tar xf -)
250 # Huh? It seems we need at least one command to make this rule kick-in.
251 install-lib-%: install-lib-%-copy; @true
253 # Huh? that one does not inherit the -opy dependency, above...
254 install-lib-scripts: install-lib-scripts-copy
255 @chmod a+x $(DESTDIR)$(LIBDIR)/scripts/crosstool-NG.sh
256 @chmod a+x $(DESTDIR)$(LIBDIR)/scripts/saveSample.sh
257 @rm -f "$(DESTDIR)$(LIBDIR)/scripts/addToolVersion.sh"
259 install-lib-main: $(DESTDIR)$(LIBDIR) $(patsubst %,install-lib-%,$(LIB_SUB_DIR))
260 @echo " INST 'steps.mk'"
261 @$(install) -m 644 steps.mk "$(DESTDIR)$(LIBDIR)/steps.mk"
262 @echo " INST 'paths.mk'"
263 @$(install) -m 644 paths.mk "$(DESTDIR)$(LIBDIR)/paths.mk"
265 # Samples need a little love:
266 # - change every occurrence of CT_TOP_DIR to CT_LIB_DIR
267 install-lib-samples: $(DESTDIR)$(LIBDIR) install-lib-main
268 @echo " INSTDIR 'samples/'"
269 @for samp_file in samples/*/crosstool.config; do \
270 mkdir -p "$(DESTDIR)$(LIBDIR)/$${samp_file%/*}"; \
271 $(sed) -r -e 's:\$$\{CT_TOP_DIR\}:\$$\{CT_LIB_DIR\}:;' \
272 -e 's:^(CT_WORK_DIR)=.*:\1="\$${CT_TOP_DIR}/.build":;' \
274 >"$(DESTDIR)$(LIBDIR)/$${samp_file}"; \
276 @$(install) -m 644 samples/samples.mk "$(DESTDIR)$(LIBDIR)/samples/samples.mk"
278 install-doc: $(DESTDIR)$(DOCDIR)
279 @echo " INST 'docs/*.txt'"
280 @for doc_file in docs/*.txt; do \
281 $(install) -m 644 "$${doc_file}" "$(DESTDIR)$(DOCDIR)"; \
284 install-man: $(DESTDIR)$(MANDIR)$(MAN_SUBDIR)
285 @echo " INST 'ct-ng.1.gz'"
286 @$(install) -m 644 docs/ct-ng.1.gz "$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)"
288 $(sort $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(MANDIR)$(MAN_SUBDIR)):
290 @$(install) -m 755 -d "$@"
294 @echo "For auto-completion, do not forget to install 'ct-ng.comp' into"
295 @echo "your bash completion directory (usually /etc/bash_completion.d)"
297 #--------------------------------------
300 real-uninstall: $(patsubst %,uninstall-%,$(TARGETS))
303 @echo " RM '$(DESTDIR)$(BINDIR)/ct-ng'"
304 @rm -f "$(DESTDIR)$(BINDIR)/ct-ng"
307 @echo " RMDIR '$(DESTDIR)$(LIBDIR)/'"
308 @rm -rf "$(DESTDIR)$(LIBDIR)"
311 @echo " RMDIR '$(DESTDIR)$(DOCDIR)/'"
312 @rm -rf "$(DESTDIR)$(DOCDIR)"
315 @echo " RM '$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)/ct-ng.1.gz'"
316 @rm -f "$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)/ct-ng.1"{,.gz}
320 endif # No extra MAKEFLAGS were added