Initial port to ackbuilder. The fluxengine binary builds on Linux.

This commit is contained in:
David Given
2022-06-11 01:00:31 +02:00
parent d7ce10001b
commit 5efbb38270
12 changed files with 419 additions and 95 deletions

218
Makefile
View File

@@ -1,98 +1,130 @@
PACKAGES = zlib sqlite3 protobuf
OBJDIR = .obj
LUA = lua5.3
CC = gcc
CXX = g++
AR = ar
PKG_CONFIG = pkg-config
CFLAGS = -g
CXXFLAGS = -std=c++2a \
-Wno-deprecated-enum-float-conversion \
-Wno-deprecated-enum-enum-conversion
LDFLAGS =
export CFLAGS = \
-ffunction-sections -fdata-sections
export CXXFLAGS = $(CFLAGS) \
-x c++ --std=gnu++2a \
-Wno-deprecated-enum-enum-conversion \
-Wno-deprecated-enum-float-conversion
export LDFLAGS = -pthread
all: $(OBJDIR)/build.ninja
@ninja -f $<
export COPTFLAGS = -Os
export LDOPTFLAGS = -Os
export CDBGFLAGS = -O0 -g
export LDDBGFLAGS = -O0 -g
ifeq ($(OS), Windows_NT)
else
ifeq ($(shell uname),Darwin)
else
PACKAGES += libudev
endif
endif
ifeq ($(OS), Windows_NT)
export PROTOC = /mingw32/bin/protoc
export CC = /mingw32/bin/gcc
export CXX = /mingw32/bin/g++
export AR = /mingw32/bin/ar rc
export RANLIB = /mingw32/bin/ranlib
export STRIP = /mingw32/bin/strip
export CFLAGS += -I/mingw32/include
export CXXFLAGS += $(shell wx-config --cxxflags --static=yes)
export GUILDFLAGS += -lmingw32
export LIBS += -L/mingw32/lib -static\
-lsqlite3 -lz \
-lsetupapi -lwinusb -lole32 -lprotobuf -luuid
export GUILIBS += -L/mingw32/lib -static -lsqlite3 \
$(shell wx-config --libs --static=yes core base) -lz \
-lcomctl32 -loleaut32 -lspoolss -loleacc -lwinspool \
-lsetupapi -lwinusb -lole32 -lprotobuf -luuid
export EXTENSION = .exe
else
packages-exist = $(shell pkg-config --exists $(PACKAGES) && echo yes)
ifneq ($(packages-exist),yes)
$(warning These pkg-config packages are installed: $(shell pkg-config --list-all | sort | awk '{print $$1}'))
$(error You must have these pkg-config packages installed: $(PACKAGES))
endif
wx-exist = $(shell wx-config --cflags > /dev/null && echo yes)
ifneq ($(wx-exist),yes)
$(error You must have these wx-config installed)
endif
export PROTOC = protoc
export CC = gcc
export CXX = g++
export AR = ar rc
export RANLIB = ranlib
export STRIP = strip
export CFLAGS += $(shell pkg-config --cflags $(PACKAGES)) $(shell wx-config --cxxflags)
export LDFLAGS +=
export LIBS += $(shell pkg-config --libs $(PACKAGES))
export GUILIBS += $(shell wx-config --libs core base)
export EXTENSION =
ifeq ($(shell uname),Darwin)
AR = ar rcS
RANLIB += -c -no_warning_for_no_symbols
export CC = clang
export CXX = clang++
export COBJC = clang
export LDFLAGS += -framework IOKit -framework CoreFoundation
export CFLAGS += -Wno-deprecated-declarations
endif
endif
export XXD = xxd
CFLAGS += -Ilib -Idep/fmt -Iarch
export OBJDIR = .obj
all: .obj/build.ninja
@ninja -f .obj/build.ninja
@if command -v cscope > /dev/null; then cscope -bRq; fi
$(OBJDIR)/build.ninja: Makefile $(shell find . -name '*.lua')
@mkdir -p $(OBJDIR)
@$(LUA) build/ackbuilder.lua build/build.lua build.lua \
--ninja \
AR="$(AR)" \
CC="$(CC)" \
CFLAGS="$(CFLAGS)" \
CXX="$(CXX)" \
CXXFLAGS="$(CXXFLAGS)" \
LDFLAGS="$(LDFLAGS)" \
OBJDIR="$(OBJDIR)" \
PKG_CONFIG="$(PKG_CONFIG)" \
> $@
clean:
@echo CLEAN
@rm -rf $(OBJDIR)
rm -rf $(OBJDIR)
.obj/build.ninja: mkninja.sh Makefile
@echo MKNINJA $@
@mkdir -p $(OBJDIR)
@sh $< > $@
compdb:
@ninja -f .obj/build.ninja -t compdb > compile_commands.json
#PACKAGES = zlib sqlite3 protobuf
#
#export CFLAGS = \
# -ffunction-sections -fdata-sections
#export CXXFLAGS = $(CFLAGS) \
# -x c++ --std=gnu++2a \
# -Wno-deprecated-enum-enum-conversion \
# -Wno-deprecated-enum-float-conversion
#export LDFLAGS = -pthread
#
#export COPTFLAGS = -Os
#export LDOPTFLAGS = -Os
#
#export CDBGFLAGS = -O0 -g
#export LDDBGFLAGS = -O0 -g
#
#ifeq ($(OS), Windows_NT)
#else
#ifeq ($(shell uname),Darwin)
#else
# PACKAGES += libudev
#endif
#endif
#
#ifeq ($(OS), Windows_NT)
#export PROTOC = /mingw32/bin/protoc
#export CC = /mingw32/bin/gcc
#export CXX = /mingw32/bin/g++
#export AR = /mingw32/bin/ar rc
#export RANLIB = /mingw32/bin/ranlib
#export STRIP = /mingw32/bin/strip
#export CFLAGS += -I/mingw32/include
#export CXXFLAGS += $(shell wx-config --cxxflags --static=yes)
#export GUILDFLAGS += -lmingw32
#export LIBS += -L/mingw32/lib -static\
# -lsqlite3 -lz \
# -lsetupapi -lwinusb -lole32 -lprotobuf -luuid
#export GUILIBS += -L/mingw32/lib -static -lsqlite3 \
# $(shell wx-config --libs --static=yes core base) -lz \
# -lcomctl32 -loleaut32 -lspoolss -loleacc -lwinspool \
# -lsetupapi -lwinusb -lole32 -lprotobuf -luuid
#export EXTENSION = .exe
#else
#
#packages-exist = $(shell pkg-config --exists $(PACKAGES) && echo yes)
#ifneq ($(packages-exist),yes)
#$(warning These pkg-config packages are installed: $(shell pkg-config --list-all | sort | awk '{print $$1}'))
#$(error You must have these pkg-config packages installed: $(PACKAGES))
#endif
#wx-exist = $(shell wx-config --cflags > /dev/null && echo yes)
#ifneq ($(wx-exist),yes)
#$(error You must have these wx-config installed)
#endif
#
#export PROTOC = protoc
#export CC = gcc
#export CXX = g++
#export AR = ar rc
#export RANLIB = ranlib
#export STRIP = strip
#export CFLAGS += $(shell pkg-config --cflags $(PACKAGES)) $(shell wx-config --cxxflags)
#export LDFLAGS +=
#export LIBS += $(shell pkg-config --libs $(PACKAGES))
#export GUILIBS += $(shell wx-config --libs core base)
#export EXTENSION =
#
#ifeq ($(shell uname),Darwin)
#AR = ar rcS
#RANLIB += -c -no_warning_for_no_symbols
#export CC = clang
#export CXX = clang++
#export COBJC = clang
#export LDFLAGS += -framework IOKit -framework CoreFoundation
#export CFLAGS += -Wno-deprecated-declarations
#endif
#
#endif
#export XXD = xxd
#
#CFLAGS += -Ilib -Idep/fmt -Iarch
#
#export OBJDIR = .obj
#
#all: .obj/build.ninja
# @ninja -f .obj/build.ninja
# @if command -v cscope > /dev/null; then cscope -bRq; fi
#
#clean:
# @echo CLEAN
# @rm -rf $(OBJDIR)
#
#.obj/build.ninja: mkninja.sh Makefile
# @echo MKNINJA $@
# @mkdir -p $(OBJDIR)
# @sh $< > $@
#
#compdb:
# @ninja -f .obj/build.ninja -t compdb > compile_commands.json

35
build/dependency.lua Normal file
View File

@@ -0,0 +1,35 @@
local function unnl(s)
return (s:gsub("[\n\r]+", " "))
end
definerule("dependency",
{
pkg_config = { type="string", optional=true },
fallback = { type="targets", optional=true }
},
function (e)
local fallback = e.fallback and targetsof(e.fallback) or {}
if #fallback > 1 then
error("fallback must be a single target")
end
local cflags, _, _, e1 = shell(vars.PKG_CONFIG, "--silence-errors", "--cflags", e.pkg_config)
local libs, _, _, e2 = shell(vars.PKG_CONFIG, "--silence-errors", "--libs", e.pkg_config)
local version, _, _, e3 = shell(vars.PKG_CONFIG, "--silence-errors", "--modversion", e.pkg_config)
if (e1 ~= 0) or (e2 ~= 0) or (e3 ~= 0) then
if #fallback == 0 then
error(string.format("required dependency '%s' missing", e.pkg_config))
end
print("dependency ", e.pkg_config, ": internal")
return inherit(fallback[1], {})
else
print("dependency ", e.pkg_config, ": pkg-config ", unnl(version))
return {
is = { clibrary = true },
dep_cflags = unnl(cflags),
dep_libs = unnl(libs),
}
end
end
)

53
build/protobuf.lua Normal file
View File

@@ -0,0 +1,53 @@
definerule("proto_cc_library",
{
srcs = { type="targets", default={} },
deps = { type="targets", default={} },
commands = {
type="strings",
default={
"rm -f %{outs[1]}",
"$(AR) cqs %{outs[1]} %{ins}",
},
}
},
function (e)
local ins = {}
local outleaves = {}
for _, src in fpairs(e.srcs) do
local n = src:gsub("%.%w*$", "")
ins[#ins+1] = src
outleaves[#outleaves+1] = n..".pb.cc"
outleaves[#outleaves+1] = n..".pb.h"
end
local protosrcs = normalrule {
name = e.name.."_src",
cwd = e.cwd,
ins = ins,
outleaves = outleaves,
commands = {
"protoc --cpp_out=%{dir} %{ins}"
}
}
local hdrs = {}
for _, src in fpairs(e.srcs) do
local n = src:gsub("%.%w*$", "")
hdrs[n..".pb.h"] = protosrcs.dir.."/"..n..".pb.h"
end
local lib = clibrary {
name = e.name,
srcs = { protosrcs },
hdrs = hdrs,
dep_cflags = { "-I"..protosrcs.dir },
vars = {
["+cflags"] = { "-I"..protosrcs.dir }
}
}
return lib
end
)

9
dep/agg/build.lua Normal file
View File

@@ -0,0 +1,9 @@
clibrary {
name = "agg",
srcs = { "./src/*.cpp" },
dep_cflags = { "-Idep/agg/include" },
vars = {
["+cflags"] = { "-Idep/agg/include" }
}
}

9
dep/emu/build.lua Normal file
View File

@@ -0,0 +1,9 @@
clibrary {
name = "emu",
srcs = { "./*.c" },
hdrs = {
"./fnmatch.h"
}
}

6
dep/fmt/build.lua Normal file
View File

@@ -0,0 +1,6 @@
clibrary {
name = "fmt",
srcs = { "./*.cc" },
hdrs = { "./fmt/*.h" }
}

19
dep/libusbp/build.lua Normal file
View File

@@ -0,0 +1,19 @@
clibrary {
name = "libusbp",
srcs = {
"./src/*.c",
"./src/linux/*.c",
},
hdrs = {
["libusbp_config.h"] = "./include/libusbp_config.h",
["libusbp.h"] = "./include/libusbp.h",
["libusbp.hpp"] = "./include/libusbp.hpp",
},
vars = {
["+cflags"] = {
"-I"..cwd().."/include",
"-I"..cwd().."/src",
}
}
}

6
dep/stb/build.lua Normal file
View File

@@ -0,0 +1,6 @@
clibrary {
name = "stb",
srcs = { "./*.c" },
hdrs = { "./*.h" }
}

0
scripts/mktable.sh Normal file → Executable file
View File

58
scripts/protoencode.cc Normal file
View File

@@ -0,0 +1,58 @@
#include <stdio.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <fstream>
#include "fmt/format.h"
#include "lib/config.pb.h"
#define STRINGIFY(s) #s
int main(int argc, const char* argv[])
{
ConfigProto message;
std::ifstream input(argv[1]);
if (!input)
{
perror("couldn't open input file");
exit(1);
}
google::protobuf::io::IstreamInputStream istream(&input);
if (!google::protobuf::TextFormat::Parse(&istream, &message))
{
fprintf(stderr, "cannot parse text proto");
exit(1);
}
std::ofstream output(argv[2]);
if (!output)
{
perror("couldn't open output file");
exit(1);
}
auto data = message.SerializeAsString();
output << "#include <string>\n"
<< "static const unsigned char data[] = {\n";
int count = 0;
for (char c : data)
{
if (count == 0)
output << "\n\t";
else
output << ' ';
output << fmt::format("0x{:02x},", (unsigned char)c);
count = (count+1) & 7;
}
output << "};\n"
<< fmt::format("extern std::string {}();\n", argv[3])
<< fmt::format("std::string {}()\n", argv[3])
<< "{ return std::string((const char*)data, sizeof(data)); }\n";
return 0;
}

View File

@@ -163,7 +163,8 @@ static void draw_y_axis(Agg2D& painter, double x, double y1, double y2,
do_in_steps(y1, y2, lo, hi, step, [&](double y, double v)
{
painter.line(x, y, x-5, y);
painter.text(x-8, y+5.0, fmt::format(format, v));
painter.text(
x-8, y+5.0, fmt::format(fmt::runtime(format), v));
});
}
@@ -179,7 +180,8 @@ static void draw_x_axis(Agg2D& painter, double x1, double x2, double y,
do_in_steps(x1, x2, lo, hi, step, [&](double x, double v)
{
painter.line(x, y, x, y+5);
painter.text(x, y+18, fmt::format(format, v));
painter.text(
x, y+18, fmt::format(fmt::runtime(format), v));
});
}

95
src/formats/build.lua Normal file
View File

@@ -0,0 +1,95 @@
FORMATS = {
"40track_drive",
"acornadfs",
"acorndfs",
"aeslanier",
"agat840",
"amiga",
"ampro",
"apple2_drive",
"apple2",
"appledos",
"atarist360",
"atarist370",
"atarist400",
"atarist410",
"atarist720",
"atarist740",
"atarist800",
"atarist820",
"bk800",
"brother120",
"brother240",
"commodore1541",
"commodore1581",
"eco1",
"f85",
"fb100",
"hp9121",
"hplif770",
"ibm1200",
"ibm1232",
"ibm1440",
"ibm180",
"ibm360",
"ibm720",
"ibm",
"mac400",
"mac800",
"micropolis143",
"micropolis287",
"micropolis315",
"micropolis630",
"mx",
"n88basic",
"northstar175",
"northstar350",
"northstar87",
"prodos",
"rx50",
"shugart_drive",
"tids990",
"vgi",
"victor9k_ds",
"victor9k_ss",
"zilogmcz",
}
cprogram {
name = "protoencode",
srcs = { "scripts/protoencode.cc" },
deps = {
".+config_lib",
".+protobuf_dep",
".+fmt_dep",
},
}
for _, format in pairs(FORMATS) do
normalrule {
name = format.."_cc_proto",
ins = { "./"..format..".textpb", "+protoencode" },
outleaves = { format..".cc" },
commands = {
"%{ins[2]} %{ins[1]} %{outs} formats_"..format.."_pb"
}
}
end
normalrule {
name = "format_table",
ins = { "scripts/mktable.sh" },
outleaves = { "formats.cc" },
commands = {
"%{ins[1]} formats "..table.concat(FORMATS, " ").." > %{outs[1]}"
}
}
clibrary {
name = "formats",
srcs = {
"+format_table",
map(FORMATS, function(f) return "+"..f.."_cc_proto" end),
}
}