Skip to content

Commit f9c48fa

Browse files
author
newnix
committed
Include Build Files, Update Fallthrough Condition
* *.mk - Included configuration and build specification files * subnom.c - Added an if statement to catch when cmdbuf->command == 0 in runcmd() to ensure the default behaviour is looking up the provided term. This will need to be revisited and most likely addressed earlier in the call chain. * README.md - Updated with dependency information and initial installation instructions.
1 parent 98a2c8b commit f9c48fa

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,35 @@ Runtime Dependencies:
2222
* A POSIX-ish OS
2323
* A C99 compliant C library (optional)
2424
* The SQLite3 library (optional)
25+
26+
Note: These are optional runtime deps due to the possibility of static linking. In the default scenario,
27+
dynamic linking is used instead, and requires the libraries to be available at runtime to work properly.
2528

2629

30+
# Installation
31+
After cloning the repo, you can run `make help` to see the current build settings. The defaults should be fine for most
32+
installs, though the primary options can be set through `make config` which will open up your `$EDITOR` to view/edit
33+
`config.mk`.
34+
35+
These build flags should be appropriate for all UNIX-like systems aside from MacOS, in which case the "failsafe" settings should allow
36+
the build to complete without issue. Simply uncomment the line desired to use either GCC or Clang/LLVM to build `nombre(1)` and comment out
37+
the other two.
38+
39+
If you do not wish to have `nombre(1)` installed to `${HOME}/nombre/bin`, simply change the values of `PREFIX` and `DESTDIR` in `config.mk`
40+
to reflect the desired installation directory. Just take note of any necessary permissions if installing outside of your home directory.
41+
You will also need to ensure that whatever directory you install to is in your `PATH`, so in the default scenario, you'd want to run something
42+
like the following (assuming Bash is the interactive shell being used):
43+
44+
```
45+
export PATH="${PATH}:${HOME}/bin"
46+
printf "export %s=%s\n" "PATH" "${PATH}" >> ${HOME}/.bashrc
47+
```
48+
49+
There may be some non-portable flags in use which will hinder installation on other platforms, but I'm in the process of testing on
50+
Alpine Linux and Ubuntu to ensure that where possible, only portable interfaces/flags are used or are appropriately fenced off behind
51+
an `#ifdef`. Please let me know if any errors are encountered so they can be addressed as swiftly as possible. If it's a problem encountered
52+
when using the `nombre(1)` utility, please include the runtime traces from using the `-D` flag.
53+
2754
## Interface
2855
The `nombre(1)` interface is a semi-natural language command line primarily driven by the use of subcommands,
2956
which will then construct and run SQL queries to interface with the database on your behalf. This allows

clang-opts.mk

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Compilation and Linking settings when using Clang/LLVM
2+
CC = clang
3+
LD = lld
4+
5+
WRN = -Wextra -Wall -Weverything -Wdeprecated -pedantic -Werror -Wno-padded -Wno-cast-qual
6+
CFLAGS = ${WRN} -std=${STD} -Oz -fpic -fpie -pipe -fPIC -fPIE -fvectorize -fstack-protector \
7+
-fstrict-enums -fstrict-return -fstack-protector-strong -fmerge-all-constants -fstack-protector-all \
8+
-Qn -fstrict-aliasing -ffunction-sections -fdata-sections
9+
LDFLAGS = -z relro -z now -z combreloc #--icf=safe

config.mk

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Set up some variables for use in building nombre
2+
## Used as a means of working around Makefile limitations and portability concerns
3+
4+
## Uncomment to force a debug build
5+
#DBG = -g3 -NOMBRE_DEBUG
6+
7+
## Set the library and include paths
8+
INCS = -I/usr/include -I/usr/local/include
9+
LIBS = -L/usr/lib -L/usr/local/lib
10+
11+
## Library linkages
12+
LINKTO = -lc -lsqlite3 -lpthread
13+
14+
## Define where the binary will be installed
15+
## Default is ${HOME}/bin
16+
PREFIX = ${HOME}
17+
DESTDIR = /bin
18+
19+
## Comment out to not use Clang
20+
include clang-opts.mk
21+
22+
## Uncomment to use GCC
23+
#include gcc-opts.mk
24+
25+
## Uncomment for "failsafe" settings
26+
#include failsafe.mk

failsafe.mk

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Presumed safe compilation/linking settings
2+
CC = cc
3+
LD = ld
4+
CFLAGS = -std=${STD} -O2 -fpic -fpie
5+
LDFLAGS =

gcc-opts.mk

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Compiler and Linker settings for using GCC
2+
CC = gcc
3+
LD = ld
4+
5+
WRN = -pedantic -Wno-alignment -Werror -Wall
6+
CFLAGS = ${WRN} -std=${STD} -Os -fpic -fpie -pipe -fPIC -fPIE -fstack-protector-all -fstack-protector-strong \
7+
-fstrict-aliasing -ffunction-sections -fdata-sections
8+
LDFLAGS = -z combreloc -z now -z relro -fpie -fpic --icf=safe

subnom.c

+5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ runcmd(nomcmd * restrict cmdbuf, int genlen) {
172172

173173
if ((retc = sqlite3_prepare_v2(cmdbuf->dbcon, cmdbuf->gensql, genlen, &stmt, &sqltail)) != SQLITE_OK) {
174174
NOMERR("Error compiling SQL (%s)!\n", sqlite3_errstr(sqlite3_errcode(cmdbuf->dbcon)));
175+
} else {
176+
/* XXX: This should be handled elsewhere */
177+
if (cmdbuf->command == 0) {
178+
cmdbuf->command = lookup;
179+
}
175180
}
176181
/*
177182
* Determine how to best proceed with processing the statement based on

0 commit comments

Comments
 (0)