Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 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 | |
Fumitoshi Ukai | 65c7233 | 2015-06-26 21:32:50 +0900 | [diff] [blame^] | 25 | func bootstrapMakefile(targets []string) (makefile, error) { |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 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 | SHELL:=/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 Ukai | 65c7233 | 2015-06-26 21:32:50 +0900 | [diff] [blame^] | 48 | return makefile{}, err |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 49 | } |
| 50 | bootstrap += fmt.Sprintf("CURDIR:=%s\n", cwd) |
Fumitoshi Ukai | 65c7233 | 2015-06-26 21:32:50 +0900 | [diff] [blame^] | 51 | return parseMakefileString(bootstrap, srcpos{bootstrapMakefileName, 0}) |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 52 | } |