prototype

This commit is contained in:
2025-08-20 21:15:35 +03:00
parent 598d516b57
commit 58414744ce
11 changed files with 390 additions and 0 deletions

View 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
}