-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile.OS4
92 lines (70 loc) · 3.48 KB
/
Makefile.OS4
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
# 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/os4/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)
# https://stackoverflow.com/questions/4036191/sources-from-subdirectories-in-makefile/4038459
# http://www.microhowto.info/howto/automatically_generate_makefile_dependencies.html
PROGRAM_NAME = AmigaGPT_OS4
EXECUTABLE_OUT = out/$(PROGRAM_NAME)
CC = ppc-amigaos-gcc
SDKLIBDIR = /tools/ppc-amigaos/SDK/lib
LIBDIR = /tools/ppc-amigaos/lib
SDKDIR = /tools/ppc-amigaos/SDK/include/include_h
NETINCDIR = /tools/ppc-amigaos/SDK/include/netinclude
INCDIR = /tools/ppc-amigaos/include
ifeq ($(OS),Darwin)
SED = sed -i ""
else
SED = sed -i
endif
CCFLAGS = -MP -MMD -Ofast -Wextra -Wno-unused-function -Wno-discarded-qualifiers -Wno-int-conversion -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -flto -fwhole-program -fno-exceptions -D__AMIGAOS4__ -D__USE_INLINE__ -DHAVE_VASPRINTF -DPROGRAM_NAME=\"$(PROGRAM_NAME)\"
CPPFLAGS= $(CCFLAGS) -fno-rtti -fcoroutines -fno-use-cxa-atexit
ASFLAGS = -Wa,-g,--register-prefix-optional,-I$(SDKDIR),-I$(NETINCDIR),-D
LDFLAGS = -Wl,-Map=$(EXECUTABLE_OUT).map,-L$(LIBDIR),-L$(SDKLIBDIR),-lm,-lamisslstubs,-ljson-c
VASMFLAGS = -Fhunk -opt-fconst -nowarn=62 -dwarf=3 -quiet -x -I. -D__AMIGAOS4__ -DPROGRAM_NAME=\"$(PROGRAM_NAME)\" -I$(NETINCDIR) -I$(SDKDIR)
.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) $(objects) -o $@ $(LDFLAGS)
clean:
$(info Cleaning...)
@$(RM) -f $(EXECUTABLE_OUT)
@$(RM) $(BUILD_DIR)*
-include $(objects:.o=.d)
$(cpp_objects) : build/os4/obj/%.o : %.cpp | build/os4/obj/%.dir
$(info Compiling $<)
$(CC) $(CPPFLAGS) -c -o $@ $(CURDIR)/$<
$(c_objects) : build/os4/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/os4/obj/%.o : %.s |$(BUILD_DIR)
$(info Assembling $<)
$(CC) $(CCFLAGS) $(ASFLAGS) -c -o $@ $(CURDIR)/$<
$(vasm_objects): build/os4/obj/%.o : %.asm | $(BUILD_DIR)
$(info Assembling $<)
$(VASM) $(VASMFLAGS) -o $@ $(CURDIR)/$<
copy_bundle_files:
$(info Copying bundle files...)
mkdir -p out
cp assets/AmigaGPT_OS4.info bundle/AmigaGPT/$(PROGRAM_NAME).info
cp -R bundle/AmigaGPT/* out/