mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-24 11:11:02 -07:00
Get the executables building on WSL2 Fedora.
This commit is contained in:
41
Makefile
41
Makefile
@@ -1,9 +1,37 @@
|
||||
CC = gcc
|
||||
CXX = g++ -std=c++17
|
||||
CFLAGS = -g -O3
|
||||
LDFLAGS =
|
||||
export BUILDTYPE
|
||||
BUILDTYPE ?= host
|
||||
|
||||
OBJ = .obj
|
||||
ifeq ($(BUILDTYPE),windows)
|
||||
MINGW = i686-w64-mingw32-
|
||||
CC = $(MINGW)gcc
|
||||
CXX = $(MINGW)g++ -std=c++17
|
||||
CFLAGS += -g -O3
|
||||
CXXFLAGS += \
|
||||
-fext-numeric-literals \
|
||||
-Wno-deprecated-enum-float-conversion \
|
||||
-Wno-deprecated-enum-enum-conversion
|
||||
LDFLAGS += -static
|
||||
AR = $(MINGW)ar
|
||||
PKG_CONFIG = $(MINGW)pkg-config -static
|
||||
WINDRES = $(MINGW)windres
|
||||
WX_CONFIG = /usr/i686-w64-mingw32/sys-root/mingw/bin/wx-config-3.0 --static=yes
|
||||
EXT = .exe
|
||||
else
|
||||
CC = gcc
|
||||
CXX = g++ -std=c++17
|
||||
CFLAGS = -g -O3
|
||||
LDFLAGS =
|
||||
AR = ar
|
||||
PKG_CONFIG = pkg-config
|
||||
endif
|
||||
|
||||
HOSTCC = gcc
|
||||
HOSTCXX = g++ -std=c++17
|
||||
HOSTCFLAGS = -g -O3
|
||||
HOSTLDFLAGS =
|
||||
|
||||
REALOBJ = .obj
|
||||
OBJ = $(REALOBJ)/$(BUILDTYPE)
|
||||
DESTDIR ?=
|
||||
PREFIX ?= /usr/local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
@@ -54,6 +82,9 @@ README.md: $(OBJ)/scripts/+mkdocindex/+mkdocindex$(EXT)
|
||||
.PHONY: install install-bin
|
||||
install:: all install-bin
|
||||
|
||||
clean::
|
||||
$(hide) rm -rf $(REALOBJ)
|
||||
|
||||
install-bin:
|
||||
@echo "INSTALL"
|
||||
$(hide) install -D -v "$(OBJ)/src+fluxengine/src+fluxengine" "$(DESTDIR)$(BINDIR)/fluxengine"
|
||||
|
||||
12
build.py
12
build.py
@@ -1,7 +1,7 @@
|
||||
from build.ab import export
|
||||
from build.c import clibrary, cxxlibrary
|
||||
from build.protobuf import proto, protocc
|
||||
from build.pkg import package
|
||||
from build.pkg import package, hostpackage
|
||||
from build.utils import test
|
||||
from glob import glob
|
||||
import config
|
||||
@@ -9,9 +9,14 @@ import re
|
||||
|
||||
package(name="protobuf_lib", package="protobuf")
|
||||
package(name="z_lib", package="zlib")
|
||||
package(name="fmt_lib", package="fmt")
|
||||
package(name="fmt_lib", package="fmt", fallback="dep/fmt")
|
||||
package(name="sqlite3_lib", package="sqlite3")
|
||||
|
||||
hostpackage(name="protobuf_host_lib", package="protobuf")
|
||||
hostpackage(name="z_host_lib", package="zlib")
|
||||
hostpackage(name="fmt_host_lib", package="fmt")
|
||||
hostpackage(name="sqlite3_host_lib", package="sqlite3")
|
||||
|
||||
clibrary(name="protocol", hdrs={"protocol.h": "./protocol.h"})
|
||||
|
||||
proto(name="fl2_proto", srcs=["lib/fl2.proto"])
|
||||
@@ -211,14 +216,15 @@ cxxlibrary(
|
||||
},
|
||||
deps=[
|
||||
"+fl2_proto_lib",
|
||||
"+fmt_lib",
|
||||
"+protocol",
|
||||
"lib+config_proto_lib",
|
||||
"dep/adflib",
|
||||
"dep/agg",
|
||||
"dep/fatfs",
|
||||
"dep/hfsutils",
|
||||
"dep/libusbp",
|
||||
"dep/stb",
|
||||
"lib+config_proto_lib",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ update-ab:
|
||||
.PHONY: clean
|
||||
clean::
|
||||
@echo CLEAN
|
||||
$(hide) rm -rf $(OBJ) bin
|
||||
$(hide) rm -rf $(OBJ)
|
||||
|
||||
export PYTHONHASHSEED = 1
|
||||
build-files = $(shell find . -name 'build.py') $(wildcard build/*.py) $(wildcard config.py)
|
||||
|
||||
@@ -401,6 +401,7 @@ def emitter_endrule(rule, outs):
|
||||
emit("\t$(hide) touch", rule.sentinel)
|
||||
|
||||
for f in filenamesof(outs):
|
||||
emit(".SECONDARY:", f)
|
||||
emit(f, ":", rule.sentinel, ";")
|
||||
|
||||
|
||||
|
||||
91
build/c.py
91
build/c.py
@@ -18,6 +18,26 @@ from os.path import *
|
||||
from types import SimpleNamespace
|
||||
|
||||
|
||||
class Toolchain:
|
||||
label = ""
|
||||
cfile = ["$(CC) -c -o {outs[0]} {ins[0]} $(CFLAGS) {cflags}"]
|
||||
cxxfile = ["$(CXX) -c -o {outs[0]} {ins[0]} $(CFLAGS) {cflags}"]
|
||||
clibrary = ["$(AR) cqs {outs[0]} {ins}"]
|
||||
cxxlibrary = ["$(AR) cqs {outs[0]} {ins}"]
|
||||
cprogram = ["$(CC) -o {outs[0]} {ins} {ldflags} $(LDFLAGS)"]
|
||||
cxxprogram = ["$(CXX) -o {outs[0]} {ins} {ldflags} $(LDFLAGS)"]
|
||||
|
||||
|
||||
class HostToolchain:
|
||||
label = "HOST "
|
||||
cfile = ["$(HOSTCC) -c -o {outs[0]} {ins[0]} $(HOSTCFLAGS) {cflags}"]
|
||||
cxxfile = ["$(HOSTCXX) -c -o {outs[0]} {ins[0]} $(HOSTCFLAGS) {cflags}"]
|
||||
clibrary = ["$(HOSTAR) cqs {outs[0]} {ins}"]
|
||||
cxxlibrary = ["$(HOSTAR) cqs {outs[0]} {ins}"]
|
||||
cprogram = ["$(HOSTCC) -o {outs[0]} {ins} {ldflags} $(HOSTLDFLAGS)"]
|
||||
cxxprogram = ["$(HOSTCXX) -o {outs[0]} {ins} {ldflags} $(HOSTLDFLAGS)"]
|
||||
|
||||
|
||||
def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, cflags):
|
||||
outleaf = stripext(basename(filenameof(srcs[0]))) + suffix
|
||||
|
||||
@@ -40,9 +60,14 @@ def cfile(
|
||||
deps: Targets = None,
|
||||
cflags: List = [],
|
||||
suffix=".o",
|
||||
commands=["$(CC) -c -o {outs[0]} {ins[0]} $(CFLAGS) {cflags}"],
|
||||
label="CC",
|
||||
toolchain=Toolchain,
|
||||
commands=None,
|
||||
label=None,
|
||||
):
|
||||
if not label:
|
||||
label = toolchain.label + "CC"
|
||||
if not commands:
|
||||
commands = toolchain.cfile
|
||||
cfileimpl(self, name, srcs, deps, suffix, commands, label, "cfile", cflags)
|
||||
|
||||
|
||||
@@ -54,15 +79,20 @@ def cxxfile(
|
||||
deps: Targets = None,
|
||||
cflags: List = [],
|
||||
suffix=".o",
|
||||
commands=["$(CXX) -c -o {outs[0]} {ins[0]} $(CFLAGS) {cflags}"],
|
||||
label="CXX",
|
||||
toolchain=Toolchain,
|
||||
commands=None,
|
||||
label=None,
|
||||
):
|
||||
if not label:
|
||||
label = toolchain.label + "CC"
|
||||
if not commands:
|
||||
commands = toolchain.cfile
|
||||
cfileimpl(
|
||||
self, name, srcs, deps, suffix, commands, label, "cxxfile", cflags
|
||||
)
|
||||
|
||||
|
||||
def findsources(name, srcs, deps, cflags, filerule):
|
||||
def findsources(name, srcs, deps, cflags, toolchain, filerule):
|
||||
objs = []
|
||||
for s in flatten(srcs):
|
||||
objs += [
|
||||
@@ -71,6 +101,7 @@ def findsources(name, srcs, deps, cflags, filerule):
|
||||
srcs=[f],
|
||||
deps=deps,
|
||||
cflags=cflags,
|
||||
toolchain=toolchain,
|
||||
)
|
||||
for f in filenamesof(s)
|
||||
if f.endswith(".c")
|
||||
@@ -131,6 +162,7 @@ def libraryimpl(
|
||||
caller_ldflags,
|
||||
cflags,
|
||||
ldflags,
|
||||
toolchain,
|
||||
commands,
|
||||
label,
|
||||
kind,
|
||||
@@ -159,6 +191,7 @@ def libraryimpl(
|
||||
srcs,
|
||||
targetswithtraitsof(deps, "cheaders"),
|
||||
cflags + bubbledattrsof(deps, "caller_cflags"),
|
||||
toolchain,
|
||||
kind,
|
||||
)
|
||||
|
||||
@@ -188,10 +221,15 @@ def clibrary(
|
||||
caller_ldflags: List = [],
|
||||
cflags: List = [],
|
||||
ldflags: List = [],
|
||||
commands=["$(AR) cqs {outs[0]} {ins}"],
|
||||
label="LIB",
|
||||
toolchain=Toolchain,
|
||||
commands=None,
|
||||
label=None,
|
||||
cfilerule=cfile,
|
||||
):
|
||||
if not label:
|
||||
label = toolchain.label + "LIB"
|
||||
if not commands:
|
||||
commands = toolchain.clibrary
|
||||
libraryimpl(
|
||||
self,
|
||||
name,
|
||||
@@ -202,6 +240,7 @@ def clibrary(
|
||||
caller_ldflags,
|
||||
cflags,
|
||||
ldflags,
|
||||
toolchain,
|
||||
commands,
|
||||
label,
|
||||
cfilerule,
|
||||
@@ -219,9 +258,14 @@ def cxxlibrary(
|
||||
caller_ldflags: List = [],
|
||||
cflags: List = [],
|
||||
ldflags: List = [],
|
||||
commands=["$(AR) cqs {outs[0]} {ins}"],
|
||||
label="LIB",
|
||||
toolchain=Toolchain,
|
||||
commands=None,
|
||||
label=None,
|
||||
):
|
||||
if not label:
|
||||
label = toolchain.label + "LIB"
|
||||
if not commands:
|
||||
commands = toolchain.clibrary
|
||||
libraryimpl(
|
||||
self,
|
||||
name,
|
||||
@@ -232,6 +276,7 @@ def cxxlibrary(
|
||||
caller_ldflags,
|
||||
cflags,
|
||||
ldflags,
|
||||
toolchain,
|
||||
commands,
|
||||
label,
|
||||
cxxfile,
|
||||
@@ -239,19 +284,29 @@ def cxxlibrary(
|
||||
|
||||
|
||||
def programimpl(
|
||||
self, name, srcs, deps, cflags, ldflags, commands, label, filerule, kind
|
||||
self,
|
||||
name,
|
||||
srcs,
|
||||
deps,
|
||||
cflags,
|
||||
ldflags,
|
||||
toolchain,
|
||||
commands,
|
||||
label,
|
||||
filerule,
|
||||
kind,
|
||||
):
|
||||
ars = filenamesmatchingof(deps, "*.a")
|
||||
deps = deps + filenamesmatchingof(srcs, "*.h")
|
||||
ldflags = ldflags + bubbledattrsof(deps, "caller_ldflags")
|
||||
|
||||
cfiles = findsources(name, srcs, deps, cflags, filerule)
|
||||
cfiles = findsources(name, srcs, deps, cflags, toolchain, filerule)
|
||||
normalrule(
|
||||
replaces=self,
|
||||
ins=cfiles + ars + ars,
|
||||
outs=[basename(name) + "$(EXT)"],
|
||||
deps=deps,
|
||||
label=label,
|
||||
label=toolchain.label + label,
|
||||
commands=commands,
|
||||
ldflags=ldflags,
|
||||
)
|
||||
@@ -265,11 +320,14 @@ def cprogram(
|
||||
deps: Targets = None,
|
||||
cflags: List = [],
|
||||
ldflags: List = [],
|
||||
commands=["$(CC) -o {outs[0]} {ins} {ldflags} $(LDFLAGS)"],
|
||||
toolchain=Toolchain,
|
||||
commands=None,
|
||||
label="CLINK",
|
||||
cfilerule=cfile,
|
||||
cfilekind="cprogram",
|
||||
):
|
||||
if not commands:
|
||||
commands = toolchain.cprogram
|
||||
programimpl(
|
||||
self,
|
||||
name,
|
||||
@@ -277,6 +335,7 @@ def cprogram(
|
||||
deps,
|
||||
cflags,
|
||||
ldflags,
|
||||
toolchain,
|
||||
commands,
|
||||
label,
|
||||
cfilerule,
|
||||
@@ -292,9 +351,12 @@ def cxxprogram(
|
||||
deps: Targets = None,
|
||||
cflags: List = [],
|
||||
ldflags: List = [],
|
||||
commands=["$(CXX) -o {outs[0]} {ins} {ldflags} $(LDFLAGS)"],
|
||||
toolchain=Toolchain,
|
||||
commands=None,
|
||||
label="CXXLINK",
|
||||
):
|
||||
if not commands:
|
||||
commands = toolchain.cxxprogram
|
||||
programimpl(
|
||||
self,
|
||||
name,
|
||||
@@ -302,6 +364,7 @@ def cxxprogram(
|
||||
deps,
|
||||
cflags,
|
||||
ldflags,
|
||||
toolchain,
|
||||
commands,
|
||||
label,
|
||||
cxxfile,
|
||||
|
||||
44
build/pkg.py
44
build/pkg.py
@@ -1,4 +1,4 @@
|
||||
from build.ab import Rule, emit, Target, bubbledattrsof
|
||||
from build.ab import Rule, emit, Target, bubbledattrsof, filenamesof
|
||||
from types import SimpleNamespace
|
||||
import os
|
||||
import subprocess
|
||||
@@ -7,12 +7,18 @@ emit(
|
||||
"""
|
||||
PKG_CONFIG ?= pkg-config
|
||||
PACKAGES := $(shell $(PKG_CONFIG) --list-all | cut -d' ' -f1 | sort)
|
||||
|
||||
HOST_PKG_CONFIG ?= pkg-config
|
||||
HOST_PACKAGES := $(shell $(HOST_PKG_CONFIG) --list-all | cut -d' ' -f1 | sort)
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
@Rule
|
||||
def package(self, name, package=None, fallback: Target = None):
|
||||
self.ins = []
|
||||
self.outs = []
|
||||
|
||||
emit("ifeq ($(filter %s, $(PACKAGES)),)" % package)
|
||||
if fallback:
|
||||
emit(
|
||||
@@ -23,7 +29,7 @@ def package(self, name, package=None, fallback: Target = None):
|
||||
f"PACKAGE_LDFLAGS_{package} := ",
|
||||
bubbledattrsof(fallback, "caller_ldflags"),
|
||||
)
|
||||
emit(f"PACKAGE_DEP_{package} := ", fallback.name)
|
||||
self.outs = filenamesof(fallback)
|
||||
else:
|
||||
emit(f"$(error Required package '{package}' not installed.)")
|
||||
emit("else")
|
||||
@@ -33,11 +39,41 @@ def package(self, name, package=None, fallback: Target = None):
|
||||
emit(
|
||||
f"PACKAGE_LDFLAGS_{package} := $(shell $(PKG_CONFIG) --libs {package})"
|
||||
)
|
||||
emit(f"PACKAGE_DEP_{package} := ")
|
||||
emit("endif")
|
||||
|
||||
self.attr.caller_cflags = [f"$(PACKAGE_CFLAGS_{package})"]
|
||||
self.attr.caller_ldflags = [f"$(PACKAGE_LDFLAGS_{package})"]
|
||||
self.traits.add("clibrary")
|
||||
self.traits.add("cheaders")
|
||||
|
||||
|
||||
@Rule
|
||||
def hostpackage(self, name, package=None, fallback: Target = None):
|
||||
emit("ifeq ($(filter %s, $(HOST_PACKAGES)),)" % package)
|
||||
if fallback:
|
||||
emit(
|
||||
f"HOST_PACKAGE_CFLAGS_{package} :=",
|
||||
bubbledattrsof(fallback, "caller_cflags"),
|
||||
)
|
||||
emit(
|
||||
f"HOST_PACKAGE_LDFLAGS_{package} := ",
|
||||
bubbledattrsof(fallback, "caller_ldflags"),
|
||||
)
|
||||
emit(f"HOST_PACKAGE_DEP_{package} := ", fallback.name)
|
||||
else:
|
||||
emit(f"$(error Required host package '{package}' not installed.)")
|
||||
emit("else")
|
||||
emit(
|
||||
f"HOST_PACKAGE_CFLAGS_{package} := $(shell $(HOST_PKG_CONFIG) --cflags {package})"
|
||||
)
|
||||
emit(
|
||||
f"HOST_PACKAGE_LDFLAGS_{package} := $(shell $(HOST_PKG_CONFIG) --libs {package})"
|
||||
)
|
||||
emit(f"HOST_PACKAGE_DEP_{package} := ")
|
||||
emit("endif")
|
||||
|
||||
self.attr.caller_cflags = [f"$(HOST_PACKAGE_CFLAGS_{package})"]
|
||||
self.attr.caller_ldflags = [f"$(HOST_PACKAGE_LDFLAGS_{package})"]
|
||||
|
||||
self.ins = []
|
||||
self.outs = [f"$(PACKAGE_DEP_{package})"]
|
||||
self.outs = [f"$(HOST_PACKAGE_DEP_{package})"]
|
||||
|
||||
12
config.py
12
config.py
@@ -1,5 +1,11 @@
|
||||
import platform
|
||||
import os
|
||||
|
||||
windows = platform.system() == "Windows"
|
||||
osx = platform.system() == "Darwin"
|
||||
unix = not windows
|
||||
if os.getenv("BUILDTYPE") == "windows":
|
||||
windows = True
|
||||
osx = False
|
||||
unix = False
|
||||
else:
|
||||
windows = False
|
||||
osx = platform.system() == "Darwin"
|
||||
unix = True
|
||||
|
||||
17
dep/fmt/build.py
Normal file
17
dep/fmt/build.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from build.c import cxxlibrary, HostToolchain
|
||||
|
||||
cxxlibrary(
|
||||
name="fmt",
|
||||
srcs=[
|
||||
"./src/format.cc",
|
||||
"./src/os.cc",
|
||||
],
|
||||
cflags=["-Idep/fmt/include"],
|
||||
hdrs={
|
||||
"fmt/args.h": "./include/fmt/args.h",
|
||||
"fmt/chrono.h": "./include/fmt/chrono.h",
|
||||
"fmt/core.h": "./include/fmt/core.h",
|
||||
"fmt/format.h": "./include/fmt/format.h",
|
||||
"fmt/ostream.h": "./include/fmt/ostream.h",
|
||||
"fmt/ranges.h": "./include/fmt/ranges.h",
|
||||
})
|
||||
@@ -61,7 +61,7 @@ clibrary(
|
||||
name="libusbp",
|
||||
srcs=srcs,
|
||||
cflags=["-Idep/libusbp/include", "-Idep/libusbp/src"],
|
||||
ldflags=ldflags,
|
||||
caller_ldflags=ldflags,
|
||||
deps=deps,
|
||||
hdrs={
|
||||
"libusbp_internal.h": "./src/libusbp_internal.h",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from build.ab import Rule, normalrule, Targets
|
||||
from build.c import cxxprogram
|
||||
from build.c import cxxprogram, HostToolchain
|
||||
|
||||
encoders = {}
|
||||
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
#include "winuser.h"
|
||||
|
||||
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "src/gui/manifest.xml"
|
||||
101 ICON DISCARDABLE ".obj/extras+fluxengine_ico/fluxengine.ico"
|
||||
101 ICON DISCARDABLE ".obj/windows/extras/+fluxengine_ico/fluxengine.ico"
|
||||
|
||||
Reference in New Issue
Block a user