blob: 9ef396a39386b6f31a5e0cf2b179242c0bcbb775 [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 := `
Shinichiro Hamaji91d12492015-09-04 09:54:48 +090027CC?=cc
28CXX?=g++
29AR?=ar
30MAKE?=kati
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090031# Pretend to be GNU make 3.81, for compatibility.
Shinichiro Hamaji91d12492015-09-04 09:54:48 +090032MAKE_VERSION?=3.81
Shinichiro Hamajicdcd4192015-09-04 10:06:30 +090033KATI?=kati
Shinichiro Hamaji91d12492015-09-04 09:54:48 +090034SHELL=/bin/sh
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090035# TODO: Add more builtin vars.
36
37# http://www.gnu.org/software/make/manual/make.html#Catalogue-of-Rules
38# The document above is actually not correct. See default.c:
39# http://git.savannah.gnu.org/cgit/make.git/tree/default.c?id=4.1
40.c.o:
41 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
42.cc.o:
43 $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
44# TODO: Add more builtin rules.
45`
46 bootstrap += fmt.Sprintf("MAKECMDGOALS:=%s\n", strings.Join(targets, " "))
47 cwd, err := filepath.Abs(".")
48 if err != nil {
Fumitoshi Ukai65c72332015-06-26 21:32:50 +090049 return makefile{}, err
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090050 }
51 bootstrap += fmt.Sprintf("CURDIR:=%s\n", cwd)
Fumitoshi Ukai65c72332015-06-26 21:32:50 +090052 return parseMakefileString(bootstrap, srcpos{bootstrapMakefileName, 0})
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090053}