1 // 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 15 package kati 16 17 import ( 18 "fmt" 19 "path/filepath" 20 "strings" 21 ) 22 23 const bootstrapMakefileName = "*bootstrap*" 24 25 func bootstrapMakefile(targets []string) (makefile, error) { 26 bootstrap := ` 27 CC?=cc 28 CXX?=g++ 29 AR?=ar 30 MAKE?=kati 31 # Pretend to be GNU make 3.81, for compatibility. 32 MAKE_VERSION?=3.81 33 KATI?=kati 34 SHELL=/bin/sh 35 # 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 { 49 return makefile{}, err 50 } 51 bootstrap += fmt.Sprintf("CURDIR:=%s\n", cwd) 52 return parseMakefileString(bootstrap, srcpos{bootstrapMakefileName, 0}) 53 } 54