Lindenii Project Forge
Login
Commit info
IDed4a8f9068a2a880280954db7f9424bbdc1dee5a
AuthorRunxi Yu<me@runxiyu.org>
Author dateMon, 17 Feb 2025 02:03:37 +0800
CommitterRunxi Yu<me@runxiyu.org>
Committer dateMon, 17 Feb 2025 02:03:37 +0800
Actions
Get patch
*: Restructure build system
.PHONY: clean version.go

forge: $(filter-out forge,$(wildcard *)) version.go
CFLAGS = -Wall -Wextra -Werror -pedantic -std=c99 -D_GNU_SOURCE

forge: $(filter-out forge,$(wildcard *)) version.go git_hooks_client/*.c git_hooks_client/git_hooks_client
	go mod vendor
	go build -o $@

git_hooks_client/git_hooks_client:

version.go:
	printf 'package main\nconst VERSION="%s"\n' $(shell git describe --tags --long --always --dirty) > $@

clean:
	$(RM) forge version.go vendor

CFLAGS = -Wall -Wextra -Werror -pedantic -std=c99 -D_GNU_SOURCE

git_hooks_client:
package main

import (
	"embed"
	"html/template"
	"io/fs"
	"net/http"
)

//go:embed .gitignore .gitattributes
//go:embed LICENSE README.md
//go:embed *.go go.mod go.sum
//go:embed *.scfg
//go:embed Makefile
//go:embed schema.sql
//go:embed static/* templates/*
//go:embed git_hooks_client/*
//go:embed git_hooks_client/*.c
//go:embed vendor/*
var source_fs embed.FS

var source_handler http.Handler

func init() {
	source_handler = http.StripPrefix(
		"/:/source/",
		http.FileServer(http.FS(source_fs)),
	)
}

//go:embed templates/* static/*
//go:embed templates/* static/* git_hooks_client/git_hooks_client
var resources_fs embed.FS

var templates *template.Template

func load_templates() (err error) {
	templates, err = template.New("templates").Funcs(template.FuncMap{
		"first_line": first_line,
		"base_name":  base_name,
	}).ParseFS(resources_fs, "templates/*")
	return err
}

var static_handler http.Handler

func init() {
	static_fs, err := fs.Sub(resources_fs, "static")
	if err != nil {
		panic(err)
	}
	static_handler = http.StripPrefix("/:/static/", http.FileServer(http.FS(static_fs)))
}