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 := ` |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 27 | CC?=cc |
| 28 | CXX?=g++ |
| 29 | AR?=ar |
| 30 | MAKE?=kati |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 31 | # Pretend to be GNU make 3.81, for compatibility. |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 32 | MAKE_VERSION?=3.81 |
Shinichiro Hamaji | cdcd419 | 2015-09-04 10:06:30 +0900 | [diff] [blame] | 33 | KATI?=kati |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 34 | SHELL=/bin/sh |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 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 { |
Fumitoshi Ukai | 65c7233 | 2015-06-26 21:32:50 +0900 | [diff] [blame] | 49 | return makefile{}, err |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 50 | } |
| 51 | bootstrap += fmt.Sprintf("CURDIR:=%s\n", cwd) |
Fumitoshi Ukai | 65c7233 | 2015-06-26 21:32:50 +0900 | [diff] [blame] | 52 | return parseMakefileString(bootstrap, srcpos{bootstrapMakefileName, 0}) |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 53 | } |