Files
old_carga/internal/target/darwin/template.go
2025-08-20 21:15:35 +03:00

70 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}