sophuwu.site > crls
Made make file.
sophuwu sophie@sophuwu.site
Sun, 06 Aug 2023 13:41:17 +0200
commit

10e994613ebedf2fca0d9d812811e5a6705cf9bc

parent

fa567199f75ee229ab17e1f0f0b30b01847f7908

3 files changed, 63 insertions(+), 13 deletions(-)

jump to
A Makefile

@@ -0,0 +1,55 @@

+ifeq ($(shell command -v cmake), ) +COMPCMD = $(CC) --std=c++17 -o build/rls main.cpp +COMPMSG = $(CC) +else +ifeq ($(shell command -v ninja), ) +COMPCMD = cmake -S . -B build && cmake --build build +COMPMSG = cmake +else +COMPCMD = cmake -GNinja -S . -B build && cmake --build build +COMPMSG = cmake and ninja +endif +CMAKELISTS = CMakeLists.txt +endif + +ifeq ($(shell command -v strip), ) +STRIPCMD = echo Strip not found. Binary size may be larger than expected. +else +STRIPCMD = strip --strip-all build/rls +endif +ifeq ($(shell command -v upx), ) +UPXCMD = echo UPX not found. Binary size may be larger than expected. +else +UPXCMD = upx --best build/rls +endif + +build: main.cpp $(CMAKELISTS) + @echo Building with $(COMPMSG). + @sleep 2 + @mkdir -p build + @$(COMPCMD) + @echo Compiled successfully. + @echo Program is located at build/rls. + @echo \"make small\" to reduce binary size. Requires strip and/or upx. + @echo \"sudo make install\" to install the program into /usr/local/bin. + @echo And \"make clean\" to remove the build directory. + +clean: build + @echo Cleaning up. + @rm -rf build + @echo Cleaned up successfully. + +small: build/rls + @cp build/rls build/rls.bak + @echo Stripping binary. + @$(STRIPCMD) + @$(UPXCMD) + @echo Old Sise: $(shell du -sh build/rls.bak) + @echo New size: $(shell du -sh build/rls) + + +install: build/rls + @echo Installing to /usr/local/bin. + @sudo cp build/rls /usr/local/bin/rls + @echo Installed successfully. + @echo Run \"rls\" to use the program.
D build.sh

@@ -1,6 +0,0 @@

-#!/bin/bash -cmake -S . -B build -GNinja && \ -cmake --build build && \ -chmod +x build/rls && \ -strip --strip-all build/rls && \ -upx --best build/rls
M main.cppmain.cpp

@@ -126,7 +126,7 @@ else item.size = convsize(0);

files.push_back(item); } len /= i; - return (10+len)*10; + return (5+len)*5; } int charcmp(char a, char b) {

@@ -139,9 +139,11 @@

int strcomp(std::string a, std::string b) { int len = a.length(); if (b.length()<len) len=b.length(); - char c[len] = ""; + char c[len]; + c[0] = 0; strncat(c, a.c_str(),len); - char d[len] = ""; + char d[len]; + d[0] = 0; strncat(d,b.c_str(),len); int cmp; for (int i = 0; i < len; i++) {

@@ -190,15 +192,14 @@ sortdir(files,dirlist);

if (dirlist.size()<30) r.init(dirlist.size()); - r.print2d(path+"\n", path.length()); + r.print2d(path+"\n", len); r.next(); for (int i = 0; i < dirlist.size(); i++) { - printf(" "); - r.print2d(dirlist[i], len); + r.print2d(" "+dirlist[i], len); r.next(); } - r.print2d("\nFolders / Files / Total: " + std::to_string(folders.size()) + '/' + std::to_string(files.size()) + '/' + std::to_string(folders.size()+files.size()) + '\n', len); + r.print2d("Folders / Files / Total: " + std::to_string(folders.size()) + '/' + std::to_string(files.size()) + '/' + std::to_string(folders.size()+files.size()) + '\n', len); return 0; }