Makefile.in
author Titus von Boxberg <titus@v9g.de>
Mon Aug 22 09:41:35 2011 +0200 (2011-08-22)
changeset 2625 b1be254591e7
parent 2622 bc9f7c29311e
child 2626 c7c9e98d36d8
permissions -rw-r--r--
configure: fix --with-prog=[...]

check_for didn't set variable 'where' when the path to a prog
was passed manually "(cached)".

Signed-off-by: "Titus von Boxberg" <titus@v9g.de>
     1 # Makefile.in for building crosstool-NG
     2 # This file serves as source for the ./configure operation
     3 
     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
     9 
    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.
    15 
    16 # CT_MAKEFLAGS will be used later, below...
    17 
    18 # Do not print directories as we descend into them
    19 ifeq ($(filter --no-print-directory,$(MAKEFLAGS)),)
    20 CT_MAKEFLAGS += --no-print-directory
    21 endif
    22 
    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)),)
    29 CT_MAKEFLAGS += -Rr
    30 endif # No -Rr
    31 endif # No Rr
    32 
    33 # Remove any suffix rules
    34 .SUFFIXES:
    35 
    36 all: Makefile build
    37 
    38 ###############################################################################
    39 # Configuration variables
    40 
    41 VERSION:= @@VERSION@@
    42 BINDIR := @@BINDIR@@
    43 LIBDIR := @@LIBDIR@@
    44 DOCDIR := @@DOCDIR@@
    45 MANDIR := @@MANDIR@@
    46 PROG_PFX:=@@PROG_PFX@@
    47 PROG_SFX:=@@PROG_SFX@@
    48 PROG_SED:=@@PROG_SED@@
    49 DATE   := @@DATE@@
    50 LOCAL  := @@LOCAL@@
    51 
    52 # Paths found by ./configure
    53 install:= @@install@@
    54 bash   := @@bash@@
    55 grep   := @@grep@@
    56 make   := @@make@@
    57 sed    := @@sed@@
    58 libtool:= @@libtool@@
    59 objcopy:= @@objcopy@@
    60 objdump:= @@objdump@@
    61 readelf:= @@readelf@@
    62 patch  := @@patch@@
    63 
    64 # config options to push down to kconfig
    65 KCONFIG:= @@KCONFIG@@
    66 
    67 ###############################################################################
    68 # Non-configure variables
    69 MAN_SECTION := 1
    70 MAN_SUBDIR := /man$(MAN_SECTION)
    71 
    72 PROG_NAME := $(shell echo '$(PROG_PFX)ct-ng$(PROG_SFX)' |sed -e '$(PROG_SED)' )
    73 
    74 ###############################################################################
    75 # Sanity checks
    76 
    77 # Check if Makefile is up to date:
    78 Makefile: Makefile.in
    79 	@echo "$< did changed: you must re-run './configure'"
    80 	@false
    81 
    82 # If installing with DESTDIR, check it's an absolute path
    83 ifneq ($(strip $(DESTDIR)),)
    84   ifneq ($(DESTDIR),$(abspath /$(DESTDIR)))
    85     $(error DESTDIR is not an absolute PATH: '$(DESTDIR)')
    86   endif
    87 endif
    88 
    89 ###############################################################################
    90 # Global make rules
    91 
    92 # If any extra MAKEFLAGS were added, re-run ourselves
    93 # See top of file for an explanation of why this is needed...
    94 ifneq ($(strip $(CT_MAKEFLAGS)),)
    95 
    96 # Somehow, the new auto-completion for make in the recent distributions
    97 # trigger a behavior where our Makefile calls itself recursively, in a
    98 # never-ending loop (except on lack of ressources, swap, PIDs...)
    99 # Avoid this situation by cutting the recursion short at the first
   100 # level.
   101 # This has the side effect of only showing the real targets, and hiding our
   102 # internal ones. :-)
   103 ifneq ($(MAKELEVEL),0)
   104 $(error Recursion detected, bailing out...)
   105 endif
   106 
   107 MAKEFLAGS += $(CT_MAKEFLAGS)
   108 build install clean distclean uninstall:
   109 	@$(MAKE) $@
   110 
   111 else
   112 # There were no additional MAKEFLAGS to add, do the job
   113 
   114 TARGETS := bin lib doc man
   115 
   116 build: $(patsubst %,build-%,$(TARGETS))
   117 
   118 install: build real-install
   119 
   120 clean: $(patsubst %,clean-%,$(TARGETS))
   121 
   122 distclean: clean
   123 	@echo "  RM     'Makefile'"
   124 	@rm -f Makefile
   125 
   126 uninstall: real-uninstall
   127 
   128 ###############################################################################
   129 # Specific make rules
   130 
   131 #--------------------------------------
   132 # Build rules
   133 
   134 build-bin: $(PROG_NAME) scripts/crosstool-NG.sh scripts/saveSample.sh scripts/showTuple.sh
   135 	@chmod 755 $^
   136 
   137 build-lib: paths.mk config/configure.in
   138 
   139 build-doc:
   140 
   141 build-man: docs/$(PROG_NAME).1.gz
   142 
   143 docs/$(PROG_NAME).1.gz: docs/$(PROG_NAME).1
   144 	@echo "  GZIP   '$@'"
   145 	@gzip -c9 $< >$@
   146 
   147 define sed_it
   148 	@echo "  SED    '$@'"
   149 	@$(sed) -r -e 's,@@CT_BINDIR@@,$(BINDIR),g;'        \
   150 	           -e 's,@@CT_LIBDIR@@,$(LIBDIR),g;'        \
   151 	           -e 's,@@CT_DOCDIR@@,$(DOCDIR),g;'        \
   152 	           -e 's,@@CT_MANDIR@@,$(MANDIR),g;'        \
   153 	           -e 's,@@CT_PROG_PFX@@,$(PROG_PFX),g;'    \
   154 	           -e 's,@@CT_PROG_SFX@@,$(PROG_SFX),g;'    \
   155 	           -e 's,@@CT_PROG_SED@@,$(PROG_SED),g;'    \
   156 	           -e 's,@@CT_PROG_NAME@@,$(PROG_NAME),g;'  \
   157 	           -e 's,@@CT_VERSION@@,$(VERSION),g;'	    \
   158 	           -e 's,@@CT_DATE@@,$(DATE),g;'            \
   159 	           -e 's,@@CT_make@@,$(make),g;'            \
   160 	           -e 's,@@CT_bash@@,$(bash),g;'            \
   161 	           $< >$@
   162 endef
   163 
   164 docs/$(PROG_NAME).1: docs/ct-ng.1.in Makefile
   165 	$(call sed_it)
   166 
   167 $(PROG_NAME): ct-ng.in Makefile
   168 	$(call sed_it)
   169 
   170 %: %.in Makefile
   171 	$(call sed_it)
   172 
   173 # We create a script fragment that is parseable from inside a Makefile,
   174 # but also from inside a shell script, hence the reason why we don't
   175 # use := to set variables, although that will incur a (very small)
   176 # penalty from the Makefile that includes it (due to re-evaluation at
   177 # each call).
   178 paths.mk: FORCE
   179 	@echo "  GEN    '$@'"
   180 	@(echo "export install=$(install)"; \
   181 	  echo "export bash=$(bash)";       \
   182 	  echo "export grep=$(grep)";       \
   183 	  echo "export make=$(make)";       \
   184 	  echo "export sed=$(sed)";         \
   185 	  echo "export libtool=$(libtool)"; \
   186 	  echo "export objcopy=$(objcopy)"; \
   187 	  echo "export objdump=$(objdump)"; \
   188 	  echo "export readelf=$(readelf)"; \
   189 	  echo "export patch=$(patch)";     \
   190 	 ) >paths.mk
   191 
   192 config/configure.in: FORCE
   193 	@echo "  GEN    '$@'"
   194 	@{  printf "# Generated file, do not edit\n";            \
   195 	    printf "# Default values as found by ./configure\n"; \
   196 	    for var in $(KCONFIG); do                            \
   197 	        printf "\n";                                     \
   198 	        printf "config CONFIGURE_$${var%%=*}\n";         \
   199 	        printf "    bool\n";                             \
   200 	        if [ "$${var#*=}" = "y" ]; then                  \
   201 	            printf "    default y\n";                    \
   202 	        fi;                                              \
   203 	    done;                                                \
   204 	 } >$@
   205 
   206 FORCE:
   207 
   208 #--------------------------------------
   209 # Clean rules
   210 
   211 clean-bin:
   212 	@echo "  RM     '$(PROG_NAME)'"
   213 	@rm -f $(PROG_NAME)
   214 	@echo "  RM     'scripts/crosstool-NG.sh'"
   215 	@rm -f scripts/crosstool-NG.sh
   216 	@echo "  RM     'scripts/saveSample.sh'"
   217 	@rm -f scripts/saveSample.sh
   218 	@echo "  RM     'scripts/showTuple.sh'"
   219 	@rm -f scripts/showTuple.sh
   220 
   221 clean-lib:
   222 	@echo "  RM     'paths.mk'"
   223 	@rm -f paths.mk
   224 	@echo "  RM     'config/configure.in'"
   225 	@rm -f config/configure.in
   226 
   227 clean-doc:
   228 
   229 clean-man:
   230 	@echo "  RM     'docs/$(PROG_NAME).1'"
   231 	@rm -f docs/$(PROG_NAME).1
   232 	@echo "  RM     'docs/$(PROG_NAME).1.gz'"
   233 	@rm -f docs/$(PROG_NAME).1.gz
   234 
   235 #--------------------------------------
   236 # Check for --local setup
   237 
   238 ifeq ($(strip $(LOCAL)),y)
   239 
   240 real-install:
   241 	@true
   242 
   243 real-uninstall:
   244 	@true
   245 
   246 else
   247 
   248 #--------------------------------------
   249 # Install rules
   250 
   251 real-install: $(patsubst %,install-%,$(TARGETS)) install-post
   252 
   253 install-bin: $(DESTDIR)$(BINDIR)
   254 	@echo "  INST    '$(PROG_NAME)'"
   255 	@$(install) -m 755 $(PROG_NAME) "$(DESTDIR)$(BINDIR)/$(PROG_NAME)"
   256 
   257 # If one is hacking crosstool-NG, the patch set might change between any two
   258 # installations of the same VERSION, thus the patches must be removed prior
   259 # to being installed. It is simpler to remove the whole lib/ directory, as it
   260 # is the goal of the install-lib rule to install the lib/ directory...
   261 install-lib: uninstall-lib $(DESTDIR)$(LIBDIR) install-lib-main install-lib-samples
   262 
   263 LIB_SUB_DIR := config contrib kconfig patches scripts
   264 $(patsubst %,install-lib-%-copy,$(LIB_SUB_DIR)): $(DESTDIR)$(LIBDIR)
   265 	@echo "  INSTDIR '$(patsubst install-lib-%-copy,%,$(@))/'"
   266 	@tar cf - --exclude='*.sh.in' $(patsubst install-lib-%-copy,%,$(@)) \
   267 	 |(cd "$(DESTDIR)$(LIBDIR)"; tar xf -)
   268 
   269 # Huh? It seems we need at least one command to make this rule kick-in.
   270 install-lib-%: install-lib-%-copy; @true
   271 
   272 # Huh? that one does not inherit the -opy dependency, above...
   273 install-lib-scripts: install-lib-scripts-copy
   274 	@chmod a+x $(DESTDIR)$(LIBDIR)/scripts/crosstool-NG.sh
   275 	@chmod a+x $(DESTDIR)$(LIBDIR)/scripts/saveSample.sh
   276 	@rm -f "$(DESTDIR)$(LIBDIR)/scripts/addToolVersion.sh"
   277 
   278 install-lib-main: $(DESTDIR)$(LIBDIR) $(patsubst %,install-lib-%,$(LIB_SUB_DIR))
   279 	@echo "  INST    'steps.mk'"
   280 	@$(install) -m 644 steps.mk "$(DESTDIR)$(LIBDIR)/steps.mk"
   281 	@echo "  INST    'paths.mk'"
   282 	@$(install) -m 644 paths.mk "$(DESTDIR)$(LIBDIR)/paths.mk"
   283 
   284 # Samples need a little love:
   285 #  - change every occurrence of CT_TOP_DIR to CT_LIB_DIR
   286 install-lib-samples: $(DESTDIR)$(LIBDIR) install-lib-main
   287 	@echo "  INSTDIR 'samples/'"
   288 	@for samp_dir in samples/*/; do                                         \
   289 	     mkdir -p "$(DESTDIR)$(LIBDIR)/$${samp_dir}";                       \
   290 	     $(sed) -r -e 's:\$$\{CT_TOP_DIR\}:\$$\{CT_LIB_DIR\}:;'             \
   291 	               -e 's:^(CT_WORK_DIR)=.*:\1="\$${CT_TOP_DIR}/.build":;'   \
   292 	            $${samp_dir}/crosstool.config                               \
   293 	            >"$(DESTDIR)$(LIBDIR)/$${samp_dir}/crosstool.config";       \
   294 	     $(install) -m 644 "$${samp_dir}/reported.by"                       \
   295 	                       "$(DESTDIR)$(LIBDIR)/$${samp_dir}";              \
   296 	     for libc_cfg in "$${samp_dir}/"*libc*.config; do                   \
   297 	         [ -f "$${libc_cfg}" ] || continue;                             \
   298 	         $(install) -m 644 "$${libc_cfg}"                               \
   299 	                           "$(DESTDIR)$(LIBDIR)/$${samp_dir}";          \
   300 	     done;                                                              \
   301 	 done
   302 	@$(install) -m 644 samples/samples.mk "$(DESTDIR)$(LIBDIR)/samples/samples.mk"
   303 
   304 install-doc: $(DESTDIR)$(DOCDIR)
   305 	@echo "  INST    'docs/*.txt'"
   306 	@for doc_file in docs/*.txt; do                              \
   307 	     $(install) -m 644 "$${doc_file}" "$(DESTDIR)$(DOCDIR)"; \
   308 	 done
   309 
   310 install-man: $(DESTDIR)$(MANDIR)$(MAN_SUBDIR)
   311 	@echo "  INST    '$(PROG_NAME).1.gz'"
   312 	@$(install) -m 644 docs/$(PROG_NAME).1.gz "$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)"
   313 
   314 $(sort $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(MANDIR)$(MAN_SUBDIR)):
   315 	@echo "  MKDIR   '$@/'"
   316 	@$(install) -m 755 -d "$@"
   317 
   318 install-post:
   319 	@echo
   320 	@echo "For auto-completion, do not forget to install '$(PROG_NAME).comp' into"
   321 	@echo "your bash completion directory (usually /etc/bash_completion.d)"
   322 
   323 #--------------------------------------
   324 # Uninstall rules
   325 
   326 real-uninstall: $(patsubst %,uninstall-%,$(TARGETS))
   327 
   328 uninstall-bin:
   329 	@echo "  RM      '$(DESTDIR)$(BINDIR)/$(PROG_NAME)'"
   330 	@rm -f "$(DESTDIR)$(BINDIR)/$(PROG_NAME)"
   331 
   332 uninstall-lib:
   333 	@echo "  RMDIR   '$(DESTDIR)$(LIBDIR)/'"
   334 	@rm -rf "$(DESTDIR)$(LIBDIR)"
   335 
   336 uninstall-doc:
   337 	@echo "  RMDIR   '$(DESTDIR)$(DOCDIR)/'"
   338 	@rm -rf "$(DESTDIR)$(DOCDIR)"
   339 
   340 uninstall-man:
   341 	@echo "  RM      '$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)/$(PROG_NAME).1.gz'"
   342 	@rm -f "$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)/$(PROG_NAME).1"{,.gz}
   343 
   344 endif # Not --local
   345 
   346 endif # No extra MAKEFLAGS were added