prototype
This commit is contained in:
69
internal/target/darwin/template.go
Normal file
69
internal/target/darwin/template.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package darwin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
const makefileTemplate = `# Автогенерируемый Makefile
|
||||
FILES := {{.FILES}}
|
||||
RUNTIME := {{.RUNTIME}}
|
||||
TARGET := {{.TARGET}}
|
||||
|
||||
CC := clang
|
||||
CFLAGS := -I$(RUNTIME) -o3
|
||||
LDFLAGS := -lm -rdynamic
|
||||
|
||||
SRCS := $(FILES) \
|
||||
$(RUNTIME)/rt_api.c \
|
||||
$(RUNTIME)/rt_sysapi.c \
|
||||
$(RUNTIME)/rt_syscrash_linux.c
|
||||
|
||||
OUT := ../$(TARGET).exe
|
||||
|
||||
.PHONY: darwin-build clean
|
||||
|
||||
darwin-build:
|
||||
$(CC) $(SRCS) $(CFLAGS) $(LDFLAGS) -o $(OUT)
|
||||
|
||||
clean:
|
||||
rm -f $(OUT)
|
||||
|
||||
`
|
||||
|
||||
type Vars struct {
|
||||
FILES string
|
||||
RUNTIME string
|
||||
TARGET string
|
||||
}
|
||||
|
||||
func getCFilesInCurrentDir() (string, error) {
|
||||
files, err := ioutil.ReadDir("./_си")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var cFiles []string
|
||||
for _, f := range files {
|
||||
if !f.IsDir() && filepath.Ext(f.Name()) == ".c" {
|
||||
cFiles = append(cFiles, f.Name())
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(cFiles, " "), nil
|
||||
}
|
||||
|
||||
func renderMakefile(vars Vars) (string, error) {
|
||||
tmpl, err := template.New("makefile").Parse(makefileTemplate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := tmpl.Execute(&buf, vars); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user