# $Id$ ## @file # GNU Make Compatible bootstrap Makefile. # # # Copyright (c) 2007 knut st. osmundsen # # This file is part of kBuild. # # kBuild is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # kBuild is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with kBuild; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # # ASSUMES: # - KBUILD_TARGET, KBUILD_HOST, KBUILD_HOST_ARCH, and KBUILD_TYPE in the env. # - KBUILD_PATH points to ./kBuild with an absolute path. # - KBUILD_BIN_PATH and PATH_KBUILD_BIN must *NOT* be defined anywhere. # - Current directory == bootstrap.gmk directory. # - mkdir -p works. # - ln -s works # - cp -f works # - cd somedir && command works. # - echo done > some-file works. # - Recent GNU make that implements CURDIR, $(error) and ifdef. # # Tip: kBuild/env.sh --full (g(nu))make -f bootstrap.kmk # # # # OPTIONAL: # Set env.var. NIX_INSTALL_DIR to /usr/local or /usr # (see Config.kmk and wiki for details) # # # Deal with legacy env.vars. - no niceties here. # ifndef KBUILD_HOST KBUILD_HOST := $(BUILD_PLATFORM) endif ifndef KBUILD_HOST_ARCH KBUILD_HOST_ARCH := $(BUILD_PLATFORM_ARCH) endif ifndef KBUILD_HOST_CPU KBUILD_HOST_CPU := $(BUILD_PLATFORM_CPU) endif ifndef KBUILD_TARGET KBUILD_TARGET := $(BUILD_TARGET) endif ifndef KBUILD_TARGET_ARCH KBUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH) endif ifndef KBUILD_TARGET_CPU KBUILD_TARGET_CPU := $(BUILD_TARGET_CPU) endif ifndef KBUILD_TYPE KBUILD_TYPE := $(BUILD_TYPE) endif ifndef KBUILD_PATH KBUILD_PATH := $(PATH_KBUILD) endif # # Check (some of) the assumptions. # ifndef KBUILD_TARGET $(error KBUILD_TARGET not set) endif ifndef KBUILD_HOST $(error KBUILD_HOST not set) endif ifndef KBUILD_HOST_ARCH $(error KBUILD_HOST_ARCH not set) endif ifndef KBUILD_TYPE $(error KBUILD_TYPE not set) endif ifndef KBUILD_TYPE $(error KBUILD_TYPE not set) endif ifndef KBUILD_PATH $(error KBUILD_PATH not set) endif ifdef KBUILD_BIN_PATH $(error KBUILD_BIN_PATH is set) endif ifdef PATH_KBUILD_BIN $(error PATH_KBUILD_BIN is set) endif # # Globals # SRCDIR = $(CURDIR) OUTDIR = $(SRCDIR)/out/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)/$(KBUILD_TYPE)/bootstrap # Override this on the make commandline if you need to (FreeBSD). AUTORECONF = autoreconf all: stage1 stage2 # # Stage 1 - Build bootstrap kmk, kmk_redirect and sed, refresh config.h caches, link # up kmk_ash so $(OUTDIR)/kmk can serve as kBuild bin dir. # stage1: \ $(OUTDIR)/kmk/kmk \ $(OUTDIR)/kmk/kmk_ash \ $(OUTDIR)/kmk/kmk_sed \ $(SRCDIR)/src/kmk/config.h.$(KBUILD_TARGET) \ $(SRCDIR)/src/sed/config.h.$(KBUILD_TARGET) # kmk $(OUTDIR)/kmk/ts-autoreconf: mkdir -p $(@D) cd $(SRCDIR)/src/kmk && $(AUTORECONF) -i -v echo done > $@ $(OUTDIR)/kmk/ts-configured: $(OUTDIR)/kmk/ts-autoreconf cd $(OUTDIR)/kmk && $(SRCDIR)/src/kmk/configure echo done > $@ $(OUTDIR)/kmk/config.h: $(OUTDIR)/kmk/ts-configured $(SRCDIR)/src/kmk/config.h.$(KBUILD_TARGET): $(OUTDIR)/kmk/config.h cp -f $(OUTDIR)/kmk/config.h $(SRCDIR)/src/kmk/config.h.$(KBUILD_TARGET) $(OUTDIR)/kmk/kmk: $(OUTDIR)/kmk/ts-configured $(MAKE) -C $(@D) # sed $(OUTDIR)/sed/ts-autoreconf: mkdir -p $(@D) @cd $(SRCDIR)/src/sed && $(AUTORECONF) -i -v --force echo done > $@ $(OUTDIR)/sed/ts-configured: $(OUTDIR)/sed/ts-autoreconf cd $(OUTDIR)/sed && $(SRCDIR)/src/sed/configure --without-libintl --disable-nls echo done > $@ $(OUTDIR)/sed/config.h: $(OUTDIR)/sed/ts-configured $(SRCDIR)/src/sed/config.h.$(KBUILD_TARGET): $(OUTDIR)/sed/config.h cp -f $< $@ $(OUTDIR)/sed/sed/sed: $(OUTDIR)/sed/ts-configured $(MAKE) -C $(@D)/.. $(OUTDIR)/kmk/kmk_sed: $(OUTDIR)/sed/sed/sed cp -f $< $@ $(OUTDIR)/kmk/kmk_ash: ln -s /bin/sh $@ # # Stage 2 - Build kBuild using the bootstrap tools from the previous step # and install it to kBuild/bin/x.y. # stage2: \ $(OUTDIR)/ts-stage2-build \ $(OUTDIR)/ts-stage2-install $(OUTDIR)/ts-stage2-build: \ $(SRCDIR)/src/kmk/config.h.$(KBUILD_TARGET) \ $(SRCDIR)/src/sed/config.h.$(KBUILD_TARGET) \ $(OUTDIR)/kmk/kmk $(OUTDIR)/kmk/kmk -C $(SRCDIR) echo done > $@ $(OUTDIR)/ts-stage2-install: $(OUTDIR)/ts-stage2-build $(OUTDIR)/kmk/kmk -C $(SRCDIR) PATH_INS=$(SRCDIR) install echo done > $@ # # Clean the output files... # clean: rm -Rf $(SRCDIR)/out/ \ $(SRCDIR)/src/kmk/autom4te.cache/ \ $(SRCDIR)/src/sed/autom4te.cache/ rm -f $(SRCDIR)/src/kmk/Makefile.in \ $(SRCDIR)/src/kmk/config.h.in \ $(SRCDIR)/src/kmk/configure \ $(SRCDIR)/src/kmk/aclocal.m4 \ $(SRCDIR)/src/kmk/glob/Makefile.in \ $(SRCDIR)/src/kmk/config/Makefile.in \ $(SRCDIR)/src/kmk/config/depcomp \ $(SRCDIR)/src/kmk/config/compile \ $(SRCDIR)/src/kmk/config/missing \ $(SRCDIR)/src/kmk/config/config.guess \ $(SRCDIR)/src/kmk/config/config.sub \ $(SRCDIR)/src/kmk/config/install-sh \ $(SRCDIR)/src/kmk/w32/Makefile.in # can't hurt... .NOTPARALLEL: