-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
99 lines (88 loc) · 2.55 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
PROJECTNAME=ez80asm
ARCHITECTURE=linux_elf_x86_64
BUILD_WINDOWS=false
# Tools and arguments
MSBUILD='/mnt/c/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/MSBuild.exe'
MSBUILDFLAGS=/property:Configuration=Release
CC=gcc
LFLAGS=-g -Wall -DUNIX
CFLAGS=$(LFLAGS) -c
OUTFLAG=-o
RELEASE_LFLAGS=-s -static -Wall -O2 -DNDEBUG -DUNIX -Wno-unused-result
RELEASE_CFLAGS=$(RELEASE_LFLAGS) -c
.DEFAULT_GOAL := linux
# project directories
SRCDIR=src
OBJDIR=obj
BINDIR=bin
LOADERDIR=mosloader
RELEASEDIR=releases
VSPROJECTDIR=$(SRCDIR)/vsproject
VSPROJECTBINDIR=$(VSPROJECTDIR)/x64/Release
# Automatically get all sourcefiles
SRCS=$(wildcard $(SRCDIR)/*.c)
# Automatically get all objects to make from sources
OBJS=$(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRCS))
# Target project binary
BIN=$(BINDIR)/$(PROJECTNAME)
# Default rule
all: linux agon windows
linux: $(BINDIR) $(OBJDIR) $(BIN)
windows:
ifeq ($(BUILD_WINDOWS), true)
@$(MSBUILD) $(VSPROJECTDIR)/$(PROJECTNAME).sln $(MSBUILDFLAGS)
else
@echo === Windows build disabled in makefile
endif
agon:
@echo === Compiling Agon target
@make --file=Makefile-agon --no-print-directory
# Release with optimal settings for release target
release: CFLAGS=$(RELEASE_CFLAGS)
release: LFLAGS=$(RELEASE_LFLAGS)
release: all
release: $(RELEASEDIR)
release: package
# Linking all compiled objects into final binary
$(BIN):$(OBJS)
@echo === Linking Linux target
ifeq ($(CC),gcc)
$(CC) $(LFLAGS) $(OBJS) $(OUTFLAG) $@
else
$(LINKER) $(LINKERFLAGS)$@ $(OBJS)
endif
# Compile each .c file into .o file
$(OBJDIR)/%.o: $(SRCDIR)/%.c
ifeq ($(CC),gcc)
$(CC) $(CFLAGS) $< $(OUTFLAG) $@
else
$(CC) $(CFLAGS)$@ $<
endif
$(BINDIR):
mkdir $(BINDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(RELEASEDIR):
mkdir $(RELEASEDIR)
package:
@echo === Packaging binaries
@tar -zcvf $(RELEASEDIR)/$(PROJECTNAME)_$(ARCHITECTURE).gz $(BINDIR)/$(PROJECTNAME)
@cp $(BINDIR)/$(PROJECTNAME).bin $(RELEASEDIR)/$(PROJECTNAME).bin
ifeq ($(BUILD_WINDOWS), true)
@cp $(VSPROJECTBINDIR)/$(PROJECTNAME).exe $(RELEASEDIR)/
endif
clean:
@echo Cleaning directories
@find tests -name "*.output" -type f -delete
ifeq ($(BUILD_WINDOWS), true)
@$(MSBUILD) $(VSPROJECTDIR)/$(PROJECTNAME).sln $(MSBUILDFLAGS) -t:Clean >/dev/null
endif
ifdef OS
del /s /q $(BINDIR) >nul 2>&1
del /s /q $(OBJDIR) >nul 2>&1
del /s /q $(RELEASEDIR) >nul 2>&1
del /s /q $(LOADERDIR)/$(PROJECTNAME).bin
else
@$(RM) -r $(BINDIR) $(OBJDIR) $(RELEASEDIR)
@$(RM) $(LOADERDIR)/$(PROJECTNAME).bin
endif