Makefile.in
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Aug 17 23:05:01 2011 +0200 (2011-08-17)
changeset 2621 00853d565edf
parent 2620 d9c5b3b75864
child 2622 bc9f7c29311e
permissions -rw-r--r--
configure: handle --program-prefix

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