Created
December 5, 2025 22:55
-
-
Save GamerGirlandCo/79017993d49d20b47a8a61f20fd6e59b to your computer and use it in GitHub Desktop.
worst makefile ever (not clickbait)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .ONESHELL: | |
| SHELL = bash | |
| override PARTS := backend frontend | |
| override PREFIX.INTERNAL := _______ | |
| override GO := go | |
| override DOCKER := docker | |
| override REPO := xxx | |
| override REGISTRY := xxx.xxx.xxx | |
| override IMAGE_NAME := $(REGISTRY)/$(REPO) | |
| override DOCKER_BASE_BUILD_ARGS := --build-context root=${CURDIR} --progress=plain | |
| override BACKEND.SUBDIRS := $(shell find backend -type d) | |
| override BACKEND.ROUTE_DIRS := $(shell find backend/routes/api -type d) | |
| override BACKEND.SRC := $(foreach dir,$(BACKEND.SUBDIRS),$(wildcard $(dir)/*.go)) | |
| override BACKEND.ROUTES_SRC := $(foreach dir,$(BACKEND.ROUTE_DIRS),$(wildcard $(dir)/*.go)) | |
| override BACKEND.BASE_FLAGS := -tags 'goexperiment.jsonv2' | |
| override backend := $(BACKEND.SRC) | |
| override frontend := $(PREFIX.INTERNAL)zod-defs | |
| override zod_defs := $(PREFIX.INTERNAL)openapi-spec | |
| override openapi_spec := $(BACKEND.ROUTES_SRC) | |
| override frontend_image := $(PREFIX.INTERNAL)frontend | |
| override backend_image := $(BACKEND.SRC) | |
| override push := $(PREFIX.INTERNAL)backend-image $(PREFIX.INTERNAL)frontend-image | |
| define GET_RULE_TYPE | |
| $(strip $(shell if [[ "$(strip $(1))" =~ ^(openapi|zod) ]]; then echo "frontend/"; elif [[ "$(1)" =~ (image$$|push) ]]; then echo "docker/"; fi)) | |
| endef | |
| define FAKE_DEP | |
| $(strip .artifacts/$(strip $(call GET_RULE_TYPE,$(strip $(1))))$(strip $(1)).make-evidence) | |
| endef | |
| define STRIP_PREFIX | |
| $(strip $(shell echo $(1) | sed 's/^$(PREFIX.INTERNAL)//')) | |
| endef | |
| define FACADE | |
| $(call FAKE_DEP,$(call STRIP_PREFIX,$(1))): $(foreach el,$($(subst -,_,$(call STRIP_PREFIX,$(1)))),$(if $(call IS_TARGET,$(el)),$(call FAKE_DEP,$(call STRIP_PREFIX,$(el))),$(el))) | |
| $(MAKE) -f Makefile.fucked $(1) | |
| mkdir -p $$(dir $$@) || true | |
| @echo $$@ | |
| touch $$@ | |
| $(call STRIP_PREFIX,$(1)): $(call FAKE_DEP,$(call STRIP_PREFIX,$(1))) | |
| endef | |
| define IS_TARGET | |
| $(if $(findstring $(PREFIX.INTERNAL),$(1)),true,) | |
| endef | |
| define CREATE_IMAGE_BUILD_CMD | |
| $(DOCKER) build $(DOCKER_BASE_BUILD_ARGS) -f $(call STRIP_PREFIX,$(1))/Dockerfile -t ${IMAGE_NAME}/$(call STRIP_PREFIX,$(1)):latest -t ${IMAGE_NAME}/$(call STRIP_PREFIX,$(1)):snapshot-$(shell date +'%s') . ; | |
| endef | |
| .PHONY: help | |
| help: | |
| echo there''s no help, there''s no hope... | |
| ### actual targets ### | |
| $(PREFIX.INTERNAL)backend: | |
| cd backend; \ | |
| mkdir -p ./bin; \ | |
| go build $(BACKEND.BASE_FLAGS) -o ./bin/main.exe . | |
| $(PREFIX.INTERNAL)frontend: | |
| @echo -n | |
| $(PREFIX.INTERNAL)openapi-spec: | |
| cd backend; \ | |
| go run $(BACKEND.BASE_FLAGS) . .. oapi-spec.json; \ | |
| cd ..; \ | |
| mv -f oapi-spec.json frontend/ | |
| $(PREFIX.INTERNAL)zod-defs: | |
| bun frontend/scripts/generate-zod-bodies.ts | |
| ### docker ### | |
| $(PARTS:%=prune-%): prune-%: | |
| python tools/registry.py -r https://$(REGISTRY) -i celtrackr/$* --delete --num 10 | |
| $(PREFIX.INTERNAL)frontend-image: | |
| $(call CREATE_IMAGE_BUILD_CMD,frontend,$@) | |
| $(PREFIX.INTERNAL)backend-image: | |
| $(call CREATE_IMAGE_BUILD_CMD,backend,$@) | |
| $(PREFIX.INTERNAL)push: | |
| $(DOCKER) push --all-tags $(IMAGE_NAME)/frontend | |
| $(DOCKER) push --all-tags $(IMAGE_NAME)/backend | |
| ### shit ### | |
| %.go: .artifacts/%.make-evidence | |
| $(shell echo -n) | |
| .artifacts/%.make-evidence: | |
| mkdir -p $(dir $@) || true | |
| @echo $@ | |
| touch $@ | |
| ifndef $(LOWER) | |
| $(info hi) | |
| override els := $(shell LOWER="LOWER" make -f Makefile.fucked -qp | awk -F':' '/^[a-zA-Z0-9_][^$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | grep -Ei '^__' | sort -u) | |
| $(foreach el,$(els),$(eval $(call FACADE,$(el)))) | |
| endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment