+[+ ;; These Scheme functions build the bulk of the dependencies.
+ ;; dep-target builds a string like "maybe-all-MODULE_KIND-gcc",
+ ;; where "maybe-" is only included if HARD is not true, and all-gcc
+ ;; is taken from VAR-NAME.
+ (define dep-target (lambda (module-kind var-name hard)
+ (string-append
+ (if hard "" "maybe-")
+ (dep-subtarget var-name)
+ module-kind
+ (dep-module var-name)
+ )))
+
+ ;; make-dep builds a dependency from the MODULE and ON AutoGen vars.
+ (define make-dep (lambda (module-kind on-kind)
+ (string-append
+ (dep-target module-kind "module" #t) ": "
+ (dep-target on-kind "on" (exist? "hard")))))
+
+ ;; dep-subtarget extracts everything up to the first dash in the given
+ ;; AutoGen variable, for example it extracts "all-" out of "all-gcc".
+ (define dep-subtarget (lambda (var-name)
+ (substring (get var-name) 0 (+ 1 (string-index (get var-name) #\-)))))
+
+ ;; dep-module extracts everything up to the first dash in the given
+ ;; AutoGen variable, for example it extracts "gcc" out of "all-gcc".
+ (define dep-module (lambda (var-name)
+ (substring (get var-name) (+ 1 (string-index (get var-name) #\-)))))
+
+ ;; dep-stage builds a string for the prefix of a bootstrap stage.
+ (define dep-stage (lambda ()
+ (string-append
+ "stage"
+ (get "id")
+ "-")))
+
+ ;; dep-maybe is the same as the AutoGen expression "- hard 'maybe-'"
+ ;; but is written in Scheme.
+ (define dep-maybe (lambda ()
+ (if (exist? "hard") "" "maybe-")))
+
+ ;; dep-kind returns returns "prebootstrap" for configure or build
+ ;; dependencies of bootstrapped modules on a build module
+ ;; (e.g. all-gcc on all-build-bison); "normal" if the dependency is
+ ;; on an "install" target, or if the dependence module is not
+ ;; bootstrapped; otherwise, it returns "bootstrap" or
+ ;; "postbootstrap" depending on whether the dependent module is
+ ;; bootstrapped. All this is only necessary for host and target
+ ;; modules. It might seem like, in order to avoid build races, we
+ ;; might need more elaborate detection between prebootstrap and
+ ;; postbootstrap modules, but there are no host prebootstrap
+ ;; modules. If there were any non-bootstrap host modules that
+ ;; bootstrap modules depended on, we'd get unsatisfied per-stage
+ ;; dependencies on them, which would be immediately noticed.
+ (define dep-kind (lambda ()
+ (cond
+ ((and (hash-ref boot-modules (dep-module "module"))
+ (=* (dep-module "on") "build-"))
+ "prebootstrap")
+
+ ((or (= (dep-subtarget "on") "install-")
+ (not (hash-ref boot-modules (dep-module "on"))))
+ "normal")
+
+ ((hash-ref boot-modules (dep-module "module"))
+ "bootstrap")
+
+ (1 "postbootstrap"))))
+
+ (define make-postboot-dep (lambda ()
+ (let ((target (dep-module "module")) (dep "stage_last"))
+ (unless (= (hash-ref postboot-targets target) dep)
+ (hash-create-handle! postboot-targets target dep)
+ ;; All non-bootstrap modules' configure target already
+ ;; depend on dep.
+ (unless (=* target "target-")
+ (string-append "configure-" target ": " dep "\n"))))))
+
+ ;; We now build the hash table that is used by dep-kind.
+ (define boot-modules (make-hash-table 113))
+ (define postboot-targets (make-hash-table 113))
++]
+
+[+ FOR host_modules +][+
+ (if (exist? "bootstrap")
+ (hash-create-handle! boot-modules (get "module") #t))
+ "" +][+ ENDFOR host_modules +]
+[+ FOR target_modules +][+
+ (if (exist? "bootstrap")
+ (hash-create-handle! boot-modules (string-append "target-" (get "module")) #t))
+ "" +][+ ENDFOR target_modules +]
+
+# With all the machinery above in place, it is pretty easy to generate
+# dependencies. Host dependencies are a bit more complex because we have
+# to check for bootstrap/prebootstrap dependencies. To resolve
+# prebootstrap dependencies, prebootstrap modules are gathered in
+# a hash table.
+[+ FOR dependencies +][+ CASE (dep-kind) +]
+[+ == "prebootstrap" +][+ (make-dep "" "") +][+ FOR bootstrap_stage +]
+[+ (make-dep (dep-stage) "") +][+ ENDFOR bootstrap_stage +]
+[+ == "bootstrap" +][+ (make-dep "" "") +][+ FOR bootstrap_stage +]
+[+ (make-dep (dep-stage) (dep-stage)) +][+ ENDFOR bootstrap_stage +]
+[+ == "normal" +][+ (make-dep "" "") +]
+[+ ESAC +][+ ENDFOR dependencies +]
+
+@if gcc-bootstrap
+[+ FOR dependencies +][+ CASE (dep-kind) +]
+[+ == "postbootstrap" +][+ (make-postboot-dep) +][+ ESAC +][+
+ENDFOR dependencies +]@endif gcc-bootstrap
+
+@unless gcc-bootstrap
+[+ FOR dependencies +][+ CASE (dep-kind) +]
+[+ == "postbootstrap" +][+ (make-dep "" "") +]
+[+ ESAC +][+ ENDFOR dependencies +]@endunless gcc-bootstrap
+
+# Dependencies for target modules on other target modules are
+# described by lang_env_dependencies; the defaults apply to anything
+# not mentioned there.
+[+
+ ;; Predicate for whether LANG was specified in lang_env_dependencies.
+ (define lang-dep (lambda (lang)
+ (hash-ref lang-env-deps (string-append (get "module") "-" lang))))
+
+ ;; Build the hash table we will need.
+ (define lang-env-deps (make-hash-table 7))
++][+ FOR lang_env_dependencies +][+
+ (if (exist? "cxx")
+ (hash-create-handle! lang-env-deps
+ (string-append (get "module") "-" "cxx") #t))
+
+ (if (exist? "no_c")
+ (hash-create-handle! lang-env-deps
+ (string-append (get "module") "-" "no_c") #t))
+
+ (if (exist? "no_gcc")
+ (hash-create-handle! lang-env-deps
+ (string-append (get "module") "-" "no_gcc") #t))
+ "" +][+ ENDFOR lang_env_dependencies +]
+
+@if gcc-bootstrap[+ FOR target_modules +][+ IF (not (lang-dep "no_gcc"))
+ +][+ IF bootstrap +][+ FOR bootstrap_stage +]
+configure-stage[+id+]-target-[+module+]: maybe-all-stage[+id+]-target-libgcc[+
+ ENDFOR +][+ ENDIF bootstrap +][+ ENDIF +][+ ENDFOR target_modules +]
+@endif gcc-bootstrap
+
+@if gcc-no-bootstrap[+ FOR target_modules +][+ IF (not (lang-dep "no_gcc")) +]
+configure-target-[+module+]: maybe-all-target-libgcc[+
+ ENDIF +][+ ENDFOR target_modules +]
+@endif gcc-no-bootstrap
+
+[+ FOR target_modules +][+ IF (not (lang-dep "no_c")) +]
+configure-target-[+module+]: maybe-all-target-newlib maybe-all-target-libgloss[+
+ ENDIF +][+ IF (lang-dep "cxx") +]
+configure-target-[+module+]: maybe-all-target-libstdc++-v3[+
+ ENDIF +]
+[+ ENDFOR target_modules +]
+
+CONFIGURE_GDB_TK = @CONFIGURE_GDB_TK@