From 6295a0b7e68849c7f4bfef5dbfaca8480dc27636 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 11 Sep 2023 21:43:43 +0300 Subject: [PATCH] separate programs by language --- cpp/Makefile | 46 +++++++++++++++++++++++++++++++++++++++++++++ cpp/tinierfetch.cpp | 10 ++++++++++ go/go.mod | 3 +++ go/main.go | 15 +++++++++++++++ rs/Cargo.lock | 7 +++++++ rs/Cargo.toml | 16 ++++++++++++++++ rs/main.rs | 9 +++++++++ tinierfetch.cpp | 4 ---- 8 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 cpp/Makefile create mode 100644 cpp/tinierfetch.cpp create mode 100644 go/go.mod create mode 100644 go/main.go create mode 100644 rs/Cargo.lock create mode 100644 rs/Cargo.toml create mode 100644 rs/main.rs delete mode 100644 tinierfetch.cpp diff --git a/cpp/Makefile b/cpp/Makefile new file mode 100644 index 0000000..b51e3b5 --- /dev/null +++ b/cpp/Makefile @@ -0,0 +1,46 @@ +# Compiler +CXX = g++ + +# Source files +SOURCES = tinierfetch.cpp + +# Output binaries +OUTPUT_SIZE = tinierfetch-cpp-size +OUTPUT_SPEED = tinierfetch-cpp-speed + +# Compiler flags for size optimization +CXXFLAGS_SIZE = -Os -ffunction-sections -fdata-sections \ + -fno-exceptions -fno-stack-protector -fno-rtti \ + -ffunction-sections -fdata-sections -fno-math-errno \ + -fno-unroll-loops -fmerge-all-constants -fno-ident \ + -mfpmath=387 -mfancy-math-387 -s -flto \ + -fno-asynchronous-unwind-tables -fsingle-precision-constant + +# Compiler flags for speed optimization +CXXFLAGS_SPEED = -O3 -march=native -funroll-loops -finline-functions \ + -ffast-math -fno-exceptions -fno-stack-protector -fno-rtti \ + -ffunction-sections -fdata-sections -fno-math-errno \ + -fmerge-all-constants -fno-ident -mfpmath=387 \ + -mfancy-math-387 -s -flto -fno-asynchronous-unwind-tables \ + -fsingle-precision-constant + +# Linker flags (common for both targets) +LDFLAGS = -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none -Wl,--strip-all + +# Makefile targets +all: optimize-size optimize-speed + +optimize-size: $(OUTPUT_SIZE) + +optimize-speed: $(OUTPUT_SPEED) + +$(OUTPUT_SIZE): $(SOURCES) + $(CXX) $(CXXFLAGS_SIZE) $(LDFLAGS) $(SOURCES) -o ../bin/$(OUTPUT_SIZE) + +$(OUTPUT_SPEED): $(SOURCES) + $(CXX) $(CXXFLAGS_SPEED) $(LDFLAGS) $(SOURCES) -o ../bin/$(OUTPUT_SPEED) + +clean: + rm -f $(OUTPUT_SIZE) $(OUTPUT_SPEED) + +.PHONY: all optimize-size optimize-speed clean diff --git a/cpp/tinierfetch.cpp b/cpp/tinierfetch.cpp new file mode 100644 index 0000000..4cd9642 --- /dev/null +++ b/cpp/tinierfetch.cpp @@ -0,0 +1,10 @@ +#include +#define l getenv +#define i << +int main() { + std::cout i "\e[31muser:\e[0m " i l("USER") i "\n\e[32msh:\e[0m " i l("SHELL") + i "\n\e[33mterm:\e[0m " i l("TERM") i "\n\e[34mlocale:\e[0m " i l("LANG") + i "\n\x1b[35mcolors: \x1b[0m\x1b[41m \x1b[42m \x1b[43m \x1b[44m " + "\x1b[45m \x1b[0m\n"; + return 0; +} diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000..0176175 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,3 @@ +module tinierfetch-go + +go 1.20 diff --git a/go/main.go b/go/main.go new file mode 100644 index 0000000..8e20985 --- /dev/null +++ b/go/main.go @@ -0,0 +1,15 @@ +package main + +import "os" + +func main() { + e := []string{"USER", "SHELL", "TERM", "LANG"} + c := []string{"31", "32", "33", "34"} + r := "\033[0m" + + for i, v := range e { + os.Stdout.WriteString("\033[0;" + c[i] + "m" + v + ":\033[0m " + os.Getenv(v) + "\n") + } + + os.Stdout.WriteString("\033[35mcolors: \033[0m\033[41m \033[42m \033[43m \033[44m \033[45m " + r + "\n") +} diff --git a/rs/Cargo.lock b/rs/Cargo.lock new file mode 100644 index 0000000..fbbb14e --- /dev/null +++ b/rs/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "tinierfetch-rs" +version = "0.1.0" diff --git a/rs/Cargo.toml b/rs/Cargo.toml new file mode 100644 index 0000000..66d7ba0 --- /dev/null +++ b/rs/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "tinierfetch-rs" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "tinierfetch-rs" +path = "main.rs" + +[profile.release] +strip = true +opt-level = "z" +lto = true +codegen-units = 1 +panic = "abort" + diff --git a/rs/main.rs b/rs/main.rs new file mode 100644 index 0000000..ab90fea --- /dev/null +++ b/rs/main.rs @@ -0,0 +1,9 @@ +use std::env; + +fn main() { + ["USER", "SHELL", "TERM", "LANG"] + .iter() + .for_each(|var| println!("{}: {}", var, env::var(var).unwrap_or_default())); + + println!("\x1B[35mcolors: \x1B[0m\x1B[41m \x1B[42m \x1B[43m \x1B[44m \x1B[45m \x1B[0m"); +} diff --git a/tinierfetch.cpp b/tinierfetch.cpp deleted file mode 100644 index de56d24..0000000 --- a/tinierfetch.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include -#define e getenv -#define i << -int main() { std::cout i "\e[31muser:\e[0m " i e("USER") i "\n\e[32msh:\e[0m " i e("SHELL") i "\n\e[33mterm:\e[0m " i e("TERM") i "\n\e[34mlocale:\e[0m " i e("LANG") i "\n\x1b[35mcolors: \x1b[0m\x1b[41m \x1b[42m \x1b[43m \x1b[44m " "\x1b[45m \x1b[0m\n"; return 0;}