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

Respect CC/CXX/CFLAGS/CXXFLAGS/LDFLAGS. #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 17 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ V8_ARCH = x64
V8_MODE = release

WASM_FLAGS = -DDEBUG # -DDEBUG_LOG
C_FLAGS = ${WASM_FLAGS} -Wall -Werror -ggdb -O -fsanitize=address
CC_FLAGS = ${C_FLAGS}
LD_FLAGS = -fsanitize-memory-track-origins -fsanitize-memory-use-after-dtor
CFLAGS ?= ${WASM_FLAGS} -Wall -Werror -ggdb -O -fsanitize=address
CXXFLAGS ?= -std=c++11 ${CFLAGS}
LDFLAGS ?= -fsanitize-memory-track-origins -fsanitize-memory-use-after-dtor

C_COMP = clang
ifeq ($(origin CC),default)
CC = clang
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply CC ?= clang?

endif
ifeq ($(origin CXX),default)
CXX = clang++
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.
Of course, moving this here loses the ability to set both compilers with just one command line var.

endif

WASM_INTERPRETER = ../spec/interpreter/wasm # Adjust as needed.

Expand Down Expand Up @@ -60,16 +65,12 @@ V8_GN_ARGS = \
use_custom_libcxx_for_host=false

# Compiler config
ifeq (${C_COMP},clang)
CC_COMP = clang++
LD_GROUP_START =
LD_GROUP_END =
else ifeq (${C_COMP},gcc)
CC_COMP = g++
ifeq ($(firstword $(subst -, ,${CXX})),g++)
LD_GROUP_START = -Wl,--start-group
LD_GROUP_END = -Wl,--end-group
else
$(error C_COMP set to unknown compiler, must be clang or gcc)
LD_GROUP_START =
LD_GROUP_END =
endif


Expand Down Expand Up @@ -113,16 +114,16 @@ run-%-cc: ${EXAMPLE_OUT}/%-cc ${EXAMPLE_OUT}/%.wasm ${V8_BLOBS:%=${EXAMPLE_OUT}/
# Compiling C / C++ example
${EXAMPLE_OUT}/%-c.o: ${EXAMPLE_DIR}/%.c ${WASM_INCLUDE}/wasm.h
mkdir -p ${EXAMPLE_OUT}
${C_COMP} -c ${C_FLAGS} -I. -I${V8_INCLUDE} -I${WASM_INCLUDE} $< -o $@
${CC} -c ${CFLAGS} -I. -I${V8_INCLUDE} -I${WASM_INCLUDE} $< -o $@

${EXAMPLE_OUT}/%-cc.o: ${EXAMPLE_DIR}/%.cc ${WASM_INCLUDE}/wasm.hh
mkdir -p ${EXAMPLE_OUT}
${CC_COMP} -c -std=c++11 ${CC_FLAGS} -I. -I${V8_INCLUDE} -I${WASM_INCLUDE} $< -o $@
${CXX} -c ${CXXFLAGS} -I. -I${V8_INCLUDE} -I${WASM_INCLUDE} $< -o $@

# Linking C / C++ example
.PRECIOUS: ${EXAMPLES:%=${EXAMPLE_OUT}/%-c}
${EXAMPLE_OUT}/%-c: ${EXAMPLE_OUT}/%-c.o ${WASM_C_O}
${CC_COMP} ${C_FLAGS} ${LD_FLAGS} $< -o $@ \
${CXX} ${CXXFLAGS} ${LDFLAGS} $< -o $@ \
Copy link
Author

@PiotrSikora PiotrSikora May 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I changed CFLAGS to CXXFLAGS here, since CXX is used to link those targets, so it seemed more correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

${WASM_C_O} \
${LD_GROUP_START} \
${V8_LIBS:%=${V8_OUT}/obj/libv8_%.a} \
Expand All @@ -131,7 +132,7 @@ ${EXAMPLE_OUT}/%-c: ${EXAMPLE_OUT}/%-c.o ${WASM_C_O}

.PRECIOUS: ${EXAMPLES:%=${EXAMPLE_OUT}/%-cc}
${EXAMPLE_OUT}/%-cc: ${EXAMPLE_OUT}/%-cc.o ${WASM_CC_O}
${CC_COMP} ${CC_FLAGS} ${LD_FLAGS} $< -o $@ \
${CXX} ${CXXFLAGS} ${LDFLAGS} $< -o $@ \
${WASM_CC_O} \
${LD_GROUP_START} \
${V8_LIBS:%=${V8_OUT}/obj/libv8_%.a} \
Expand Down Expand Up @@ -169,7 +170,7 @@ wasm-cc: ${WASM_CC_LIBS:%=${WASM_OUT}/%.o}
# Compiling
${WASM_OUT}/%.o: ${WASM_SRC}/%.cc ${WASM_INCLUDE}/wasm.h ${WASM_INCLUDE}/wasm.hh
mkdir -p ${WASM_OUT}
${CC_COMP} -c -std=c++11 ${CC_FLAGS} -I. -I${V8_INCLUDE} -I${WASM_INCLUDE} -I${WASM_SRC} $< -o $@
${CXX} -c ${CXXFLAGS} -I. -I${V8_INCLUDE} -I${WASM_INCLUDE} -I${WASM_SRC} $< -o $@

# wasm-c.cc includes wasm-v8.cc, so set up a side dependency
${WASM_OUT}/wasm-c.o: ${WASM_SRC}/wasm-v8.cc
Expand Down