-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
98 lines (79 loc) · 3.95 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
# to generate assembler listing with LTO, add to LDFLAGS: -Wa,[email protected],--listing-rhs-width=200
# for better annotations add -dA -dP
# to generate assembler source with LTO, add to LDFLAGS: -save-temps=cwd
OS := $(shell uname)
subdirs := $(wildcard */) $(wildcard src/*/) $(wildcard src/*/*/)
VPATH = $(subdirs)
BUILD_DIR := build/os3/obj/
cpp_sources := $(wildcard *.cpp) $(wildcard $(addsuffix *.cpp,$(subdirs)))
cpp_objects := $(addprefix $(BUILD_DIR),$(patsubst %.cpp,%.o,$(notdir $(cpp_sources))))
c_sources := $(wildcard *.c) $(wildcard $(addsuffix *.c,$(subdirs)))
c_sources := $(filter-out src/test/%, $(c_sources))
c_objects := $(addprefix $(BUILD_DIR),$(patsubst %.c,%.o,$(notdir $(c_sources))))
s_sources := $(wildcard *.s) $(wildcard $(addsuffix *.s,$(subdirs)))
s_objects := $(addprefix $(BUILD_DIR),$(patsubst %.s,%.o,$(notdir $(s_sources))))
vasm_sources := $(wildcard *.asm) $(wildcard $(addsuffix *.asm, $(subdirs)))
vasm_objects := $(addprefix $(BUILD_DIR), $(patsubst %.asm,%.o,$(notdir $(vasm_sources))))
objects := $(cpp_objects) $(c_objects) $(s_objects) $(vasm_objects)
AUTOGEN_FILE := src/version.h
AUTOGEN_NEXT := $(shell expr $$(awk '/#define BUILD_NUMBER/' $(AUTOGEN_FILE) | tr -cd "[0-9]") + 1)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_TIMESTAMP := $(shell git log -1 --format=%cd --date=format:"%Y-%m-%d~%H:%M:%S")
# https://stackoverflow.com/questions/4036191/sources-from-subdirectories-in-makefile/4038459
# http://www.microhowto.info/howto/automatically_generate_makefile_dependencies.html
PROGRAM_NAME = AmigaGPT
EXECUTABLE_OUT = out/$(PROGRAM_NAME)
CC = m68k-amigaos-gcc
VASM = vasmm68k_mot
LIBDIR = /opt/amiga/m68k-amigaos/lib
SDKDIR = /opt/amiga/m68k-amigaos/sys-include
NDKDIR = /opt/amiga/m68k-amigaos/ndk-include
INCDIR = /opt/amiga/m68k-amigaos/include
ifeq ($(OS),Darwin)
SED = sed -i ""
else
SED = sed -i
endif
CCFLAGS = -MP -MMD -m68020 -Wextra -Wno-unused-function -Wno-discarded-qualifiers -Wno-int-conversion -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -fno-exceptions -noixemul -fbaserel -lamiga -lm -lamisslstubs -lmui -D__AMIGAOS3__ -DPROGRAM_NAME=\"$(PROGRAM_NAME)\" -DGIT_BRANCH=\"$(GIT_BRANCH)\" -DGIT_COMMIT=\"$(GIT_COMMIT)\" -DGIT_TIMESTAMP=\"$(GIT_TIMESTAMP)\"
ifeq ($(DEBUG),1)
CCFLAGS += -DPROGDIR=\"OUT:\" -DDEBUG -g -O0
else
# Writing to disk crashes inside hooks in anything higher than -O1
CCFLAGS += -DPROGDIR=\"PROGDIR:\" -O1
endif
CPPFLAGS= $(CCFLAGS) -fno-rtti -fcoroutines -fno-use-cxa-atexit
ASFLAGS = -Wa,-g,--register-prefix-optional,-I$(SDKDIR),-I$(NDKDIR),-I$(INCDIR),-D
LDFLAGS = -Wl,-Map=$(EXECUTABLE_OUT).map,-L$(LIBDIR),-lamiga,-lm,-lamisslstubs,-ljson-c,-lmui
VASMFLAGS = -m68020 -Fhunk -opt-fconst -nowarn=62 -dwarf=3 -quiet -x -I. -D__AMIGAOS3__ -DPROGRAM_NAME=\"$(PROGRAM_NAME)\" -I$(INCDIR) -I$(SDKDIR) -I$(NDKDIR)
.PHONY: all clean copy_bundle_files
all: copy_bundle_files $(EXECUTABLE_OUT)
$(BUILD_DIR):
@$(info Creating directory $@)
@mkdir -p $@
$(EXECUTABLE_OUT): $(objects)
$(info Linking $(PROGRAM_NAME))
$(CC) $(CCFLAGS) $(LDFLAGS) $(objects) -o $@ $(LDFLAGS)
clean:
$(info Cleaning...)
@$(RM) -f $(EXECUTABLE_OUT)
@$(RM) $(BUILD_DIR)*
-include $(objects:.o=.d)
$(cpp_objects) : build/os3/obj/%.o : %.cpp | build/os3/obj/%.dir
$(info Compiling $<)
$(CC) $(CPPFLAGS) -c -o $@ $(CURDIR)/$<
$(c_objects) : build/os3/obj/%.o : %.c | $(BUILD_DIR)
$(info Compiling $<)
$(SED) 's|#define BUILD_NUMBER ".*"|#define BUILD_NUMBER "$(AUTOGEN_NEXT)"|' $(AUTOGEN_FILE)
$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$<
$(s_objects): build/os3/obj/%.o : %.s |$(BUILD_DIR)
$(info Assembling $<)
$(CC) $(CCFLAGS) $(ASFLAGS) -c -o $@ $(CURDIR)/$<
$(vasm_objects): build/os3/obj/%.o : %.asm | $(BUILD_DIR)
$(info Assembling $<)
$(VASM) $(VASMFLAGS) -o $@ $(CURDIR)/$<
copy_bundle_files:
$(info Copying bundle files...)
mkdir -p out
cp assets/AmigaGPT_OS3.info bundle/$(PROGRAM_NAME)/$(PROGRAM_NAME).info
cp -R bundle/$(PROGRAM_NAME)/* out/