Makefile.in
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Aug 19 22:43:01 2011 +0200 (2011-08-19)
changeset 2622 bc9f7c29311e
parent 2621 00853d565edf
child 2623 e8e30025fcc5
permissions -rw-r--r--
configure: recognise and handle --program-suffix

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