From 986be921f4095362831f1ddcd7e4543a856d5f90 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 22 Oct 2023 19:18:14 +0200 Subject: [PATCH] First working command-line executable. --- arch/build.py | 67 ++++++++++++++++++++++++++++++++++++++++ arch/mx/decoder.cc | 2 +- arch/tids990/decoder.cc | 2 +- build.py | 5 +++ build/ab.py | 8 ++--- build/c.py | 15 ++++++--- build/pkg.py | 4 +-- config.py | 5 +++ dep/libusbp/build.py | 68 +++++++++++++++++++++++++++++++++-------- lib/build.py | 8 +++-- src/build.py | 5 +++ 11 files changed, 161 insertions(+), 28 deletions(-) diff --git a/arch/build.py b/arch/build.py index 426b90a8..6ef55eed 100644 --- a/arch/build.py +++ b/arch/build.py @@ -1,3 +1,4 @@ +from build.c import clibrary from build.protobuf import proto, protocc proto( @@ -23,3 +24,69 @@ proto( "./zilogmcz/zilogmcz.proto", ], ) + +clibrary( + name="arch", + srcs=[ + "./aeslanier/decoder.cc", + "./agat/agat.cc", + "./agat/decoder.cc", + "./agat/encoder.cc", + "./amiga/amiga.cc", + "./amiga/decoder.cc", + "./amiga/encoder.cc", + "./apple2/decoder.cc", + "./apple2/encoder.cc", + "./brother/decoder.cc", + "./brother/encoder.cc", + "./c64/c64.cc", + "./c64/decoder.cc", + "./c64/encoder.cc", + "./f85/decoder.cc", + "./fb100/decoder.cc", + "./ibm/decoder.cc", + "./ibm/encoder.cc", + "./macintosh/decoder.cc", + "./macintosh/encoder.cc", + "./micropolis/decoder.cc", + "./micropolis/encoder.cc", + "./mx/decoder.cc", + "./northstar/decoder.cc", + "./northstar/encoder.cc", + "./rolandd20/decoder.cc", + "./smaky6/decoder.cc", + "./tids990/decoder.cc", + "./tids990/encoder.cc", + "./victor9k/decoder.cc", + "./victor9k/encoder.cc", + "./zilogmcz/decoder.cc", + ], + hdrs={ + "arch/ibm/ibm.h": "./ibm/ibm.h", + "arch/apple2/data_gcr.h": "./apple2/data_gcr.h", + "arch/apple2/apple2.h": "./apple2/apple2.h", + "arch/smaky6/smaky6.h": "./smaky6/smaky6.h", + "arch/tids990/tids990.h": "./tids990/tids990.h", + "arch/zilogmcz/zilogmcz.h": "./zilogmcz/zilogmcz.h", + "arch/amiga/amiga.h": "./amiga/amiga.h", + "arch/f85/data_gcr.h": "./f85/data_gcr.h", + "arch/f85/f85.h": "./f85/f85.h", + "arch/mx/mx.h": "./mx/mx.h", + "arch/aeslanier/aeslanier.h": "./aeslanier/aeslanier.h", + "arch/northstar/northstar.h": "./northstar/northstar.h", + "arch/brother/data_gcr.h": "./brother/data_gcr.h", + "arch/brother/brother.h": "./brother/brother.h", + "arch/brother/header_gcr.h": "./brother/header_gcr.h", + "arch/macintosh/data_gcr.h": "./macintosh/data_gcr.h", + "arch/macintosh/macintosh.h": "./macintosh/macintosh.h", + "arch/agat/agat.h": "./agat/agat.h", + "arch/fb100/fb100.h": "./fb100/fb100.h", + "arch/victor9k/data_gcr.h": "./victor9k/data_gcr.h", + "arch/victor9k/victor9k.h": "./victor9k/victor9k.h", + "arch/rolandd20/rolandd20.h": "./rolandd20/rolandd20.h", + "arch/micropolis/micropolis.h": "./micropolis/micropolis.h", + "arch/c64/data_gcr.h": "./c64/data_gcr.h", + "arch/c64/c64.h": "./c64/c64.h", + }, + deps=["lib", "lib+config_proto_lib", "+protocol"], +) diff --git a/arch/mx/decoder.cc b/arch/mx/decoder.cc index daec99fa..1404f0bf 100644 --- a/arch/mx/decoder.cc +++ b/arch/mx/decoder.cc @@ -1,6 +1,6 @@ #include "lib/globals.h" #include "lib/decoders/decoders.h" -#include "mx/mx.h" +#include "arch/mx/mx.h" #include "lib/crc.h" #include "lib/fluxmap.h" #include "lib/decoders/fluxmapreader.h" diff --git a/arch/tids990/decoder.cc b/arch/tids990/decoder.cc index 5baddc66..5653f475 100644 --- a/arch/tids990/decoder.cc +++ b/arch/tids990/decoder.cc @@ -1,7 +1,7 @@ #include "lib/globals.h" #include "lib/decoders/decoders.h" #include "lib/encoders/encoders.h" -#include "tids990/tids990.h" +#include "arch/tids990/tids990.h" #include "lib/crc.h" #include "lib/fluxmap.h" #include "lib/decoders/fluxmapreader.h" diff --git a/build.py b/build.py index fc82e3b5..d862396b 100644 --- a/build.py +++ b/build.py @@ -1,6 +1,11 @@ from build.ab import export from build.c import clibrary from build.protobuf import proto, protocc +from build.pkg import package + +package(name="protobuf_lib", package="protobuf") +package(name="z_lib", package="zlib") +package(name="fmt_lib", package="fmt") clibrary(name="protocol", hdrs={"protocol.h": "./protocol.h"}) diff --git a/build/ab.py b/build/ab.py index 70e85c13..40572ab7 100644 --- a/build/ab.py +++ b/build/ab.py @@ -243,11 +243,11 @@ def targetof(s, cwd): t.materialise() return t - if s.startswith("+"): - s = cwd + s - if s.startswith("./"): + if s.startswith(".+"): + s = cwd + s[1:] + elif s.startswith("./"): s = normpath(join(cwd, s)) - if s.startswith("$"): + elif s.startswith("$"): return fileinvocation(s) if "+" not in s: diff --git a/build/c.py b/build/c.py index 0bd2995a..57e4eb4a 100644 --- a/build/c.py +++ b/build/c.py @@ -97,6 +97,7 @@ def clibrary( "clibrary contains no sources and no exported headers" ) + ldflags = [] libraries = [d for d in deps if hasattr(d, "clibrary")] for library in libraries: if library.clibrary.cflags: @@ -124,7 +125,7 @@ def clibrary( i = i + 1 if srcs: - nr = None + hr = None if hdrcs: hr = normalrule( name=f"{name}_hdrs", @@ -151,7 +152,7 @@ def clibrary( commands=commands if actualsrcs else [], ) - self.clibrary.ldflags = [] + self.clibrary.ldflags = ldflags self.clibrary.cflags = ["-I" + hr.normalrule.objdir] if hr else [] else: r = normalrule( @@ -163,7 +164,7 @@ def clibrary( ) r.materialise() - self.clibrary.ldflags = [] + self.clibrary.ldflags = ldflags self.clibrary.cflags = ["-I" + r.normalrule.objdir] @@ -201,7 +202,9 @@ def cprogram( deps: Targets = [], cflags=[], ldflags=[], - commands=["$(CC) -o {outs[0]} {ins} {ldflags}"], + commands=[ + "$(CC) -o {outs[0]} -Wl,--start-group {ins} -Wl,--end-group {ldflags}" + ], label="CLINK", ): programimpl( @@ -226,7 +229,9 @@ def cxxprogram( deps: Targets = [], cflags=[], ldflags=[], - commands=["$(CXX) -o {outs[0]} {ins} {ldflags}"], + commands=[ + "$(CXX) -o {outs[0]} -Wl,--start-group {ins} -Wl,--end-group {ldflags}" + ], label="CXXLINK", ): programimpl( diff --git a/build/pkg.py b/build/pkg.py index 0da471e8..598a532e 100644 --- a/build/pkg.py +++ b/build/pkg.py @@ -22,10 +22,10 @@ def package(self, name, package=None, fallback: Target = None): emit(f"$(error Required package '{package}' not installed.)") emit("else") emit( - f"PACKAGE_CFLAGS_{package} := $(shell $(PKG_CONFIG) --cflags {package}" + f"PACKAGE_CFLAGS_{package} := $(shell $(PKG_CONFIG) --cflags {package})" ) emit( - f"PACKAGE_LDFLAGS_{package} := $(shell $(PKG_CONFIG) --ldflags {package}" + f"PACKAGE_LDFLAGS_{package} := $(shell $(PKG_CONFIG) --libs {package})" ) emit(f"PACKAGE_DEP_{package} := ") emit("endif") diff --git a/config.py b/config.py index e69de29b..08073692 100644 --- a/config.py +++ b/config.py @@ -0,0 +1,5 @@ +import platform + +windows = platform.system() == "Windows" +osx = platform.system() == "Darwin" +unix = not windows diff --git a/dep/libusbp/build.py b/dep/libusbp/build.py index c37e076e..5305c8f0 100644 --- a/dep/libusbp/build.py +++ b/dep/libusbp/build.py @@ -1,20 +1,64 @@ from build.c import clibrary +from build.pkg import package +from config import windows, osx, unix + +srcs = [ + "./src/async_in_pipe.c", + "./src/error.c", + "./src/error_hresult.c", + "./src/find_device.c", + "./src/list.c", + "./src/pipe_id.c", + "./src/string.c", + "./src/libusbp_internal.h", + "./include/libusbp_config.h", + "./include/libusbp.h", +] +deps = [] + +if windows: + srcs += [ + "./src/windows/async_in_transfer_windows.c", + "./src/windows/device_instance_id_windows.c", + "./src/windows/device_windows.c", + "./src/windows/error_windows.c", + "./src/windows/generic_handle_windows.c", + "./src/windows/generic_interface_windows.c", + "./src/windows/interface_windows.c", + "./src/windows/list_windows.c", + "./src/windows/serial_port_windows.c", + ] +elif osx: + srcs += [ + "./src/mac/async_in_transfer_mac.c", + "./src/mac/device_mac.c", + "./src/mac/error_mac.c", + "./src/mac/generic_handle_mac.c", + "./src/mac/generic_interface_mac.c", + "./src/mac/iokit_mac.c", + "./src/mac/list_mac.c", + "./src/mac/serial_port_mac.c", + ] +else: + package(name="udev_lib", package="libudev") + srcs += [ + "./src/linux/async_in_transfer_linux.c", + "./src/linux/device_linux.c", + "./src/linux/error_linux.c", + "./src/linux/generic_handle_linux.c", + "./src/linux/generic_interface_linux.c", + "./src/linux/list_linux.c", + "./src/linux/serial_port_linux.c", + "./src/linux/udev_linux.c", + "./src/linux/usbfd_linux.c", + ] + deps += [".+udev_lib"] clibrary( name="libusbp", - srcs=[ - "./src/async_in_pipe.c", - "./src/error.c", - "./src/error_hresult.c", - "./src/find_device.c", - "./src/list.c", - "./src/pipe_id.c", - "./src/string.c", - "./src/libusbp_internal.h", - "./include/libusbp_config.h", - "./include/libusbp.h", - ], + srcs=srcs, cflags=["-Idep/libusbp/include", "-Idep/libusbp/src"], + deps=deps, hdrs={ "libusbp_internal.h": "./src/libusbp_internal.h", "libusbp_config.h": "./include/libusbp_config.h", diff --git a/lib/build.py b/lib/build.py index 1317d403..743d8442 100644 --- a/lib/build.py +++ b/lib/build.py @@ -99,6 +99,7 @@ clibrary( "lib/bitmap.h": "./bitmap.h", "lib/bytes.h": "./bytes.h", "lib/config.h": "./config.h", + "lib/crc.h": "./crc.h", "lib/csvreader.h": "./csvreader.h", "lib/decoders/decoders.h": "./decoders/decoders.h", "lib/decoders/fluxdecoder.h": "./decoders/fluxdecoder.h", @@ -115,6 +116,7 @@ clibrary( "lib/image.h": "./image.h", "lib/imagereader/imagereader.h": "./imagereader/imagereader.h", "lib/imagewriter/imagewriter.h": "./imagewriter/imagewriter.h", + "lib/layout.h": "./layout.h", "lib/proto.h": "./proto.h", "lib/readerwriter.h": "./readerwriter.h", "lib/sector.h": "./sector.h", @@ -125,7 +127,7 @@ clibrary( }, deps=[ "+fl2_proto_lib", - "+config_proto_lib", + ".+config_proto_lib", "dep/libusbp", "dep/adflib", "dep/fatfs", @@ -150,7 +152,7 @@ proto( "./usb/usb.proto", "./vfs/vfs.proto", ], - deps=["+common_proto"], + deps=[".+common_proto"], ) -protocc(name="config_proto_lib", srcs=["+config_proto", "arch+arch_proto"]) +protocc(name="config_proto_lib", srcs=[".+config_proto", "arch+arch_proto"]) diff --git a/src/build.py b/src/build.py index 21a4832b..58742bec 100644 --- a/src/build.py +++ b/src/build.py @@ -30,7 +30,11 @@ cxxprogram( cflags=["-I."], deps=[ "+fl2_proto_lib", + "+fmt_lib", + "+protobuf_lib", "+protocol", + "+z_lib", + "arch", "dep/adflib", "dep/agg", "dep/fatfs", @@ -39,5 +43,6 @@ cxxprogram( "dep/stb", "lib", "lib+config_proto_lib", + "src/formats", ], )