gnu

#define gnu: \ I----------------------------\ I _____ _ _ _ _ \ I | __ \| \ | | | | | \ I | | \/| \| | | | | \ I | | __ | . ` | | | | \ I | |_\ \| |\ | |_| | \ I \____/\_| \_/\___/ \ I----------------------------I GNU_Project:"Gnu is Not Unix" /* , , / \ ((__-^^-,-^^-__)) `-_---' `---_-' `--|o` 'o|--' \ ` / ): :( :o_o: "-" */ https://www.gnu.org/software/software.html https://savannah.gnu.org/ irc.libera.chat/6697 #gnu "Debugging/GDB" ---- ld ---- • "gnu Linker"; not an anagram ldconfig : configure dynamic linking — p : list installed C++ libraries ------ gzip ------ File_extentions: .gz : gnu zip file, ie one that was (or atleast as if were) created with gzip gzip [options] [file] — d : decompress — k : keep original — v : verbose — r : recursive — 1 : fast — 9 : best --best : alias of -9 ----- tar ----- gnu Tape ARchive File_extentions: .tar : a tape archive file, ie one that was (or atleast as if were) created with tar tar [options] [file] — A : appends tar to an archive — c : creates — r : appends files to an archive — x : extracts --list : lists — f [file] : specifies output file name; mandatory — v : verbose; show the files being worked on; each instance of '--verbose' on the command line increases the verbosity level by one, so if you need more details on the output, specify it twice. --verify : attempts to verify file integrity; cannot be used when compressing --remove-files : remove the original files — z : uses gzip on the file — I "[...]" : specify compression program and pass options to it ---- bc ---- Basic Calculator bc [options] [file]

coreutils

#define coreutils: https://jpospisil.com/2023/12/19/the-hidden-gems-of-moreutils # short introduction to every coreutils program https://www.youtube.com/playlist?list=PLp31D6HATKfeEHEFqFo5hlCOYwHi4Sl9O # coreutils tier list https://www.youtube.com/watch?v=2oGLlG3Whfk # on useless coreutils programs https://www.youtube.com/watch?v=WpqC-CZKMjw • coreutils is a collection of user-space tools which make a Unix-like operating system usable • based around POSIX • coreutils is GNU's main claim-to-fame after GCC, however, do to various quality concerns there are many alternatives trying to replace it; the most successful one is busybox • coreutils use "--help" and do not support "-h" Host_and_OS: arch date chroot hostid id logname nice nohup nproc pinky runcon stty tty uname who whoami users File_management: cat chgrp chown chmod chcon cp dd df dir dircolors du link ls mkdir mkfifo mknod mktemp mv pwd rm rmdir stat tac touch unlink vdir Line_oriented: comm fold head join nl paste shuf sort ln tail uniq Character_oriented: csplit cut expand fmt pr split wc tr truncate unexpand Paths: basename dirname pathchk readlink realpath Encoding_and_Cryptography: b2sum base32 base64 basenc cksum factor md5sum numfmt od sha1sum sha224sum sha256sum sha384sum sha512sum sum Scripting: echo env expr false install printenv printf seq sleep stdbuf yes sync tee test timeout true Misc: ptx shred tsort

gcc

#define gcc:: \ ---------\ gcc/g++ \ ---------I "Gnu Compiler Collection""Gnu C Compiler/GNU C++ Compiler (GNU Compiler)""Did you know that the first part of GCC stands for Garbage Collector?\ Because it collects your garbage code and compiles it." • GCC (C compiler) is part of GCC (compiler collection) g++ [options] [files] : compiles [files] General: — o [name] : output file will be named [name] — W<string> : turns on <string> warning — fpermissive : downgrade some diagnostics about nonconforming code from errors to warnings; thus, using -fpermissive allows some nonconforming code to compile — x [lang] : explicitly specifies [lang] language to input file be interpreted as Compialation: — E : preprocess only — S : compile only; do not assemble or link — c : compile and assemble; do not link; results in an object file Preprocessor: — D [name](=[...]) : define a macro expanding to 1 or [...] Compialation: — O[l] : adjust optimization level to [l] 0 - dont optimize; default 1 - optimize 2 - optimize even more 3 - optimize yet more fast- optimize for speed s - optimize for size g - optimize for debuging; this option is crap, -O0 works much better for debugging — mpreferred-stack-boundary=<int> : attempt to keep the stack boundary aligned to 2 raised to <int> byte boundary; the default is 4 — f-stack-protector : enabled by default; uses a Canary as stack smashing protection — fno-stack-protector : turns off the Canary; ([above]) — z execstack : allow to execute stack Linking: — l[library] : links [library] — std=[v] : use standard template library version [v] for compilation — static : do static linking — iquote [path] : add directory to the #include "[...]" preprocessor directories to be searched; thats why no sane devs do "../include/[...].h" you moron; searched before the standard paths, therefor can be used to override standard headers with ones own Debuging: — g : supplies debugging symbols; made to be gdb compatible — ggdb : "-g" plus extra symbols for gdb specifically — pg : add gprof (execution profiler) support — fno-inline Flag_packs: — reasonable warnings: -Wall -Wextra -Wpedantic — debugmaxxing: -O0 -ggdb -pg -fno-inline — all warnings for real (NOT recommended): $(gcc -Q --help=warning | sed -e 's/^\s*\(\-\S*\)\s*\[\w*\]/\1 /gp;d' | tr -d '\n') Pragmas: #pragma once : header guard alternative, but worse #pragma GCC <...> : GCC specific and reserved pragma namespace poison <symbol>+ : make any mentions of the listed symbols error out; used for ensuring no team member may use them system_header : threat file as a system header • supresses all warnings except those by #warning dependency "<file>" : ?! regions: • used for defining an optionally named chunk of code • has no compiler effect • editors may recognize regions to apply folding • external tools may recognize regions for arbitrary reasons {grouping} { #pragma region <name> <...> #pragma endregion <name> } Environment_variables: ${GCC_COLORS} Include_order: ${PWD}/<header>.gch ---> -I dirs <header>.gch ---> ${PWD}/<header> ---> -I dirs <header>

make

#define make:: \ ------\ make \ ------I "gnu MAKE" • for make to know what to do a makefile is needed make ([options]) ([target]) : runs the make-script located at $PWD; if no [target] is passed the one at the top of the makefile will be called — e : ensures that environment variables will be used when ever possible, unless the "override" keyword is used — n : do not stop at errors and do not run the commands just print them; essentially a dry run — B : execute even when all files are up to date --print-data-base : prints default set of rules and variables --no-builtin-rules : disables the usage of builtin pattern rules — the following file names will be automatically recognized by make as a makefile: • GNUmakefile • makefile • Makefile //GNU's recomendation Commenting: #[comment] : single line comment Rules: make doesnt support calling rules within rules as if they were functions, this is because its serious about its prerequisite paradigm, however theres nothing stopping you from recursively invoking make with different targets { [target]:(:) ([prerequisite] [...]) [.RECIPEPREFIX][recipe] [...] } [target]: ([specialty]) [name] • the argument you'll pass make • like a function name • can be a space separated list of multiple targets, in which case the following behaviour will be produced: { [target1] [targer2]: [rule1] [rule2] [rule3] [...] //### Same As ### [target1]: [rule1] [rule2] [rule3] [...] [target2]: [rule1] [rule2] [rule3] [...] } [prerequisite]: • space separated list of other [target]s • will also be executed if they are not up to date [recipe]: ([pre-line symbol]*)[command] [pre-line symbol]: — : do not terminate Make execution if this command returns with an error code (non 0) @ : do not echo execution { example: echo "echoing..." | V echo "echoing..." echoing... //### ### ### ### example: @echo "echoing..." | V echoing... } [command]: • $(SHELL) commands • each is executed in its own sub shell • multi-lining is done by post fixing the continued line with a '\' • non-pattern rules cannot deppend on pattern rules • see rule specific variables AT ../Variables Conventional_and_common_make_rules: all : builds the application install : installs the application clean : deletes binaries distclean : deletes everything which is not in the distributed version TAGS : generates tags table ?! info : generates GNU info files check : runs tests Pattern_rules: non-pattern rules cant depend on pattern rules • pattern rules do not expand variables in dependencies • any rule containing a '%' • as the name suggests its pattern matched to see whether executing it would help getting the desired target { %.c: g++ -c ${@} -o ${*}.o } Builtin_ones: %.o: %.c $(COMPILE.c) $(OUTPUT_OPTION) $< %.c: %.l @$(RM) $@ $(LEX.l) $< > $@ %: %.c $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@ Static: [subjects]: [pattern_rule] : only do a matching on files that are in the [subjects] list { $(OBJECTS): %.o : %c ${CC} -c $(CFLAGS) $< -o $@ } Suffix_rules: • predecessor of pattern rules • out dated [suffix2]([suffix1]([...])): [...] • [suffix] is meant to be a file extension suffix • only known suffexes are recognized • known suffexes are defined with the help of a special target .SUFFIXES • prerequisets are listed before the target, therefor: { .c.o: $(COMPILE.c) $(OUTPUT_OPTION) $< // Is equivalent to %.o: %.c $(COMPILE.c) $(OUTPUT_OPTION) $< } Double_colon_rules: {[target]:: [prerequisete1] ([...]) [.RECIPEPREFIX][recipe] [...] [target]:: [prerequisete2] ([...]) [.RECIPEPREFIX][recipe] [...] } • normally if a rule is defined multiple times only one would be run; however, this way the "two" targets are going to be managed as a different entity Special_targets: • used for changing makes default behaviours .SUFFIXES: • defines known suffexes (see AT ../Suffix_rules) • default definition: .SUFFIXES: .out .a .ln .o .c .cc .C .cpp .p .f .F .r .y .l Phony: .PHONY: <target>+ • declares that the specified targets, under no circumstances should be treated as a file and should always be executed; • can be used to improve performance by skipping known to be obsolete up-to-date checks # Example usage $ tree ./ ├── Makefile └── test/ └── test.sh 2 directories, 2 files $ bat Makefile ───────┬────────────────── │ File: Makefile ───────┼────────────────── 1 │ test: 2 │ test/test.sh ───────┴────────────────── $ make test make: 'test' is up to date. $ echo '.PHONY: test' >> Makefile $ make test test/test.sh This is test.sh; We are now testing... .ONESHELL: : run all statements of individual targets in a single shell; useful when Make is used more like a simple shell wrapper, rather than a robust build-system Variables: [name] [assignment_operator] [value] : defines variable [assignment_operator]: := : declares and assigns simple variable ::= : declares and assigns simple variable = : declares and assigns recursively expanded variable ?= : declares and assigns recursively expanded variable only if it doesnt hold a value yet += : appends [value] to variable [name] [target]:(:) [name] [assignment_operator] [value] : modifies [name]s value only inside the scope of [target] $([name]) : references variable ${[name]} : references variable — simple variables: • evaluated on assignment — recursively expanded variables • evaluated upon expansion (each time) — canned sequance • practically a glorified copy-paste • described as variable tho • also used as functions • pseudo-functions really ○ syntax { define [name] [...] endef } ○ calling (; fix your bloody syntax file; ?! $(call [name](,[args])) • [args] can be referenced to with "$[num]" where [num] is the n-th thing passed • escape '$' by using "$$" • system variables are automatically available to make • they used to be called macros • they hold string values which going to be substituted upon encountering their name prefix with a '$' and enclosed in parentheses (macro is more accurate to describe this behaviour in my opinion) • [name] can contain any characters except: '=', ':' and '#'; recommended to stick with ascii tho; "A variable name can contain almost any characters including most punctuation.\ Even spaces are allowed, but if you value your sanity you should avoid them." • variable names starting with '.' are reserved • commandline beats makefile beats envirement Built_in: • not only predefined, but also used by builtin rules AR : archive maintaining program ARFLAGS : flags for $(AR) AS : assembly compiler ASFLAGS : flags for $(AS) CC : C complier CFLAGS : flags for $(CC) CXX : C++ compiler CXXFLAGS : flags for $(CXX) CPP : C preprocessor CPPFLAGS : flags for $(CPP) FC : Fortran compiler FFLAGS : flags for $(FC) RFLAGS : flags for $(FC) M2C : Modula-2 compiler PC : Pascal compiler PFLAGS : flags for $(PC) CO : program for extraction from RCS GET : program for extraction from SCCS GFLAGS : flags for $(GET) LEX : Lex transformer LFLAGS : flags for $(LEX) YACC : Yacc transformer YFLAGS : flags for $(YACC) LINT : Lint program LINTFLAGS : flags for $(LINT) MAKEINFO : Texinfo - Info file transformer TEX : TeX DVI - Tex source transformer TEXI2DVI : TeX DVI - Texinfo transformer WEAVE : Web - TeX transformer CWEAVE : C Web - TeX transformer TANGLE : Web - Pascal transformer CTANGLE : C Web - C transformer RM : program to remove files LDFLAGS : flags for ld (the GNU linker) LDLIBS : library include flags { -lncurses } for ld (the GNU linker) COMPILE: COMPILE.* COMPILE.c : ${CC} ${CFLAGS} ${TARGET_ARCH} -c COMPILE.cpp : ${CXX} ${CXXFLAGS} ${TARGET_ARCH} -c LINK: LINK.* LINK.c : ${CC} ${LDFLAGS} LINK.cpp : ${CXX} ${LDFLAGS} Meta_informational: MAKE_VERSION : version number of current make instance CURDIR : directory from which make was invoked from ($(PWD)) MAKEFILE_LIST : a list of all files make has read (default, import-ed ones and command line specified ones) MAKECMDGOALS : a list of all targets specified on the command line .VARIABLES : a list of all variables read from the Makefile so far Special_variables: .RECIPEPREFIX : the char that must go before every [recipe]; tab by default VPATH : space separated list of folders to be searched for targets Automatic_variables: • initialized upon matching a rule @ : file name representing the target % : roughly equivalent to the Bourne Again Shell's '*' < : file name of the first prerequisite ? : names of all prerequisites that are newer than the target; separated by spaces + : names of all prerequisites; separated by spaces ^ : $+, but with duplicates removed * : file name representing the target, with the (last) extension sliced off • to get full paths, instead of just the file names, postfix the variables with a 'D' { $(@D) } • postfixing them with a 'F' indicates that you only want the file name (that's also the default behaviour tho) Expansions: ${[variable]:[string1]=[string2]} :replace; equivalent to $(subst [string1],[string2],${[variable]}), but less obvious in intent Logic: if: { [condition] [...] ([else] [...] ) endif } [conditions]: ifeq([string1], [string2]) : whether [string1] and [string2] are equal [...]: • ANY valid make statement Functions: //?! — [text]: • a string, however meant to be a space separated list of semi-related words • a list of files for example • the words are always 1 indexed { word(), wordlist(), etc. } $(Name [Args]) call [function](,[args]) : calls (user defined) canned sequence [function] strip <string> : returns <string> with all whitespaces removed filter [pattern],[text] : returns only the words from [text] which match [pattern]; [pattern] being a make style '%', only the first '%' expands, the rest are treated literally filter-out [pattern],[text] : logical not of filter(); see ABOVE findstring <string>,[text] : returns [text] if it contains <string> and nothing otherwise subst [string-1],[string-2],[text] : substitute; replaces all occurrences of [string1] with [string2] in [text] patsubst [string1],[string2],[text] : pattern substitute; same as ABOVE, however [string1] can contain a single '%' addprefix <string>,[array] : prefixes all elements of [array] with <string> addsuffix <string>,[array] : postfixes all elements of [array] with <string> words [text] : returns number of words in [text] word <int>,[text] : returns <int>th word from [text] wordlist [int-1],[int-2],[text] : returns the words from [int-1] till [int-2] inclusively sort [text] : returns [text] with the words arranged in lexical order and with all duplicates removed shell [...] : returns stdout output of shell command [...] warning <string> : prints <string> as a warning message error <string> : terminates makes execution and prints <string> as the error message dir <string> : like dirname; removes all file name portions from <string>; nukes directory names with spaces notdir <string> : like basename; removes all path name portions from <string>; nukes file names with spaces if <...>, <...>, <...> Directives: • [var] stands for [variable] ifdef [var] : includes code till next endif if [var] is defined; an empty string is trated as not defined ifndef [var] : includes code till next endif if [var] is not defined; an empty string is trated as not defined ifeq "[var1]" "[var2]" : includes code till next endif if [var1] and [var2] are equal ifneq "[var1]" "[var2]" : includes code till next endif if [var1] and [var2] are not equal endif : marks the ending of an if directive define [name] : starts definition of canned sequence called [name] (see AT ../Variables) endef : marks the ending of canned sequance (see AT ../Variables) vpath [pattern] [paths] : makes targets matching [pattern] search for targets in [paths], which is a space separated list of paths; { vpath %.c scr } include [paths] : open and interpret files specified by [paths], which is a space separated list of files Operators: [variable] ?= [value] : assigns [value] to [variable] only if [variable] was defined previously Globs: • some times refer to as wildcards • identical to the Bourne Again Shell globs (see AT Bash/Globs) ### Anons Makefile template ### .PHONY: test clean .SUFFIXES: # --- Paths / files SOURCE.d := source/ OBJECT.d := object/ LIB.d := library/ SOURCE := main.c h.c cpp.cpp OBJECT := ${SOURCE} OBJECT := $(subst .cpp,.o,${OBJECT}) OBJECT := $(subst .c,.o,${OBJECT}) GENSOURCE := l.yy.c y.tab.c vpath %.c ${SOURCE.d} vpath %.l ${SOURCE.d} vpath %.y ${SOURCE.d} vpath %.cpp ${SOURCE.d} vpath %.yy.c ${OBJECT.d} vpath %.tab.c ${OBJECT.d} OUT := example # --- Tools/Flags ifeq (${DEBUG}, 1) LFLAGS += --debug --trace YFLAGS += --debug CPPFLAGS += -DDEBUG CFLAGS.D += -Wall -Wextra -Wpedantic CFLAGS.D += -O0 -ggdb -fno-inline CFLAGS.D += -fsanitize=address,undefined CFLAGS += ${CFLAGS.D} CXXFLAGS += ${CFLAGS.D} else CFLAGS += -O3 -flto=auto -fno-stack-protector endif CPPFLAGS += -I${SOURCE.d} -I${OBJECT.d} -I${LIB.d} LDLIBS := # --- Rule Section --- all: ${OUT} ${OUT}: ${GENSOURCE} ${OBJECT} ${LINK.c} -o $@ $(addprefix ${OBJECT.d}/,${OBJECT} ${GENSOURCE}) ${LDLIBS} %.o: %.c ${COMPILE.c} -o ${OBJECT.d}/$@ $< %.o: %.cpp ${COMPILE.c} -o ${OBJECT.d}/$@ $< %.yy.c: %.l flex -o ${OBJECT.d}/$@ --header=${OBJECT.d}/$(subst .c,.h,$@) $? %.tab.c: %.y bison -o ${OBJECT.d}/$@ --header=${OBJECT.d}/$(subst .c,.h,$@) $? %.yy.o: ${OBJECT.d}/%.yy.c ${COMPILE.c} -o $@ $< %.tab.o: %.tab.c ${COMPILE.c} -o $@ $< test: cmdtest --fast clean: -${RM} $(or ${OBJECT.d},#)/* -${RM} ${OUT} # --- Notes --- # I did not comment into the source so you may use it as a template easier. # # With `.SUFFIXES:`, we empty out the default rules # because they do not comply with our project structure. # They also have a tendency to delete intermediate files. # this is in good spirit as it could be a storage space concern, # however on modern systems and for reasonable projects # this behaviour is useless at best and annoying at worst. # # We make use of Make's support for variables with dots in their names, # because it helps a lot with readability. # # We specify targets explicitly. One could use `find` in a subshell, # however having a static, logically organized list is better for # debugging. # # `vpath` helps us avoid `${SOURCE.d}/%.c` and such, # removing visual clutter. It also has nicer syntax than `VPATH`. # # We account for `DEBUG` being passed from the environment. # It's a very convenient way for toggling developer builds. # # `flex` and `bison` are explicitly specified, # because it is highly unlikely ${LEX} and ${YACC} # will be able to parse your source code; # not to mention that they are simply # the same tools pretending to be POSIX. # Wherever no such concerns are present, we use the builtins. # Some people depend on this behaviour to get linting. # # We use $(or) to prevent anyone deleting their root # in case the definition of ${OBJECT.d} goes missing. # // autogen ?!