tibia/templates/cmd-make/Makefile

123 lines
3.0 KiB
Makefile
Raw Normal View History

2024-02-22 11:31:35 +00:00
#
# Tibia
#
# Copyright (C) 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-12-11 19:18:43 +00:00
TEMPLATE := cmd
2024-01-24 11:08:49 +00:00
include vars.mk
2024-12-11 19:18:43 +00:00
COMMON_DIR ?= .
DATA_DIR ?= .
PLUGIN_DIR ?= src
API_DIR ?= $(PLUGIN_DIR)
2024-12-11 19:18:43 +00:00
MKINC_DIR ?= $(COMMON_DIR)
BUILD_BIN_DIR := build
BUILD_DATA_DIR := build
2024-12-11 19:18:43 +00:00
-include $(MKINC_DIR)/vars-pre.mk
2024-01-30 08:56:00 +00:00
ifeq ($(OS), Windows_NT)
2024-06-16 10:04:02 +00:00
EXE_SUFFIX := .exe
2024-01-30 08:56:00 +00:00
else
2024-06-16 10:04:02 +00:00
UNAME_S := $(shell uname -s)
EXE_SUFFIX :=
PREFIX := /usr/local
BINDIR := $(PREFIX)/bin
2024-01-30 08:56:00 +00:00
endif
2024-12-11 19:18:43 +00:00
TINIWAV_DIR ?= ../tinywav
MIDI_PARSER_DIR ?= ../midi-parser
2024-06-16 10:04:02 +00:00
CC := gcc
CXX := g++
2024-01-24 11:08:49 +00:00
2024-06-16 10:04:02 +00:00
CFLAGS := -O3 -Wall -Wpedantic -Wextra
CFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -I$(TINYWAV_DIR) -I$(MIDI_PARSER_DIR)/include $(CFLAGS_EXTRA) $(CFLAGS)
2024-06-16 10:04:02 +00:00
LDFLAGS :=
2024-12-11 19:18:43 +00:00
LDFLAGS_ALL := $(LDFLAGS_EXTRA) $(LDFLAGS)
2024-01-24 11:08:49 +00:00
2024-06-16 10:04:02 +00:00
CXXFLAGS := $(CFLAGS)
CXXFLAGS_ALL := -I$(DATA_DIR)/src -I$(PLUGIN_DIR) -I$(API_DIR) -I$(TINYWAV_DIR) -I$(MIDI_PARSER_DIR)/include $(CXXFLAGS_EXTRA) $(CXXFLAGS)
2024-02-02 10:25:20 +00:00
2024-02-01 17:16:03 +00:00
ifeq ($(UNAME_S), Darwin)
2024-12-11 19:18:43 +00:00
CFLAGS_ALL := $(CFLAGS_ALL) -arch arm64 -arch x86_64
LDFLAGS_ALL := $(LDFLAGS_ALL) -arch arm64 -arch x86_64
CXXFLAGS_ALL := $(CXXFLAGS_ALL) -arch arm64 -arch x86_64
2024-02-01 17:16:03 +00:00
endif
2024-06-16 10:04:02 +00:00
PROGRAM := $(BUNDLE_NAME)$(EXE_SUFFIX)
2024-01-24 11:08:49 +00:00
2024-06-16 10:04:02 +00:00
C_SRCS := $(COMMON_DIR)/src/main.c $(C_SRCS_EXTRA)
ifeq ($(HAS_MIDI_IN), yes)
2024-06-16 10:04:02 +00:00
C_SRCS := $(C_SRCS) $(MIDI_PARSER_DIR)/src/midi-parser.c
endif
2024-06-16 10:04:02 +00:00
C_OBJS := $(addprefix build/obj/, $(notdir $(C_SRCS:.c=.o)))
2024-02-01 18:35:18 +00:00
2024-06-16 10:04:02 +00:00
CXX_SRCS := $(CXX_SRCS_EXTRA)
CXX_OBJS := $(addprefix build/obj/, $(notdir $(CXX_SRCS:.cpp=.o)))
2024-02-02 10:25:20 +00:00
2024-06-16 10:04:02 +00:00
ALL := build/$(PROGRAM)
2024-12-11 19:18:43 +00:00
-include $(MKINC_DIR)/vars-extra.mk
2024-06-16 10:04:02 +00:00
all: $(ALL)
2024-01-30 08:56:00 +00:00
2024-02-02 10:25:20 +00:00
ifeq ($(CXX_OBJS),)
2024-06-16 10:04:02 +00:00
build/$(PROGRAM): $(C_OBJS) build/obj/tinywav.o | build
$(CC) $^ -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL)
2024-02-02 10:25:20 +00:00
else
2024-06-16 10:04:02 +00:00
build/$(PROGRAM): $(C_OBJS) $(CXX_OBJS) build/obj/tinywav.o | build
$(CXX) $^ -o $@ $(CFLAGS_ALL) $(CXXFLAGS_ALL) $(LDFLAGS_ALL)
2024-02-02 10:25:20 +00:00
endif
2024-02-01 18:35:18 +00:00
build build/obj:
2024-01-24 11:08:49 +00:00
mkdir -p $@
clean:
rm -fr build
ifeq ($(OS), Windows_NT)
.PHONY: all clean
else
2024-01-30 08:56:00 +00:00
install: all
mkdir -m 0755 -p $(BINDIR)
install -m 0755 build/$(PROGRAM) $(BINDIR)
2024-01-30 08:56:00 +00:00
.PHONY: all clean install
endif
2024-02-02 10:25:20 +00:00
2024-12-11 19:18:43 +00:00
-include $(MKINC_DIR)/rules-extra.mk
2024-06-16 10:04:02 +00:00
2024-02-02 10:25:20 +00:00
.SECONDEXPANSION:
PERCENT := %
2024-06-16 10:04:02 +00:00
build/obj/tinywav.o: $(TINYWAV_DIR)/tinywav.c
$(CC) $^ -o $@ -c $(CFLAGS_ALL) -Wno-unused-result
2024-02-02 10:25:20 +00:00
$(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 10:25:20 +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)
2024-12-11 19:18:43 +00:00
-include $(MKINC_DIR)/rules-secondexp-extra.mk