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
41 # Stuff found by ./configure
43 LOCAL := @enable_local@
44 PROG_SED := @program_transform_name@
45 PACKAGE_TARNAME := @PACKAGE_TARNAME@
46 VERSION := @PACKAGE_VERSION@
48 exec_prefix := @exec_prefix@
50 libdir := @libdir@@sublibdir@
51 docdir := @docdir@@subdocdir@
52 datarootdir := @datarootdir@
60 libtoolize := @LIBTOOLIZE@
66 # config options to push down to kconfig
67 KCONFIG:= @kconfig_options@
69 ###############################################################################
70 # Non-configure variables
72 MAN_SUBDIR := /man$(MAN_SECTION)
74 PROG_NAME := $(shell echo 'ct-ng' |$(sed) -r -e '$(PROG_SED)' )
76 ###############################################################################
79 # Check if Makefile is up to date:
81 @echo "$< did changed: you must re-run './configure'"
84 # If installing with DESTDIR, check it's an absolute path
85 ifneq ($(strip $(DESTDIR)),)
86 ifneq ($(DESTDIR),$(abspath /$(DESTDIR)))
87 $(error DESTDIR is not an absolute PATH: '$(DESTDIR)')
91 ###############################################################################
94 # If any extra MAKEFLAGS were added, re-run ourselves
95 # See top of file for an explanation of why this is needed...
96 ifneq ($(strip $(CT_MAKEFLAGS)),)
98 # Somehow, the new auto-completion for make in the recent distributions
99 # trigger a behavior where our Makefile calls itself recursively, in a
100 # never-ending loop (except on lack of ressources, swap, PIDs...)
101 # Avoid this situation by cutting the recursion short at the first
103 # This has the side effect of only showing the real targets, and hiding our
105 ifneq ($(MAKELEVEL),0)
106 $(error Recursion detected, bailing out...)
109 MAKEFLAGS += $(CT_MAKEFLAGS)
110 build install clean distclean mrproper uninstall:
114 # There were no additional MAKEFLAGS to add, do the job
116 TARGETS := bin lib doc man
118 build: $(patsubst %,build-%,$(TARGETS))
120 install: build real-install
122 clean: $(patsubst %,clean-%,$(TARGETS))
125 @echo " RM 'Makefile'"
129 @echo " RM 'autostuff'"
130 @ rm -rf autom4te.cache config.log config.status configure
132 uninstall: real-uninstall
134 ###############################################################################
135 # Specific make rules
137 #--------------------------------------
140 build-bin: $(PROG_NAME) scripts/crosstool-NG.sh scripts/saveSample.sh scripts/showTuple.sh
143 build-lib: paths.mk config/configure.in
147 build-man: docs/$(PROG_NAME).1.gz
149 docs/$(PROG_NAME).1.gz: docs/$(PROG_NAME).1
155 @$(sed) -r -e 's,@@CT_BINDIR@@,$(bindir),g;' \
156 -e 's,@@CT_LIBDIR@@,$(libdir),g;' \
157 -e 's,@@CT_DOCDIR@@,$(docdir),g;' \
158 -e 's,@@CT_MANDIR@@,$(mandir),g;' \
159 -e 's,@@CT_PROG_NAME@@,$(PROG_NAME),g;' \
160 -e 's,@@CT_VERSION@@,$(VERSION),g;' \
161 -e 's,@@CT_DATE@@,$(DATE),g;' \
162 -e 's,@@CT_make@@,$(make),g;' \
163 -e 's,@@CT_bash@@,$(bash),g;' \
167 docs/$(PROG_NAME).1: docs/ct-ng.1.in Makefile
170 $(PROG_NAME): ct-ng.in Makefile
176 # We create a script fragment that is parseable from inside a Makefile,
177 # but also from inside a shell script, hence the reason why we don't
178 # use := to set variables, although that will incur a (very small)
179 # penalty from the Makefile that includes it (due to re-evaluation at
183 @(echo "export install=$(install)"; \
184 echo "export bash=$(bash)"; \
185 echo "export grep=$(grep)"; \
186 echo "export make=$(make)"; \
187 echo "export sed=$(sed)"; \
188 echo "export libtool=$(libtool)"; \
189 echo "export libtoolize=$(libtoolize)"; \
190 echo "export objcopy=$(objcopy)"; \
191 echo "export objdump=$(objdump)"; \
192 echo "export readelf=$(readelf)"; \
193 echo "export patch=$(patch)"; \
196 config/configure.in: FORCE
198 @{ printf "# Generated file, do not edit\n"; \
199 printf "# Default values as found by ./configure\n"; \
200 for var in $(KCONFIG); do \
202 printf "config CONFIGURE_$${var%%=*}\n"; \
203 if [ "$${var#*=}" = "y" ]; then \
204 printf " def_bool y\n"; \
213 #--------------------------------------
217 @echo " RM '$(PROG_NAME)'"
219 @echo " RM 'scripts/crosstool-NG.sh'"
220 @rm -f scripts/crosstool-NG.sh
221 @echo " RM 'scripts/saveSample.sh'"
222 @rm -f scripts/saveSample.sh
223 @echo " RM 'scripts/showTuple.sh'"
224 @rm -f scripts/showTuple.sh
227 @echo " RM 'paths.mk'"
229 @echo " RM 'config/configure.in'"
230 @rm -f config/configure.in
235 @echo " RM 'docs/$(PROG_NAME).1'"
236 @rm -f docs/$(PROG_NAME).1
237 @echo " RM 'docs/$(PROG_NAME).1.gz'"
238 @rm -f docs/$(PROG_NAME).1.gz
240 #--------------------------------------
241 # Check for --local setup
243 ifeq ($(strip $(LOCAL)),yes)
253 #--------------------------------------
256 real-install: $(patsubst %,install-%,$(TARGETS)) install-post
258 install-bin: $(DESTDIR)$(bindir)
259 @echo " INST '$(PROG_NAME)'"
260 @$(install) -m 755 $(PROG_NAME) "$(DESTDIR)$(bindir)/$(PROG_NAME)"
262 # If one is hacking crosstool-NG, the patch set might change between any two
263 # installations of the same VERSION, thus the patches must be removed prior
264 # to being installed. It is simpler to remove the whole lib/ directory, as it
265 # is the goal of the install-lib rule to install the lib/ directory...
266 install-lib: uninstall-lib $(DESTDIR)$(libdir) install-lib-main install-lib-samples
268 LIB_SUB_DIR := config contrib kconfig patches scripts
269 $(patsubst %,install-lib-%-copy,$(LIB_SUB_DIR)): $(DESTDIR)$(libdir)
270 @echo " INSTDIR '$(patsubst install-lib-%-copy,%,$(@))/'"
271 @tar cf - --exclude='*.sh.in' $(patsubst install-lib-%-copy,%,$(@)) \
272 |(cd "$(DESTDIR)$(libdir)"; tar xf -)
274 # Huh? It seems we need at least one command to make this rule kick-in.
275 install-lib-%: install-lib-%-copy; @true
277 # Huh? that one does not inherit the -opy dependency, above...
278 install-lib-scripts: install-lib-scripts-copy
279 @chmod a+x $(DESTDIR)$(libdir)/scripts/crosstool-NG.sh
280 @chmod a+x $(DESTDIR)$(libdir)/scripts/saveSample.sh
281 @rm -f "$(DESTDIR)$(libdir)/scripts/addToolVersion.sh"
283 install-lib-main: $(DESTDIR)$(libdir) $(patsubst %,install-lib-%,$(LIB_SUB_DIR))
284 @echo " INST 'steps.mk'"
285 @$(install) -m 644 steps.mk "$(DESTDIR)$(libdir)/steps.mk"
286 @echo " INST 'paths.mk'"
287 @$(install) -m 644 paths.mk "$(DESTDIR)$(libdir)/paths.mk"
289 # Samples need a little love:
290 # - change every occurrence of CT_TOP_DIR to CT_LIB_DIR
291 install-lib-samples: $(DESTDIR)$(libdir) install-lib-main
292 @echo " INSTDIR 'samples/'"
293 @for samp_dir in samples/*/; do \
294 mkdir -p "$(DESTDIR)$(libdir)/$${samp_dir}"; \
295 $(sed) -r -e 's:\$$\{CT_TOP_DIR\}:\$$\{CT_LIB_DIR\}:;' \
296 -e 's:^(CT_WORK_DIR)=.*:\1="\$${CT_TOP_DIR}/.build":;' \
297 $${samp_dir}/crosstool.config \
298 >"$(DESTDIR)$(libdir)/$${samp_dir}/crosstool.config"; \
299 $(install) -m 644 "$${samp_dir}/reported.by" \
300 "$(DESTDIR)$(libdir)/$${samp_dir}"; \
301 for libc_cfg in "$${samp_dir}/"*libc*.config; do \
302 [ -f "$${libc_cfg}" ] || continue; \
303 $(install) -m 644 "$${libc_cfg}" \
304 "$(DESTDIR)$(libdir)/$${samp_dir}"; \
307 @$(install) -m 644 samples/samples.mk "$(DESTDIR)$(libdir)/samples/samples.mk"
309 install-doc: $(DESTDIR)$(docdir)
310 @echo " INST 'docs/*.txt'"
311 @for doc_file in docs/*.txt; do \
312 $(install) -m 644 "$${doc_file}" "$(DESTDIR)$(docdir)"; \
315 install-man: $(DESTDIR)$(mandir)$(MAN_SUBDIR)
316 @echo " INST '$(PROG_NAME).1.gz'"
317 @$(install) -m 644 docs/$(PROG_NAME).1.gz "$(DESTDIR)$(mandir)$(MAN_SUBDIR)"
319 $(sort $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(DESTDIR)$(docdir) $(DESTDIR)$(mandir)$(MAN_SUBDIR)):
321 @$(install) -m 755 -d "$@"
325 @echo "For auto-completion, do not forget to install '$(PROG_NAME).comp' into"
326 @echo "your bash completion directory (usually /etc/bash_completion.d)"
328 #--------------------------------------
331 real-uninstall: $(patsubst %,uninstall-%,$(TARGETS))
334 @echo " RM '$(DESTDIR)$(bindir)/$(PROG_NAME)'"
335 @rm -f "$(DESTDIR)$(bindir)/$(PROG_NAME)"
338 @echo " RMDIR '$(DESTDIR)$(libdir)/'"
339 @rm -rf "$(DESTDIR)$(libdir)"
342 @echo " RMDIR '$(DESTDIR)$(docdir)/'"
343 @rm -rf "$(DESTDIR)$(docdir)"
346 @echo " RM '$(DESTDIR)$(mandir)$(MAN_SUBDIR)/$(PROG_NAME).1.gz'"
347 @rm -f "$(DESTDIR)$(mandir)$(MAN_SUBDIR)/$(PROG_NAME).1"{,.gz}
351 endif # No extra MAKEFLAGS were added
353 .PHONY: build $(patsubst %,build-%,$(TARGETS)) install