tibia/templates/web-make/Makefile

116 lines
3.4 KiB
Makefile
Raw Normal View History

2024-02-22 11:31:35 +00:00
#
# Tibia
#
# Copyright (C) 2023, 2024 Orastron Srl unipersonale
#
# Tibia is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# Tibia is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tibia. If not, see <http://www.gnu.org/licenses/>.
#
# File author: Stefano D'Angelo
#
2024-01-17 16:31:14 +00:00
include vars.mk
2024-02-01 05:59:10 +00:00
COMMON_DIR := $(or $(COMMON_DIR),.)
DATA_DIR := $(or $(DATA_DIR),.)
PLUGIN_DIR := $(or $(PLUGIN_DIR),src)
2024-06-16 10:04:02 +00:00
CC := clang
CXX := clang++
2024-06-16 10:04:02 +00:00
CFLAGS := -Ofast -Wall -Wpedantic -Wextra
CFLAGS_ALL := -I$(COMMON_DIR)/src -I$(DATA_DIR)/src -I$(PLUGIN_DIR) --target=wasm32 -flto -fvisibility=hidden $(CFLAGS) $(CFLAGS_EXTRA)
2024-06-16 10:04:02 +00:00
LDFLAGS_ALL := \
2024-01-17 16:31:14 +00:00
-Wl,--allow-undefined \
-Wl,--no-entry \
-Wl,--lto-O3 \
-Wl,-strip-all \
-Wl,--export-table \
-Wl,--export=malloc \
-Wl,--export=realloc \
-Wl,--export=calloc \
-Wl,--export=free \
-Wl,--export=memset \
2024-02-21 08:03:50 +00:00
-Wl,--export=memcpy \
2024-01-18 14:30:38 +00:00
-Wl,--export=processor_new \
-Wl,--export=processor_free \
2024-01-19 14:33:53 +00:00
-Wl,--export=processor_get_x_buf \
-Wl,--export=processor_get_x \
-Wl,--export=processor_get_zero_buf \
2024-01-19 14:33:53 +00:00
-Wl,--export=processor_get_y_buf \
-Wl,--export=processor_get_out_params \
2024-01-18 14:30:38 +00:00
-Wl,--export=processor_process \
-Wl,--export=processor_set_parameter \
2024-01-17 16:31:14 +00:00
-Wl,-z,stack-size=$$((8*1024*1024)) \
-nostdlib
2024-06-16 10:04:02 +00:00
ifeq ($(HAS_MIDI_IN), yes)
LDFLAGS_ALL := $(LDFLAGS_ALL) -Wl,--export=processor_midi_msg_in
2024-01-19 16:28:00 +00:00
endif
2024-06-16 10:04:02 +00:00
LDFLAGS_ALL := $(LDFLAGS_ALL) $(LDFLAGS) $(LDFLAGS_EXTRA)
2024-01-19 16:28:00 +00:00
2024-06-16 10:04:02 +00:00
CXXFLAGS := $(CFLAGS)
CXXFLAGS_ALL := -I$(COMMON_DIR)/src -I$(DATA_DIR)/src -I$(PLUGIN_DIR) --target=wasm32 -flto -fvisibility=hidden $(CXXFLAGS) $(CXXFLAGS_EXTRA)
2024-02-02 16:44:58 +00:00
2024-06-16 10:04:02 +00:00
C_SRCS := $(COMMON_DIR)/src/processor.c $(COMMON_DIR)/src/walloc.c $(COMMON_DIR)/src/string.c
C_OBJS := $(addprefix build/obj/, $(notdir $(C_SRCS:.c=.o)))
2024-02-02 16:44:58 +00:00
ifeq ($(CXX_SRCS_EXTRA),)
2024-06-16 10:04:02 +00:00
CXX_SRCS :=
CXX_OBJS :=
2024-02-02 16:44:58 +00:00
else
2024-06-16 10:04:02 +00:00
CXX_SRCS := $(COMMON_DIR)/src/new.cpp $(CXX_SRCS_EXTRA)
CXX_OBJS := $(addprefix build/obj/, $(notdir $(CXX_SRCS:.cpp=.o)))
2024-02-02 16:44:58 +00:00
endif
ALL := build/web/$(BUNDLE_NAME)/module.wasm build/web/$(BUNDLE_NAME)/processor.js build/web/$(BUNDLE_NAME)/module.js
2024-01-18 17:13:31 +00:00
2024-06-16 10:04:02 +00:00
-include $(COMMON_DIR)/vars-extra.mk
2024-01-18 17:13:31 +00:00
2024-06-16 10:04:02 +00:00
all: $(ALL)
2024-01-17 16:31:14 +00:00
2024-02-02 16:44:58 +00:00
ifeq ($(CXX_OBJS),)
build/web/$(BUNDLE_NAME)/module.wasm: $(C_OBJS) | build/web/$(BUNDLE_NAME)
2024-06-16 10:04:02 +00:00
$(CC) $^ -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL)
2024-02-02 16:44:58 +00:00
else
build/web/$(BUNDLE_NAME)/module.wasm: $(C_OBJS) $(CXX_OBJS) | build/web/$(BUNDLE_NAME)
2024-06-16 10:04:02 +00:00
$(CXX) $^ -o $@ $(CFLAGS_ALL) $(CXXFLAGS_ALL) $(LDFLAGS_ALL)
2024-02-02 16:44:58 +00:00
endif
2024-01-18 14:30:38 +00:00
build/web/$(BUNDLE_NAME)/processor.js: $(DATA_DIR)/src/processor.js | build/web/$(BUNDLE_NAME)
2024-01-18 14:30:38 +00:00
cp $^ $@
2024-01-17 16:31:14 +00:00
2024-12-11 08:40:50 +00:00
build/web/$(BUNDLE_NAME)/module.js: $(DATA_DIR)/src/module.js | build/web/$(BUNDLE_NAME)
2024-01-18 17:13:31 +00:00
cp $^ $@
build/obj build/web build/web/$(BUNDLE_NAME):
2024-01-17 16:31:14 +00:00
mkdir -p $@
clean:
rm -fr build
2024-06-16 10:04:02 +00:00
-include $(COMMON_DIR)/rules-extra.mk
2024-01-17 16:31:14 +00:00
.PHONY: all clean
2024-02-02 16:44:58 +00:00
.SECONDEXPANSION:
PERCENT := %
$(C_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).c,$$(C_SRCS)) | build/obj
2024-06-16 10:04:02 +00:00
$(CC) $^ -o $@ -c $(CFLAGS_ALL)
2024-02-02 16:44:58 +00:00
$(CXX_OBJS): build/obj/%.o: $$(filter $$(PERCENT)/$$(basename $$(notdir $$@)).cpp,$$(CXX_SRCS)) | build/obj
2024-06-16 10:04:02 +00:00
$(CXX) $^ -o $@ -c $(CXXFLAGS_ALL)
-include $(COMMON_DIR)/rules-secondexp-extra.mk