| [995] | 1 | # $Id: bootstrap.gmk 2019 2008-11-02 00:21:05Z bird $
 | 
|---|
 | 2 | ## @file
 | 
|---|
 | 3 | # GNU Make Compatible bootstrap Makefile.
 | 
|---|
 | 4 | #
 | 
|---|
| [1512] | 5 | 
 | 
|---|
 | 6 | #
 | 
|---|
| [2019] | 7 | # Copyright (c) 2007-2008 knut st. osmundsen <bird-src-spam@anduin.net>
 | 
|---|
| [995] | 8 | #
 | 
|---|
 | 9 | # This file is part of kBuild.
 | 
|---|
 | 10 | #
 | 
|---|
 | 11 | # kBuild is free software; you can redistribute it and/or modify
 | 
|---|
 | 12 | # it under the terms of the GNU General Public License as published by
 | 
|---|
| [2019] | 13 | # the Free Software Foundation; either version 3 of the License, or
 | 
|---|
| [995] | 14 | # (at your option) any later version.
 | 
|---|
 | 15 | #
 | 
|---|
 | 16 | # kBuild is distributed in the hope that it will be useful,
 | 
|---|
 | 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 19 | # GNU General Public License for more details.
 | 
|---|
 | 20 | #
 | 
|---|
 | 21 | # You should have received a copy of the GNU General Public License
 | 
|---|
| [2019] | 22 | # along with kBuild.  If not, see <http://www.gnu.org/licenses/>
 | 
|---|
| [995] | 23 | #
 | 
|---|
 | 24 | #
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | #
 | 
|---|
 | 27 | # ASSUMES:
 | 
|---|
| [1506] | 28 | #   - KBUILD_TARGET, KBUILD_HOST, KBUILD_HOST_ARCH, and KBUILD_TYPE in the env.
 | 
|---|
| [1529] | 29 | #   - KBUILD_PATH points to ./kBuild with an absolute path.
 | 
|---|
 | 30 | #   - KBUILD_BIN_PATH and PATH_KBUILD_BIN must *NOT* be defined anywhere.
 | 
|---|
| [995] | 31 | #   - Current directory == bootstrap.gmk directory.
 | 
|---|
 | 32 | #   - mkdir -p works.
 | 
|---|
 | 33 | #   - ln -s works
 | 
|---|
 | 34 | #   - cp -f works
 | 
|---|
 | 35 | #   - cd somedir && command works.
 | 
|---|
| [1506] | 36 | #   - echo done > some-file works.
 | 
|---|
| [1529] | 37 | #   - Recent GNU make that implements CURDIR, $(error) and ifdef.
 | 
|---|
| [995] | 38 | #
 | 
|---|
| [1529] | 39 | # Tip: kBuild/env.sh --full (g(nu))make -f bootstrap.kmk
 | 
|---|
| [995] | 40 | #
 | 
|---|
 | 41 | #
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | #
 | 
|---|
 | 44 | # OPTIONAL:
 | 
|---|
 | 45 | #   Set env.var. NIX_INSTALL_DIR to /usr/local or /usr
 | 
|---|
 | 46 | #   (see Config.kmk and wiki for details)
 | 
|---|
 | 47 | #
 | 
|---|
 | 48 | 
 | 
|---|
| [1506] | 49 | #
 | 
|---|
 | 50 | # Deal with legacy env.vars. - no niceties here.
 | 
|---|
 | 51 | #
 | 
|---|
 | 52 | ifndef KBUILD_HOST
 | 
|---|
 | 53 |  KBUILD_HOST := $(BUILD_PLATFORM)
 | 
|---|
 | 54 | endif
 | 
|---|
 | 55 | ifndef KBUILD_HOST_ARCH
 | 
|---|
 | 56 |  KBUILD_HOST_ARCH := $(BUILD_PLATFORM_ARCH)
 | 
|---|
 | 57 | endif
 | 
|---|
 | 58 | ifndef KBUILD_HOST_CPU
 | 
|---|
 | 59 |  KBUILD_HOST_CPU := $(BUILD_PLATFORM_CPU)
 | 
|---|
 | 60 | endif
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 | ifndef KBUILD_TARGET
 | 
|---|
 | 63 |  KBUILD_TARGET := $(BUILD_TARGET)
 | 
|---|
 | 64 | endif
 | 
|---|
 | 65 | ifndef KBUILD_TARGET_ARCH
 | 
|---|
 | 66 |  KBUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH)
 | 
|---|
 | 67 | endif
 | 
|---|
 | 68 | ifndef KBUILD_TARGET_CPU
 | 
|---|
 | 69 |  KBUILD_TARGET_CPU := $(BUILD_TARGET_CPU)
 | 
|---|
 | 70 | endif
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | ifndef KBUILD_TYPE
 | 
|---|
 | 73 |  KBUILD_TYPE := $(BUILD_TYPE)
 | 
|---|
 | 74 | endif
 | 
|---|
 | 75 | 
 | 
|---|
 | 76 | ifndef KBUILD_PATH
 | 
|---|
 | 77 |  KBUILD_PATH := $(PATH_KBUILD)
 | 
|---|
 | 78 | endif
 | 
|---|
 | 79 | 
 | 
|---|
| [1529] | 80 | #
 | 
|---|
 | 81 | # Check (some of) the assumptions.
 | 
|---|
 | 82 | #
 | 
|---|
 | 83 | ifndef KBUILD_TARGET
 | 
|---|
 | 84 |  $(error KBUILD_TARGET not set)
 | 
|---|
 | 85 | endif
 | 
|---|
| [1506] | 86 | 
 | 
|---|
| [1529] | 87 | ifndef KBUILD_HOST
 | 
|---|
 | 88 |  $(error KBUILD_HOST not set)
 | 
|---|
 | 89 | endif
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 | ifndef KBUILD_HOST_ARCH
 | 
|---|
 | 92 |  $(error KBUILD_HOST_ARCH not set)
 | 
|---|
 | 93 | endif
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 | ifndef KBUILD_TYPE
 | 
|---|
 | 96 |  $(error KBUILD_TYPE not set)
 | 
|---|
 | 97 | endif
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 | ifndef KBUILD_TYPE
 | 
|---|
 | 100 |  $(error KBUILD_TYPE not set)
 | 
|---|
 | 101 | endif
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 | ifndef KBUILD_PATH
 | 
|---|
 | 104 |  $(error KBUILD_PATH not set)
 | 
|---|
 | 105 | endif
 | 
|---|
 | 106 | 
 | 
|---|
 | 107 | ifdef KBUILD_BIN_PATH
 | 
|---|
 | 108 |  $(error KBUILD_BIN_PATH is set)
 | 
|---|
 | 109 | endif
 | 
|---|
 | 110 | ifdef PATH_KBUILD_BIN
 | 
|---|
 | 111 |  $(error PATH_KBUILD_BIN is set)
 | 
|---|
 | 112 | endif
 | 
|---|
 | 113 | 
 | 
|---|
 | 114 | 
 | 
|---|
| [1506] | 115 | #
 | 
|---|
 | 116 | # Globals
 | 
|---|
 | 117 | #
 | 
|---|
| [996] | 118 | SRCDIR = $(CURDIR)
 | 
|---|
| [1506] | 119 | OUTDIR = $(SRCDIR)/out/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)/$(KBUILD_TYPE)/bootstrap
 | 
|---|
| [995] | 120 | 
 | 
|---|
| [1068] | 121 | # Override this on the make commandline if you need to (FreeBSD).
 | 
|---|
 | 122 | AUTORECONF = autoreconf
 | 
|---|
| [995] | 123 | 
 | 
|---|
| [996] | 124 | all: stage1 stage2
 | 
|---|
| [995] | 125 | 
 | 
|---|
| [996] | 126 | 
 | 
|---|
| [995] | 127 | #
 | 
|---|
| [1339] | 128 | # Stage 1 - Build bootstrap kmk, kmk_redirect and sed, refresh config.h caches, link
 | 
|---|
| [995] | 129 | #           up kmk_ash so $(OUTDIR)/kmk can serve as kBuild bin dir.
 | 
|---|
 | 130 | #
 | 
|---|
 | 131 | stage1: \
 | 
|---|
 | 132 |     $(OUTDIR)/kmk/kmk \
 | 
|---|
 | 133 |     $(OUTDIR)/kmk/kmk_ash \
 | 
|---|
 | 134 |     $(OUTDIR)/kmk/kmk_sed \
 | 
|---|
| [1506] | 135 |     $(SRCDIR)/src/kmk/config.h.$(KBUILD_TARGET) \
 | 
|---|
 | 136 |     $(SRCDIR)/src/sed/config.h.$(KBUILD_TARGET)
 | 
|---|
| [995] | 137 | 
 | 
|---|
 | 138 | # kmk
 | 
|---|
| [996] | 139 | $(OUTDIR)/kmk/ts-autoreconf:
 | 
|---|
 | 140 |         mkdir -p $(@D)
 | 
|---|
| [1068] | 141 |         cd $(SRCDIR)/src/kmk && $(AUTORECONF) -i -v
 | 
|---|
| [996] | 142 |         echo done > $@
 | 
|---|
| [995] | 143 | 
 | 
|---|
 | 144 | $(OUTDIR)/kmk/ts-configured: $(OUTDIR)/kmk/ts-autoreconf
 | 
|---|
| [996] | 145 |         cd $(OUTDIR)/kmk && $(SRCDIR)/src/kmk/configure
 | 
|---|
 | 146 |         echo done > $@
 | 
|---|
| [995] | 147 | 
 | 
|---|
 | 148 | $(OUTDIR)/kmk/config.h: $(OUTDIR)/kmk/ts-configured
 | 
|---|
 | 149 | 
 | 
|---|
| [1506] | 150 | $(SRCDIR)/src/kmk/config.h.$(KBUILD_TARGET): $(OUTDIR)/kmk/config.h
 | 
|---|
 | 151 |         cp -f $(OUTDIR)/kmk/config.h $(SRCDIR)/src/kmk/config.h.$(KBUILD_TARGET)
 | 
|---|
| [995] | 152 | 
 | 
|---|
 | 153 | $(OUTDIR)/kmk/kmk: $(OUTDIR)/kmk/ts-configured
 | 
|---|
| [996] | 154 |         $(MAKE) -C $(@D)
 | 
|---|
| [995] | 155 | 
 | 
|---|
 | 156 | # sed
 | 
|---|
| [996] | 157 | $(OUTDIR)/sed/ts-autoreconf:
 | 
|---|
 | 158 |         mkdir -p $(@D)
 | 
|---|
| [1159] | 159 |         @cd $(SRCDIR)/src/sed && $(AUTORECONF) -i -v --force
 | 
|---|
| [996] | 160 |         echo done > $@
 | 
|---|
| [995] | 161 | 
 | 
|---|
 | 162 | $(OUTDIR)/sed/ts-configured: $(OUTDIR)/sed/ts-autoreconf
 | 
|---|
| [996] | 163 |         cd $(OUTDIR)/sed && $(SRCDIR)/src/sed/configure --without-libintl --disable-nls
 | 
|---|
 | 164 |         echo done > $@
 | 
|---|
| [995] | 165 | 
 | 
|---|
 | 166 | $(OUTDIR)/sed/config.h: $(OUTDIR)/sed/ts-configured
 | 
|---|
 | 167 | 
 | 
|---|
| [1506] | 168 | $(SRCDIR)/src/sed/config.h.$(KBUILD_TARGET): $(OUTDIR)/sed/config.h
 | 
|---|
| [996] | 169 |         cp -f $< $@
 | 
|---|
| [995] | 170 | 
 | 
|---|
| [996] | 171 | $(OUTDIR)/sed/sed/sed: $(OUTDIR)/sed/ts-configured
 | 
|---|
 | 172 |         $(MAKE) -C $(@D)/..
 | 
|---|
| [995] | 173 | 
 | 
|---|
| [996] | 174 | $(OUTDIR)/kmk/kmk_sed: $(OUTDIR)/sed/sed/sed
 | 
|---|
 | 175 |         cp -f $< $@
 | 
|---|
| [995] | 176 | 
 | 
|---|
 | 177 | $(OUTDIR)/kmk/kmk_ash:
 | 
|---|
| [996] | 178 |         ln -s /bin/sh $@
 | 
|---|
| [995] | 179 | 
 | 
|---|
 | 180 | #
 | 
|---|
 | 181 | # Stage 2 - Build kBuild using the bootstrap tools from the previous step
 | 
|---|
 | 182 | #           and install it to kBuild/bin/x.y.
 | 
|---|
 | 183 | #
 | 
|---|
 | 184 | stage2: \
 | 
|---|
 | 185 |     $(OUTDIR)/ts-stage2-build \
 | 
|---|
 | 186 |     $(OUTDIR)/ts-stage2-install
 | 
|---|
 | 187 | 
 | 
|---|
| [996] | 188 | $(OUTDIR)/ts-stage2-build: \
 | 
|---|
| [1506] | 189 |                 $(SRCDIR)/src/kmk/config.h.$(KBUILD_TARGET) \
 | 
|---|
 | 190 |                 $(SRCDIR)/src/sed/config.h.$(KBUILD_TARGET) \
 | 
|---|
| [996] | 191 |                 $(OUTDIR)/kmk/kmk
 | 
|---|
 | 192 |         $(OUTDIR)/kmk/kmk -C $(SRCDIR)
 | 
|---|
 | 193 |         echo done > $@
 | 
|---|
| [995] | 194 | 
 | 
|---|
| [996] | 195 | $(OUTDIR)/ts-stage2-install: $(OUTDIR)/ts-stage2-build
 | 
|---|
| [998] | 196 |         $(OUTDIR)/kmk/kmk -C $(SRCDIR) PATH_INS=$(SRCDIR) install
 | 
|---|
| [996] | 197 |         echo done > $@
 | 
|---|
| [995] | 198 | 
 | 
|---|
| [996] | 199 | 
 | 
|---|
| [999] | 200 | #
 | 
|---|
 | 201 | # Clean the output files...
 | 
|---|
 | 202 | #
 | 
|---|
 | 203 | clean:
 | 
|---|
 | 204 |         rm -Rf $(SRCDIR)/out/ \
 | 
|---|
 | 205 |                 $(SRCDIR)/src/kmk/autom4te.cache/ \
 | 
|---|
 | 206 |                 $(SRCDIR)/src/sed/autom4te.cache/
 | 
|---|
 | 207 |         rm -f $(SRCDIR)/src/kmk/Makefile.in \
 | 
|---|
 | 208 |                 $(SRCDIR)/src/kmk/config.h.in \
 | 
|---|
 | 209 |                 $(SRCDIR)/src/kmk/configure \
 | 
|---|
 | 210 |                 $(SRCDIR)/src/kmk/aclocal.m4 \
 | 
|---|
 | 211 |                 $(SRCDIR)/src/kmk/glob/Makefile.in \
 | 
|---|
 | 212 |                 $(SRCDIR)/src/kmk/config/Makefile.in \
 | 
|---|
 | 213 |                 $(SRCDIR)/src/kmk/config/depcomp \
 | 
|---|
 | 214 |                 $(SRCDIR)/src/kmk/config/compile \
 | 
|---|
 | 215 |                 $(SRCDIR)/src/kmk/config/missing \
 | 
|---|
 | 216 |                 $(SRCDIR)/src/kmk/config/config.guess \
 | 
|---|
 | 217 |                 $(SRCDIR)/src/kmk/config/config.sub \
 | 
|---|
 | 218 |                 $(SRCDIR)/src/kmk/config/install-sh \
 | 
|---|
 | 219 |                 $(SRCDIR)/src/kmk/w32/Makefile.in
 | 
|---|
| [996] | 220 | 
 | 
|---|
 | 221 | 
 | 
|---|
 | 222 | # can't hurt...
 | 
|---|
 | 223 | .NOTPARALLEL:
 | 
|---|
 | 224 | 
 | 
|---|