-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
190 lines (166 loc) · 7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# Platform-specific variables
# RANDOM_FILE
# GREP
# OPEN
# rmrf <path>
# mkdir <path>
# fetch <url> <output-file>
# xzip <zip-file> <destination-dir>
# cp <source> <destination>
# gen_debug_args <dll> <cwd> <args>s
# open <url>
ifeq ($(OS),Windows_NT)
SHELL := pwsh.exe
.SHELLFLAGS := -NoProfile -Command
RANDOM_FILE := $(shell pwsh -c "Write-Host $$(New-TemporaryFile)")
GREP := findstr
OPEN := Start-Process
define rmrf
if (Test-Path $(1)) { Remove-Item -Recurse -Force -Path $(1) }
endef
define mkdir
New-Item -ItemType Directory -Force -Path $(1) | Out-Null
endef
define fetch
Invoke-WebRequest -Uri $(1) -OutFile $(2)
endef
define xzip
Expand-Archive -Path $(1) -DestinationPath $(2)
endef
define cp
Copy-Item -Path $(1) -Destination $(2)
endef
define gen_debug_args
$(shell pwsh .scripts/gen_debug_args.ps1 $(1) $(2) $(3))
endef
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
RANDOM_FILE := $(shell mktemp)
GREP := grep
OPEN := open
define rmrf
if [ -e $(1) ]; then rm -rf $(1); fi
endef
define mkdir
mkdir -p $(1)
endef
define fetch
curl -L -o $(2) $(1)
endef
define xzip
unzip -qq -o $(1) -d $(2)
endef
define cp
cp $(1) $(2)
endef
define gen_debug_args
$(shell .scripts/gen_debug_args.sh $(1) $(2) $(3))
endef
else
# TODO: Linux support for makefile
endif
endif
# DOTGLFW VERSION
DOTGLFW_VERSION := 1.2.0
# VERSION OF GLFW TO DOWNLOAD
GLFW_VERSION := 3.4
# BUILD STUFF
TMP_DIR := .tmp
RUNTIMEFOLDER_WINX64 := DotGLFW/runtimes/win-x64/native
RUNTIMEFOLDER_WINX86 := DotGLFW/runtimes/win-x86/native
RUNTIMEFOLDER_OSXX64 := DotGLFW/runtimes/osx-x64/native
RUNTIMEFOLDER_OSXARM64 := DotGLFW/runtimes/osx-arm64/native
NUPKGFILE := nupkg/DotGLFW.$(DOTGLFW_VERSION).nupkg
# call download_zip_and_extract_file,<url>,<path-inside-zip-to-file>,<destination-dir>,<output-file-name>
define download_zip_and_extract_file
@echo "Downloading $(1)"
@${call mkdir,"$(3)"}
@${call rmrf,"$(3)/$(4)"}
@${call fetch,"$(1)","$(RANDOM_FILE)"}
@${call xzip,"$(RANDOM_FILE)","$(TMP_DIR)"}
@${call cp,"$(TMP_DIR)/$(2)","$(3)/$(4)"}
@${call rmrf,"$(RANDOM_FILE)"}
@${call rmrf,"$(TMP_DIR)"}
@echo "Downloaded $(3)/$(4)"
endef
.PHONY: clean
clean:
@echo "Cleaning DotGLFW"
@${call rmrf,./.glfw}
@${call rmrf,./publish}
@${call rmrf,./nupkg}
@${call rmrf,./bin}
@${call rmrf,./obj}
@${call rmrf,./DotGLFW/bin}
@${call rmrf,./DotGLFW/obj}
@${call rmrf,./DotGLFW/Generated}
@${call rmrf,./DotGLFW/runtimes}
@${call rmrf,./DotGLFW.LocalExample/bin}
@${call rmrf,./DotGLFW.LocalExample/obj}
@${call rmrf,./DotGLFW.NugetExample/bin}
@${call rmrf,./DotGLFW.NugetExample/obj}
@${call rmrf,./DotGLFW.NugetAotExample/bin}
@${call rmrf,./DotGLFW.NugetAotExample/obj}
@${call rmrf,./DotGLFW.Generator/bin}
@${call rmrf,./DotGLFW.Generator/obj}
.PHONY: publish-aot
publish-aot: $(NUPKGFILE)
dotnet publish DotGLFW.NugetAotExample/DotGLFW.NugetAotExample.csproj -c Release -p:PublishTrimmed=true -p:PublishReadyToRun=true
.PHONY: run-local
run-local: $(NUPKGFILE)
dotnet run --project DotGLFW.LocalExample/DotGLFW.LocalExample.csproj
.PHONY: run-nuget
run-nuget: $(NUPKGFILE)
dotnet run --project DotGLFW.NugetExample/DotGLFW.NugetExample.csproj
.PHONY: debug-local
LOCAL_EXAMPLE_DLL := DotGLFW.LocalExample/bin/Debug/net8.0/DotGLFW.LocalExample.dll
debug-local: $(NUPKGFILE)
dotnet build DotGLFW.LocalExample/DotGLFW.LocalExample.csproj -c Debug
@$(OPEN) "vscode-insiders://fabiospampinato.vscode-debug-launcher/launch?args=$(call gen_debug_args,$(LOCAL_EXAMPLE_DLL),.,'[]')"
.PHONY: debug-nuget
debug-nuget: $(NUPKGFILE)
dotnet build DotGLFW.Example/DotGLFW.Example.csproj -c Debug
@$(OPEN) "vscode-insiders://fabiospampinato.vscode-debug-launcher/launch?args=$(call gen_debug_args,$(EXAMPLE_DLL),.,'[]')"
.PHONY: run-generator
run-generator: DotGLFW/Generated
.PHONY: debug-generator
GENERATOR_DEBUG_DLL := DotGLFW.Generator/bin/Debug/net8.0/DotGLFW.Generator.dll
debug-generator:
dotnet build DotGLFW.Generator/DotGLFW.Generator.csproj -c Debug
@$(OPEN) "vscode-insiders://fabiospampinato.vscode-debug-launcher/launch?args=$(call gen_debug_args,$(GENERATOR_DEBUG_DLL),.,'[]')"
.PHONY: pack
pack: $(NUPKGFILE)
GENERATOR_SOURCES := $(wildcard DotGLFW.Generator/*.cs) $(wildcard DotGLFW.Generator/Generation/*.cs) $(wildcard DotGLFW.Generator/Model/*.cs) $(wildcard DotGLFW.Generator/Parsing/*.cs) DotGLFW.Generator/DotGLFW.Generator.csproj
DotGLFW/Generated: .glfw/glfw-$(GLFW_VERSION) $(GENERATOR_SOURCES)
dotnet run --project DotGLFW.Generator/DotGLFW.Generator.csproj -- .glfw/glfw-$(GLFW_VERSION) DotGLFW/Generated LICENSE "https://www.glfw.org/docs/3.4/"
.glfw/glfw-%:
@echo "Downloading GLFW $* from https://github.com/glfw/glfw/releases/download/$*/glfw-$*.zip"
@${call mkdir,".glfw"}
@${call fetch,"https://github.com/glfw/glfw/releases/download/$*/glfw-$*.zip",".glfw/glfw-$*.zip"}
@${call xzip,".glfw/glfw-$*.zip",".glfw"}
@${call rmrf,".glfw/glfw-$*.zip"}
# NuGet package
DOTGLFW_SOURCES := DotGLFW/Generated $(wildcard DotGLFW/Generated/*.cs) $(wildcard DotGLFW/GLFW/*.cs) DotGLFW/DotGLFW.csproj
$(NUPKGFILE): $(RUNTIMEFOLDER_WINX64)/glfw3.dll $(RUNTIMEFOLDER_WINX86)/glfw3.dll $(RUNTIMEFOLDER_OSXX64)/libglfw3.dylib $(RUNTIMEFOLDER_OSXARM64)/libglfw3.dylib $(DOTGLFW_SOURCES)
@echo "Packing DotGLFW $(DOTGLFW_VERSION) into nupkg/DotGLFW.$(DOTGLFW_VERSION).nupkg"
dotnet pack -c Release DotGLFW -o ./nupkg -p:PackageVersion=$(DOTGLFW_VERSION) -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
@dotnet nuget locals all --clear
@dotnet restore DotGLFW.sln
# Native dependencies + download
WINX64_URL := https://github.com/glfw/glfw/releases/download/$(GLFW_VERSION)/glfw-$(GLFW_VERSION).bin.WIN64.zip
WINX64_DLL_IN_ZIP := glfw-$(GLFW_VERSION).bin.WIN64/lib-vc2022/glfw3.dll
$(RUNTIMEFOLDER_WINX64)/glfw3.dll:
$(call download_zip_and_extract_file,$(WINX64_URL),$(WINX64_DLL_IN_ZIP),$(RUNTIMEFOLDER_WINX64),glfw3.dll)
WINX86_URL := https://github.com/glfw/glfw/releases/download/$(GLFW_VERSION)/glfw-$(GLFW_VERSION).bin.WIN32.zip
WINX86_DLL_IN_ZIP := glfw-$(GLFW_VERSION).bin.WIN32/lib-vc2022/glfw3.dll
$(RUNTIMEFOLDER_WINX86)/glfw3.dll:
$(call download_zip_and_extract_file,$(WINX86_URL),$(WINX86_DLL_IN_ZIP),$(RUNTIMEFOLDER_WINX86),glfw3.dll)
OSX64_URL := https://github.com/glfw/glfw/releases/download/$(GLFW_VERSION)/glfw-$(GLFW_VERSION).bin.MACOS.zip
OSX64_DYLIB_IN_ZIP := glfw-$(GLFW_VERSION).bin.MACOS/lib-universal/libglfw.3.dylib
$(RUNTIMEFOLDER_OSXX64)/libglfw3.dylib:
$(call download_zip_and_extract_file,$(OSX64_URL),$(OSX64_DYLIB_IN_ZIP),$(RUNTIMEFOLDER_OSXX64),libglfw3.dylib)
OSXARM64_URL := https://github.com/glfw/glfw/releases/download/$(GLFW_VERSION)/glfw-$(GLFW_VERSION).bin.MACOS.zip
OSXARM64_DYLIB_IN_ZIP := glfw-$(GLFW_VERSION).bin.MACOS/lib-arm64/libglfw.3.dylib
$(RUNTIMEFOLDER_OSXARM64)/libglfw3.dylib:
$(call download_zip_and_extract_file,$(OSXARM64_URL),$(OSXARM64_DYLIB_IN_ZIP),$(RUNTIMEFOLDER_OSXARM64),libglfw3.dylib)