separate programs by language

This commit is contained in:
raf 2023-09-11 21:43:43 +03:00
parent 45f6cbb46a
commit 6295a0b7e6
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
8 changed files with 106 additions and 4 deletions

46
cpp/Makefile Normal file
View file

@ -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

10
cpp/tinierfetch.cpp Normal file
View file

@ -0,0 +1,10 @@
#include <iostream>
#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;
}

3
go/go.mod Normal file
View file

@ -0,0 +1,3 @@
module tinierfetch-go
go 1.20

15
go/main.go Normal file
View file

@ -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")
}

7
rs/Cargo.lock generated Normal file
View file

@ -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"

16
rs/Cargo.toml Normal file
View file

@ -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"

9
rs/main.rs Normal file
View file

@ -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");
}

View file

@ -1,4 +0,0 @@
#include <iostream>
#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;}