Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For C flags, only use CFLAGS environment variable #544

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,15 @@ It is possible to change the compiler optimization level, for the Pallene compil
Here are some examples:

```sh
# execute no optimization (Pallene and C compiler)
# disable Pallene optimization passes
pallenec test.pln -O0

# execute Pallene compiler optimizations and C compiler level 3 optimizations
pallenec test.pln -O3

# execute no optimizations for Pallene compiler but executes C compiler level 2 optimizations
env CFLAGS="-O2" pallenec test.pln -O0

# execute all default optimizations (same as -O2)
# disable C compiler optimization
export CFLAGS='-O0'
pallenec test.pln
```

**Note**: For the C compiler only, the setting set using `CFLAGS` overrides the setting set by flag `-O`.

For more compiler options, see `pallenec --help`
For more compiler options, see `./pallenec --help`

## Developing Pallene

Expand Down
6 changes: 3 additions & 3 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ echo "--- Test Suite ---"
# need to press Ctrl-C once and busted usually gets to exit gracefully.
FLAGS=(--verbose --no-keep-going)

# To speed things up, we tell the C compiler to skip optimizations.
# Don't worry, the continuous integration server still tests with optimizations.
export CFLAGS=-O0
# To speed things up, we tell the C compiler to skip optimizations. (It's OK, the CI still uses -O2)
# Also, add some compiler flags to verify standard compliance.
export CFLAGS='-O0 -std=c99 -Wall -Werror -Wundef -Wpedantic -Wno-unused'

if [ "$#" -eq 0 ]; then
if command -v parallel >/dev/null; then
Expand Down
17 changes: 5 additions & 12 deletions src/pallene/c_compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ local util = require "pallene.util"

local c_compiler = {}

local CC = "cc"
local CPPFLAGS = ""
local CFLAGS_BASE = "-std=c99 -g -fPIC"
local CFLAGS_WARN = "-Wall -Wundef -Wpedantic -Wno-unused"
local USER_CFlAGS = os.getenv("CFLAGS") or ""
local CC = os.getenv("CC") or "cc"
local CFLAGS = os.getenv("CFLAGS") or "-O2"

local function get_uname()
local ok, err, uname = util.outputs_of_execute("uname -s")
Expand All @@ -47,14 +44,10 @@ local function run_cc(args)
return true, {}
end

-- The third argument is the mod_name, which is not used by this
function c_compiler.compile_c_to_o(in_filename, out_filename, _, opt_level)
function c_compiler.compile_c_to_o(in_filename, out_filename)
return run_cc({
CPPFLAGS,
CFLAGS_BASE,
CFLAGS_WARN,
opt_level and "-O"..opt_level or "",
USER_CFlAGS,
"-fPIC",
CFLAGS,
"-x c",
"-o", util.shell_quote(out_filename),
"-c", util.shell_quote(in_filename),
Expand Down