Makefile.in
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jul 12 23:52:24 2011 +0200 (2011-07-12)
branch1.11
changeset 2558 b7317d2fe0e9
parent 2423 861c2479baea
child 2481 30644208c955
permissions -rw-r--r--
scripts, cc/gcc: do not fail on existing symlinks or build.log

If the user builds a toolchain over an existing one, so, without removing
CT_PREFIX_DIR, the build fails as the symlinks already exist, as does the
build.log.

This can also happen (for build.log) if the user first ran in download-
or extract-only.

Patch (with no SoB) originally from:
Phil Wilshire <phil.wilshire@overturenetworks.com>

Modified by me as it did not apply cleanly.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
(transplanted from 1ebc2248cc60230cd53ff94ae8f8f1e3261461a3)
     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 DATE   := @@DATE@@
    47 LOCAL  := @@LOCAL@@
    48 
    49 # Paths found by ./configure
    50 install:= @@install@@
    51 bash   := @@bash@@
    52 grep   := @@grep@@
    53 make   := @@make@@
    54 sed    := @@sed@@
    55 libtool:= @@libtool@@
    56 objcopy:= @@objcopy@@
    57 objdump:= @@objdump@@
    58 readelf:= @@readelf@@
    59 patch  := @@patch@@
    60 
    61 ###############################################################################
    62 # Non-configure variables
    63 MAN_SECTION := 1
    64 MAN_SUBDIR := /man$(MAN_SECTION)
    65 
    66 ###############################################################################
    67 # Sanity checks
    68 
    69 # Check if Makefile is up to date:
    70 Makefile: Makefile.in
    71 	@echo "$< did changed: you must re-run './configure'"
    72 	@false
    73 
    74 # If installing with DESTDIR, check it's an absolute path
    75 ifneq ($(strip $(DESTDIR)),)
    76   ifneq ($(DESTDIR),$(abspath /$(DESTDIR)))
    77     $(error DESTDIR is not an absolute PATH: '$(DESTDIR)')
    78   endif
    79 endif
    80 
    81 ###############################################################################
    82 # Global make rules
    83 
    84 # If any extra MAKEFLAGS were added, re-run ourselves
    85 # See top of file for an explanation of why this is needed...
    86 ifneq ($(strip $(CT_MAKEFLAGS)),)
    87 
    88 MAKEFLAGS += $(CT_MAKEFLAGS)
    89 build install clean distclean uninstall:
    90 	@$(MAKE) $@
    91 
    92 else
    93 # There were no additional MAKEFLAGS to add, do the job
    94 
    95 TARGETS := bin lib doc man
    96 
    97 build: $(patsubst %,build-%,$(TARGETS))
    98 
    99 install: build real-install
   100 
   101 clean: $(patsubst %,clean-%,$(TARGETS))
   102 
   103 distclean: clean
   104 	@echo "  RM     'Makefile'"
   105 	@rm -f Makefile
   106 
   107 uninstall: real-uninstall
   108 
   109 ###############################################################################
   110 # Specific make rules
   111 
   112 #--------------------------------------
   113 # Build rules
   114 
   115 build-bin: ct-ng scripts/crosstool-NG.sh scripts/saveSample.sh scripts/showTuple.sh
   116 	@chmod 755 $^
   117 
   118 build-lib: paths.mk
   119 
   120 build-doc:
   121 
   122 build-man: docs/ct-ng.1.gz
   123 
   124 docs/ct-ng.1.gz: docs/ct-ng.1
   125 	@echo "  GZIP   '$@'"
   126 	@gzip -c9 $< >$@
   127 
   128 %: %.in Makefile
   129 	@echo "  SED    '$@'"
   130 	@$(sed) -r -e 's,@@CT_BINDIR@@,$(BINDIR),g;'    \
   131 	           -e 's,@@CT_LIBDIR@@,$(LIBDIR),g;'    \
   132 	           -e 's,@@CT_DOCDIR@@,$(DOCDIR),g;'    \
   133 	           -e 's,@@CT_MANDIR@@,$(MANDIR),g;'    \
   134 	           -e 's,@@CT_VERSION@@,$(VERSION),g;'	\
   135 	           -e 's,@@CT_DATE@@,$(DATE),g;'        \
   136 	           -e 's,@@CT_make@@,$(make),g;'        \
   137 	           -e 's,@@CT_bash@@,$(bash),g;'        \
   138 	           $@.in >$@
   139 
   140 # We create a script fragment that is parseable from inside a Makefile,
   141 # but also from inside a shell script, hence the reason why we don't
   142 # use := to set variables, although that will incur a (very small)
   143 # penalty from the Makefile that includes it (due to re-evaluation at
   144 # each call).
   145 paths.mk:
   146 	@echo "  GEN    '$@'"
   147 	@(echo "export install=$(install)"; \
   148 	  echo "export bash=$(bash)";       \
   149 	  echo "export grep=$(grep)";       \
   150 	  echo "export make=$(make)";       \
   151 	  echo "export sed=$(sed)";         \
   152 	  echo "export libtool=$(libtool)"; \
   153 	  echo "export objcopy=$(objcopy)"; \
   154 	  echo "export objdump=$(objdump)"; \
   155 	  echo "export readelf=$(readelf)"; \
   156 	  echo "export patch=$(patch)";     \
   157 	 ) >paths.mk
   158 
   159 #--------------------------------------
   160 # Clean rules
   161 
   162 clean-bin:
   163 	@echo "  RM     'ct-ng'"
   164 	@rm -f ct-ng
   165 	@echo "  RM     'scripts/crosstool-NG.sh'"
   166 	@rm -f scripts/crosstool-NG.sh
   167 	@echo "  RM     'scripts/saveSample.sh'"
   168 	@rm -f scripts/saveSample.sh
   169 	@echo "  RM     'scripts/showTuple.sh'"
   170 	@rm -f scripts/showTuple.sh
   171 
   172 clean-lib:
   173 	@echo "  RM     'paths.mk'"
   174 	@rm -f paths.mk
   175 
   176 clean-doc:
   177 
   178 clean-man:
   179 	@echo "  RM     'docs/ct-ng.1'"
   180 	@rm -f docs/ct-ng.1
   181 	@echo "  RM     'docs/ct-ng.1.gz'"
   182 	@rm -f docs/ct-ng.1.gz
   183 
   184 #--------------------------------------
   185 # Check for --local setup
   186 
   187 ifeq ($(strip $(LOCAL)),y)
   188 
   189 real-install:
   190 	@true
   191 
   192 real-uninstall:
   193 	@true
   194 
   195 else
   196 
   197 #--------------------------------------
   198 # Install rules
   199 
   200 real-install: $(patsubst %,install-%,$(TARGETS)) install-post
   201 
   202 install-bin: $(DESTDIR)$(BINDIR)
   203 	@echo "  INST    'ct-ng'"
   204 	@$(install) -m 755 ct-ng "$(DESTDIR)$(BINDIR)/ct-ng"
   205 
   206 # If one is hacking crosstool-NG, the patch set might change between any two
   207 # installations of the same VERSION, thus the patches must be removed prior
   208 # to being installed. It is simpler to remove the whole lib/ directory, as it
   209 # is the goal of the install-lib rule to install the lib/ directory...
   210 install-lib: uninstall-lib $(DESTDIR)$(LIBDIR) install-lib-main install-lib-samples
   211 
   212 LIB_SUB_DIR := config contrib kconfig patches scripts
   213 $(patsubst %,install-lib-%-copy,$(LIB_SUB_DIR)): $(DESTDIR)$(LIBDIR)
   214 	@echo "  INSTDIR '$(patsubst install-lib-%-copy,%,$(@))/'"
   215 	@tar cf - --exclude='*.sh.in' $(patsubst install-lib-%-copy,%,$(@)) \
   216 	 |(cd "$(DESTDIR)$(LIBDIR)"; tar xf -)
   217 
   218 # Huh? It seems we need at least one command to make this rule kick-in.
   219 install-lib-%: install-lib-%-copy; @true
   220 
   221 # Huh? that one does not inherit the -opy dependency, above...
   222 install-lib-scripts: install-lib-scripts-copy
   223 	@chmod a+x $(DESTDIR)$(LIBDIR)/scripts/crosstool-NG.sh
   224 	@chmod a+x $(DESTDIR)$(LIBDIR)/scripts/saveSample.sh
   225 	@rm -f "$(DESTDIR)$(LIBDIR)/scripts/addToolVersion.sh"
   226 
   227 install-lib-main: $(DESTDIR)$(LIBDIR) $(patsubst %,install-lib-%,$(LIB_SUB_DIR))
   228 	@echo "  INST    'steps.mk'"
   229 	@$(install) -m 644 steps.mk "$(DESTDIR)$(LIBDIR)/steps.mk"
   230 	@echo "  INST    'paths.mk'"
   231 	@$(install) -m 644 paths.mk "$(DESTDIR)$(LIBDIR)/paths.mk"
   232 
   233 # Samples need a little love:
   234 #  - change every occurrence of CT_TOP_DIR to CT_LIB_DIR
   235 install-lib-samples: $(DESTDIR)$(LIBDIR) install-lib-main
   236 	@echo "  INSTDIR 'samples/'"
   237 	@for samp_file in samples/*/crosstool.config; do                        \
   238 	     mkdir -p "$(DESTDIR)$(LIBDIR)/$${samp_file%/*}";                   \
   239 	     $(sed) -r -e 's:\$$\{CT_TOP_DIR\}:\$$\{CT_LIB_DIR\}:;'             \
   240 	               -e 's:^(CT_WORK_DIR)=.*:\1="\$${CT_TOP_DIR}/.build":;'   \
   241 	            $${samp_file}                                               \
   242 	            >"$(DESTDIR)$(LIBDIR)/$${samp_file}";                       \
   243 	 done
   244 	@$(install) -m 644 samples/samples.mk "$(DESTDIR)$(LIBDIR)/samples/samples.mk"
   245 
   246 install-doc: $(DESTDIR)$(DOCDIR)
   247 	@echo "  INST    'docs/*.txt'"
   248 	@for doc_file in docs/*.txt; do                              \
   249 	     $(install) -m 644 "$${doc_file}" "$(DESTDIR)$(DOCDIR)"; \
   250 	 done
   251 
   252 install-man: $(DESTDIR)$(MANDIR)$(MAN_SUBDIR)
   253 	@echo "  INST    'ct-ng.1.gz'"
   254 	@$(install) -m 644 docs/ct-ng.1.gz "$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)"
   255 
   256 $(sort $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(MANDIR)$(MAN_SUBDIR)):
   257 	@echo "  MKDIR   '$@/'"
   258 	@$(install) -m 755 -d "$@"
   259 
   260 install-post:
   261 	@echo
   262 	@echo "For auto-completion, do not forget to install 'ct-ng.comp' into"
   263 	@echo "your bash completion directory (usually /etc/bash_completion.d)"
   264 
   265 #--------------------------------------
   266 # Uninstall rules
   267 
   268 real-uninstall: $(patsubst %,uninstall-%,$(TARGETS))
   269 
   270 uninstall-bin:
   271 	@echo "  RM      '$(DESTDIR)$(BINDIR)/ct-ng'"
   272 	@rm -f "$(DESTDIR)$(BINDIR)/ct-ng"
   273 
   274 uninstall-lib:
   275 	@echo "  RMDIR   '$(DESTDIR)$(LIBDIR)/'"
   276 	@rm -rf "$(DESTDIR)$(LIBDIR)"
   277 
   278 uninstall-doc:
   279 	@echo "  RMDIR   '$(DESTDIR)$(DOCDIR)/'"
   280 	@rm -rf "$(DESTDIR)$(DOCDIR)"
   281 
   282 uninstall-man:
   283 	@echo "  RM      '$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)/ct-ng.1.gz'"
   284 	@rm -f "$(DESTDIR)$(MANDIR)$(MAN_SUBDIR)/ct-ng.1"{,.gz}
   285 
   286 endif # Not --local
   287 
   288 endif # No extra MAKEFLAGS were added