Move $(LIBS) to end of compile command
Without this change, when I run `make` it fails with this error (edited
ld: frontend/readline.o: in function `sigint_handler':
mrsh/frontend/readline.c:33: undefined reference to `rl_on_new_line'
ld: mrsh/frontend/readline.c:34: undefined reference to `rl_replace_line'
ld: mrsh/frontend/readline.c:35: undefined reference to `rl_redisplay'
ld: frontend/readline.o: in function `interactive_init':
ld: mrsh/frontend/readline.c:53: undefined reference to `read_history'
ld: frontend/readline.o: in function `interactive_next':
ld: mrsh/frontend/readline.c:74: undefined reference to `add_history'
ld: mrsh/frontend/readline.c:76: undefined reference to `write_history'
collect2: error: ld returned 1 exit status
make: *** [Makefile:61: mrsh] Error 1
It turns out that the placement of `-l` in the command is significant
; it should come after the object files that depend on the library.
> It makes a difference where in the command you write this option; the
> linker searches and processes libraries and object files in the order
> they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after
> file foo.o but before bar.o. If bar.o refers to functions in ‘z’,
> those functions may not be loaded.
Moving $(LIBS) to the end of the command (right next to -lmrsh) fixes
Tested using gcc 12.2.0 and clang 15.0.0
readme: drop link to website
readme: update CI badge to use master branch
Add support for building static executables
This fixes the following issues:
* linked objects do not use LDFLAGS
* pkg-config is not queried appropriately depending on the desired linkage
* there's no way to configure/deconfigure static linking
(except by setting LDFLAGS, which won't work due to the prior two)
There are many ways of fixing these, but I went for the minimally intrusive approach:
* any linked objects have `$(LDFLAGS)` in front of `$(LIBS)`
* configure has a --static and --dynamic flag
* --static is added to ldflags only if selected
Makefile: Add uninstall rule
Extra checks to ensure we don't clobber std fds
Handle weird OUTDIR values in ./configure
Fix segfault when calling `mrsh -o`
* at main.c we call mrsh_process_args from builtins/set.c
* that function calls set function impl. in the same file.
* set function returns early in its switch block commandline arg `-o`
when called without a long option.
* this might be the desired behaviour, but it skips populating
* the code responsible for that is after the switch statement
* add a jump to handle this case
Initialise arith_nested_parens every word list.
Fix closing of arithmetic double parentheses.
The initial check for "))" does not account for that we might be
still parsing closing parentheses.
Fix arithmetic parsing with parentheses + spaces.
Every time arithmetic_word is called, nested_parens is reset.
Spaces (isblank) causes arithmetic_word to return, so nested_parens
is set to 0 again after every space.
Make expand_path return allocated memory
Gets rid of one PATH_MAX use.
Replace assert(0) with abort()
This ensures functions reaching the asserts won't return, and avoids
issues with NDEBUG.