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