Build system supports both MacOS and Linux now

This commit is contained in:
Robert Bendun 2022-10-14 15:56:36 +02:00
parent b93a236e37
commit 0d7f4b1eb5
7 changed files with 30 additions and 31 deletions

View File

@ -5,13 +5,13 @@ Obj := $(subst musique/,,$(Sources:%.cc=%.o))
all: bin/musique
include scripts/$(os).mk
include scripts/debug.mk
include scripts/release.mk
include scripts/test.mk
include scripts/windows.mk
# http://www.music.mcgill.ca/~gary/rtmidi/#compiling
bin/rtmidi.o: lib/rtmidi/RtMidi.cpp lib/rtmidi/RtMidi.h
bin/$(os)/rtmidi.o: lib/rtmidi/RtMidi.cpp lib/rtmidi/RtMidi.h
@echo "CXX $@"
@$(CXX) $< -c -O2 -o $@ $(CPPFLAGS) -std=c++20
@ -32,5 +32,5 @@ install: bin/musique
.PHONY: clean doc doc-open all test unit-tests release install
$(shell mkdir -p $(subst musique/,bin/,$(shell find musique/* -type d)))
$(shell mkdir -p $(subst musique/,bin/debug/,$(shell find musique/* -type d)))
$(shell mkdir -p $(subst musique/,bin/$(os)/,$(shell find musique/* -type d)))
$(shell mkdir -p $(subst musique/,bin/$(os)/debug/,$(shell find musique/* -type d)))

View File

@ -8,15 +8,9 @@ LDLIBS= -lpthread
RELEASE_FLAGS=-O2
DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug
ifeq ($(os),windows)
CC=i686-w64-mingw32-gcc
CXX=i686-w64-mingw32-g++
CPPFLAGS:=$(CPPFLAGS) -D__WINDOWS_MM__
LDLIBS:=-lwinmm $(LDLIBS)
ifeq ($(shell uname),Darwin)
os=macos
else
CC=gcc
CXX=g++
CPPFLAGS:=$(CPPFLAGS) -D __MACOSX_CORE__
LDLIBS:=-framework CoreMIDI -framework CoreAudio -framework CoreFoundation $(LDLIBS)
os=linux
endif

View File

@ -9,13 +9,14 @@
#include <iostream>
#include <numeric>
#include <compare>
#include <cstring>
Value::Value() = default;
std::strong_ordering operator<=>(std::string const& lhs, std::string const& rhs)
{
if (auto cmp = lhs.size() <=> rhs.size(); cmp == 0) {
if (auto cmp = strncmp(lhs.c_str(), rhs.c_str(), lhs.size()); cmp == 0) {
if (auto cmp = std::strncmp(lhs.c_str(), rhs.c_str(), lhs.size()); cmp == 0) {
return std::strong_ordering::equal;
} else if (cmp < 0) {
return std::strong_ordering::less;

5
scripts/linux.mk Normal file
View File

@ -0,0 +1,5 @@
CC=gcc
CXX=g++
CPPFLAGS:=$(CPPFLAGS) -D __LINUX_ALSA__
LDLIBS:=-lasound $(LDLIBS) -static-libgcc -static-libstdc++
Bestline=bin/$(os)/bestline.o

7
scripts/macos.mk Normal file
View File

@ -0,0 +1,7 @@
CC=clang
CXX=clang++
CPPFLAGS:=$(CPPFLAGS) -D __MACOSX_CORE__
LDLIBS:=-framework CoreMIDI -framework CoreAudio -framework CoreFoundation $(LDLIBS)
Release_Obj=$(addprefix bin/,$(Obj))
Bestline=bin/$(os)/bestline.o

View File

@ -1,15 +1,13 @@
ifneq ($(os),windows)
Release_Obj=$(addprefix bin/,$(Obj))
Release_Obj=$(addprefix bin/$(os)/,$(Obj))
bin/bestline.o: lib/bestline/bestline.c lib/bestline/bestline.h
bin/$(os)/bestline.o: lib/bestline/bestline.c lib/bestline/bestline.h
@echo "CC $@"
@$(CC) $< -c -O3 -o $@
bin/%.o: musique/%.cc
bin/$(os)/%.o: musique/%.cc
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c
bin/musique: $(Release_Obj) bin/main.o bin/rtmidi.o bin/bestline.o
bin/musique: $(Release_Obj) bin/$(os)/main.o bin/$(os)/rtmidi.o $(Bestline)
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/rtmidi.o bin/bestline.o $(LDFLAGS) $(LDLIBS)
endif
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/$(os)/rtmidi.o $(Bestline) $(LDFLAGS) $(LDLIBS)

View File

@ -1,11 +1,5 @@
ifeq ($(os),windows)
Release_Obj=$(addprefix bin/,$(Obj))
CC=i686-w64-mingw32-gcc
CXX=i686-w64-mingw32-g++
CPPFLAGS:=$(CPPFLAGS) -D__WINDOWS_MM__
LDLIBS:=-lwinmm $(LDLIBS) -static-libgcc -static-libstdc++
bin/%.o: musique/%.cc
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c
bin/musique: $(Release_Obj) bin/main.o bin/rtmidi.o
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/rtmidi.o $(LDFLAGS) $(LDLIBS)
endif