This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
187 lines (145 loc) · 4.67 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
ifndef CC
CC = gcc
endif
BASE_CFLAGS = --std=c99 -Wall -Wextra -flto -O3 -mtune=generic -lm -lreadline -funsigned-char
ifndef OS
CFLAGS = $(BASE_CFLAGS) -ldl
ifeq ($(shell uname -s), Darwin)
ifeq ($(shell [ -d ~/.brew/opt/readline/include ] && echo true), true)
CFLAGS += -I~/.brew/opt/readline/include
endif
ifeq ($(shell [ -d /opt/homebrew/opt/readline/include ] && echo true), true)
CFLAGS += -I/opt/homebrew/opt/readline/include
endif
ifeq ($(shell [ -d /usr/local/opt/readline/include ] && echo true), true)
CFLAGS += -I/usr/local/opt/readline/include
endif
ifeq ($(shell [ -d ~/.brew/opt/readline/lib ] && echo true), true)
CFLAGS += -L~/.brew/opt/readline/lib
endif
ifeq ($(shell [ -d /opt/homebrew/opt/readline/lib ] && echo true), true)
CFLAGS += -L/opt/homebrew/opt/readline/lib
endif
ifeq ($(shell [ -d /usr/local/opt/readline/lib ] && echo true), true)
CFLAGS += -L/usr/local/opt/readline/lib
endif
else
ifeq ($(shell uname -o), Android)
CFLAGS += -s
else
CFLAGS += -s -no-pie
endif
endif
CBITS = $(shell getconf LONG_BIT)
BUILD_TO = clibasic
BUILD32 = $(CC) clibasic.c -m32 $(CFLAGS) -DB32 -o $(BUILD_TO) && chmod +x $(BUILD_TO)
ifeq (,$(CBITS))
BUILD__ = $(BUILD32)
else
BUILD__ = $(CC) clibasic.c $(CFLAGS) -DB$(CBITS) -o $(BUILD_TO) && chmod +x $(BUILD_TO)
endif
MAN_PATH = docs/clibasic.man
ifeq ($(shell id -u), 0)
MAN_INSTALL_PATH = /usr/share/man/man1/clibasic.1
INSTALL_TO = /usr/bin/clibasic
else
MAN_INSTALL_PATH = ~/.local/share/man/man1/clibasic.1
INSTALL_TO = ~/.local/bin/clibasic
endif
INSTALL = mkdir -p $(shell dirname -- $(INSTALL_TO)) $(shell dirname -- $(MAN_INSTALL_PATH)); cp $(BUILD_TO) $(INSTALL_TO);\
if [ -f $(MAN_PATH) ]; then cp $(MAN_PATH) $(MAN_INSTALL_PATH); gzip -f $(MAN_INSTALL_PATH); fi
UNINSTALL = rm -f $(INSTALL_TO) $(MAN_INSTALL_PATH).gz
RUN = ./$(BUILD_TO)
CLEAN = rm -f clibasic
.ONESHELL:
.PHONY: all all32 build build32 update install install32 run clean cross
all: clean build run
all32: clean build32 run
build:
$(BUILD__)
build32:
$(BUILD32)
update:
printf "\\e[0m\\e[31;1mAre you sure? [y/N]:\\e[0m "; read -n 1 I; [ ! "$$I" == "" ] && printf "\\n" &&\
([[ ! "$$I" =~ ^[^Yy]$$ ]] && sh -c 'git restore . && git pull' &> /dev/null && chmod +x *.sh) || exit 0
install: uninstall
if [ ! -f $(BUILD_TO) ]; then $(BUILD__); fi
$(INSTALL)
install32:
if [ ! -f $(BUILD_TO) ]; then $(BUILD32); fi
$(INSTALL)
uninstall:
$(UNINSTALL)
run:
ifeq (32,$(CBITS))
[ ! -f "$(BUILD_TO)" ] && ($(BUILD32))
else
[ ! -f "$(BUILD_TO)" ] && ($(BUILD__))
endif
$(RUN)
clean:
$(CLEAN)
cross:
ifeq ($(MAKECMDGOALS), cross)
@$(MAKE) cross all
else
@$(eval CC = x86_64-w64-mingw32-gcc)
@$(eval C32 = i686-w64-mingw32-gcc)
@$(eval CFLAGS = $(BASE_CFLAGS) -s -Ilib)
@$(eval BUILD_TO = clibasic.exe)
@$(eval INSTALL_TO = "$$HOME/.wine/drive_c/windows/system32/")
@$(eval INSTALL = cp $(BUILD_TO) *.dll $(INSTALL_TO))
@$(eval BUILD32 = cp -f lib/win32/*.dll . && $(C32) clibasic.c -m32 $(CFLAGS) -Llib/win32 -DB32 -o $(BUILD_TO) && chmod -x $(BUILD_TO))
ifeq (,$(CBITS))
@$(eval BUILD__ = $(BUILD32))
else
@$(eval BUILD__ = cp -f lib/win64/*.dll . && $(CC) clibasic.c $(CFLAGS) -Llib/win64 -DB$(CBITS) -o $(BUILD_TO) && chmod -x $(BUILD_TO))
endif
@$(eval RUN = wineconsole .\\$(BUILD_TO))
@$(eval CLEAN = rm -f clibasic.exe *.dll)
endif
@true
vt:
@$(eval CFLAGS = $(CFLAGS) -DFORCE_VT)
@$(eval BUILD32 = cp -f lib/win32/*.dll . && $(C32) clibasic.c -m32 $(CFLAGS) -Llib/win32 -DB32 -o $(BUILD_TO) && chmod -x $(BUILD_TO))
ifeq (,$(CBITS))
@$(eval BUILD__ = $(BUILD32))
else
@$(eval BUILD__ = cp -f lib/win64/*.dll . && $(CC) clibasic.c $(CFLAGS) -Llib/win64 -DB$(CBITS) -o $(BUILD_TO) && chmod -x $(BUILD_TO))
endif
@true
else
CFLAGS = $(BASE_CFLAGS) -lpthread -Ilib -s -D_CRT_NONSTDC_NO_WARNINGS
BUILD_TO = clibasic.exe
BUILD64 = xcopy lib\win64\*.dll . /Y && $(CC) clibasic.c -m64 $(CFLAGS) -Llib\win64 -DB64 -o $(BUILD_TO)
BUILD32 = xcopy lib\win32\*.dll . /Y && $(CC) clibasic.c -m32 $(CFLAGS) -Llib\win32 -DB32 -o $(BUILD_TO)
INSTALL_TO = C:\windows\system32
INSTALL = xcopy *.dll $(INSTALL_TO) /Y && xcopy $(BUILD_TO) $(INSTALL_TO) /Y
UNINSTALL = del $(INSTALL_TO)\\$(BUILD_TO)
.PHONY: all all32 build build32 update run clean
all: clean build run
all32: clean build32 run
build:
$(BUILD64)
build32:
$(BUILD32)
update:
git restore . & git pull
install:
$(BUILD64)
$(INSTALL)
install32:
$(BUILD32)
$(INSTALL)
run:
.\\$(BUILD_TO)
clean:
del /q /f $(BUILD_TO) *.dll
vt:
ifeq ($(MAKECMDGOALS), vt)
@$(MAKE) vt all
else
@$(eval CFLAGS = $(CFLAGS) -DFORCE_VT)
endif
@echo > nul
endif