-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile.MorphOS
144 lines (114 loc) · 5.54 KB
/
Makefile.MorphOS
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
# 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)
# 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_DIR = out
EXECUTABLE_OUT = $(EXECUTABLE_DIR)/$(PROGRAM_NAME)_MorphOS
CC = ppc-morphos-gcc
SDKLIBDIR = /opt/amiga/ppc-morphos/lib
LIBDIR = /opt/amiga/lib
SDKDIR = /opt/amiga/os-include
NETINCDIR = /opt/amiga/includestd
INCDIR = /opt/amiga/ppc-morphos/include
GCCLIBDIR = /opt/amiga/lib/gcc/ppc-morphos/11.2.0/
ifeq ($(OS),Darwin)
SED = sed -i ""
else
SED = sed -i
endif
subdirs := $(wildcard */) $(wildcard src/*/) $(wildcard src/*/*/)
VPATH = $(subdirs)
SOURCE_DIR = src
BUILD_DIR = build/morphos/obj
BUNDLE_DIR = bundle
CATALOG_DIR = catalogs
CATALOG_DEFINITION = $(CATALOG_DIR)/$(PROGRAM_NAME).pot
catalog_subdirs := $(wildcard $(CATALOG_DIR)/*/)
catalog_translations := $(wildcard $(addsuffix *.po,$(catalog_subdirs)))
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 $(SOURCE_DIR)/test/% $(SOURCE_DIR)/$(PROGRAM_NAME)_cat.c,$(c_sources))
c_objects := $(addprefix $(BUILD_DIR)/,$(patsubst %.c,%.o,$(notdir $(c_sources))))
catalog_object := $(BUILD_DIR)/$(PROGRAM_NAME)_cat.o
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 = $(SOURCE_DIR)/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")
BUILD_DATE := $(shell date +%d.%m.%Y)
CCFLAGS = -MP -MMD -Wextra -Wno-unused-function -Wno-discarded-qualifiers -Wno-int-conversion -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -fno-exceptions -noixemul -D__MORPHOS__ -DHAVE_VASPRINTF -DGIT_BRANCH=\"$(GIT_BRANCH)\" -DGIT_COMMIT=\"$(GIT_COMMIT)\" -DGIT_TIMESTAMP=\"$(GIT_TIMESTAMP)\" -DBUILD_DATE=\"$(BUILD_DATE)\"
ifeq ($(DEBUG),1)
CCFLAGS += -DPROGDIR=\"OUT:\" -DDEBUG -g -O1
else
CCFLAGS += -DPROGDIR=\"PROGDIR:\" -Ofast
endif
CPPFLAGS= $(CCFLAGS) -fno-rtti -fcoroutines -fno-use-cxa-atexit
ASFLAGS = -Wa,-g,--register-prefix-optional,-I$(SDKDIR),-I$(NETINCDIR),-I$(INCDIR),-D
LDFLAGS = -Wl,-Map=$(EXECUTABLE_OUT).map,-L$(LIBDIR),-L$(SDKLIBDIR),-lm,-ljson-c,-lssl,-lcrypto,-L$(GCCLIBDIR),-latomic
VASMFLAGS = -Fhunk -opt-fconst -nowarn=62 -dwarf=3 -quiet -x -I. -D__MORPHOS__ -I$(INCDIR) -I$(NETINCDIR) -I$(SDKDIR)
.PHONY: all clean copy_bundle_files
all: $(EXECUTABLE_OUT) copy_bundle_files
clean:
$(info Cleaning...)
$(RM) -dr $(BUNDLE_DIR)/$(PROGRAM_NAME)/catalogs
$(RM) -dr $(BUILD_DIR)
catalog_definition:
$(info Generating catalog definition)
@touch $(CATALOG_DEFINITION)
@xgettext -a -c -L C -j -o $(CATALOG_DEFINITION) $(SOURCE_DIR)/*.c
catalog:
$(info Removing old catalog sources)
@$(RM) $(SOURCE_DIR)/$(PROGRAM_NAME)_cat.c $(SOURCE_DIR)/$(PROGRAM_NAME)_cat.h
$(info Generating catalog header)
@flexcat $(CATALOG_DEFINITION) $(SOURCE_DIR)/$(PROGRAM_NAME)_cat.h=C_h.sd || true
$(info Generating catalog source)
@flexcat $(CATALOG_DEFINITION) $(SOURCE_DIR)/$(PROGRAM_NAME)_cat.c=C_c.sd || true
$(info Updating catalog translations)
@for catalog_translation in $(catalog_translations); do \
msgmerge -U $$catalog_translation $(CATALOG_DEFINITION)|| true; \
done
$(info Compiling catalogs $(catalog_translations))
@for catalog_translation in $(catalog_translations); do \
flexcat POFILE $$catalog_translation CATALOG $$(dirname $$catalog_translation)/$(PROGRAM_NAME).catalog || true; \
done
$(SOURCE_DIR)/$(PROGRAM_NAME)_cat.c $(SOURCE_DIR)/$(PROGRAM_NAME)_cat.h: catalog
@true
$(BUILD_DIR):
@$(info Creating directory $@)
mkdir -p $@
$(EXECUTABLE_DIR):
@$(info Creating directory $@)
mkdir -p $@
$(EXECUTABLE_OUT): $(EXECUTABLE_DIR) $(BUILD_DIR) $(objects) catalog $(catalog_object)
$(info Linking $(PROGRAM_NAME))
@$(RM) $@
$(CC) $(CCFLAGS) $(LDFLAGS) $(objects) $(catalog_object) -o $@ $(LDFLAGS)
-include $(objects:.o=.d)
$(cpp_objects): $(BUILD_DIR)/%.o : %.cpp | $(BUILD_DIR)/%.dir
$(info Compiling $<)
$(CC) $(CPPFLAGS) -c -o $@ $(CURDIR)/$<
$(c_objects): $(BUILD_DIR)/%.o : %.c $(SOURCE_DIR)/$(PROGRAM_NAME)_cat.h | catalog
$(info Compiling $<)
@$(SED) 's|#define BUILD_NUMBER ".*"|#define BUILD_NUMBER "$(AUTOGEN_NEXT)"|' $(AUTOGEN_FILE)
$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$<
$(s_objects): $(BUILD_DIR)/%.o : %.s
$(info Assembling $<)
$(CC) $(CCFLAGS) $(ASFLAGS) -c -o $@ $(CURDIR)/$<
$(vasm_objects): $(BUILD_DIR)/%.o : %.asm
$(info Assembling $<)
$(VASM) $(VASMFLAGS) -o $@ $(CURDIR)/$<
$(catalog_object): $(SOURCE_DIR)/$(PROGRAM_NAME)_cat.c | catalog
$(info Compiling catalog $<)
$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$<
copy_bundle_files:
$(info Copying bundle files...)
@cp -R $(BUNDLE_DIR)/$(PROGRAM_NAME)/$(PROGRAM_NAME)/* $(EXECUTABLE_DIR)/