blob: 91cac40df14b566423c012b9a085a87b201cc206 [file] [log] [blame]
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +09001// Copyright 2015 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package kati
16
17import (
18 "fmt"
19 "path/filepath"
20 "strings"
21)
22
23const bootstrapMakefileName = "*bootstrap*"
24
Fumitoshi Ukai65c72332015-06-26 21:32:50 +090025func bootstrapMakefile(targets []string) (makefile, error) {
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090026 bootstrap := `
27CC:=cc
28CXX:=g++
29AR:=ar
30MAKE:=kati
31# Pretend to be GNU make 3.81, for compatibility.
32MAKE_VERSION:=3.81
33SHELL:=/bin/sh
34# TODO: Add more builtin vars.
35
36# http://www.gnu.org/software/make/manual/make.html#Catalogue-of-Rules
37# The document above is actually not correct. See default.c:
38# http://git.savannah.gnu.org/cgit/make.git/tree/default.c?id=4.1
39.c.o:
40 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
41.cc.o:
42 $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
43# TODO: Add more builtin rules.
44`
45 bootstrap += fmt.Sprintf("MAKECMDGOALS:=%s\n", strings.Join(targets, " "))
46 cwd, err := filepath.Abs(".")
47 if err != nil {
Fumitoshi Ukai65c72332015-06-26 21:32:50 +090048 return makefile{}, err
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090049 }
50 bootstrap += fmt.Sprintf("CURDIR:=%s\n", cwd)
Fumitoshi Ukai65c72332015-06-26 21:32:50 +090051 return parseMakefileString(bootstrap, srcpos{bootstrapMakefileName, 0})
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090052}