-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix embedding example, continued #21299
Changes from all commits
653fb16
aaec5e2
25fd57e
5d7c4c2
8dd3123
0c123c1
1f05ba9
87601aa
b4d01d9
c0d01c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ function libDir() | |
end | ||
end | ||
|
||
private_libDir() = joinpath(JULIA_HOME, Base.PRIVATE_LIBDIR) | ||
|
||
function includeDir() | ||
joinpath(match(r"(.*)(bin)",JULIA_HOME).captures[1],"include","julia") | ||
end | ||
|
@@ -49,7 +51,13 @@ function initDir() | |
end | ||
|
||
function ldflags() | ||
replace("""-L$(libDir())""","\\","\\\\") | ||
fl = replace("""-L$(libDir())""","\\","\\\\") | ||
if is_windows() | ||
fl = fl * " -Wl,--stack,8388608" | ||
elseif is_linux() | ||
fl = fl * " -Wl,--export-dynamic" | ||
end | ||
return fl | ||
end | ||
|
||
function ldlibs() | ||
|
@@ -59,7 +67,7 @@ function ldlibs() | |
"julia" | ||
end | ||
if is_unix() | ||
return replace("""-Wl,-rpath,$(libDir()) -l$libname""","\\","\\\\") | ||
return replace("""-Wl,-rpath,$(libDir()) -Wl,-rpath,$(private_libDir()) -l$libname""","\\","\\\\") | ||
else | ||
return "-l$libname -lopenlibm" | ||
end | ||
|
@@ -70,9 +78,9 @@ function cflags() | |
arg2 = replace(includeDir(),"\\","\\\\") | ||
threading_def = threadingOn() ? "-DJULIA_ENABLE_THREADING=1 " : "" | ||
if is_unix() | ||
return """$(threading_def)-fPIC -DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2""" | ||
return """-std=gnu99 $(threading_def)-fPIC -DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2""" | ||
else | ||
return """$(threading_def)-DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2""" | ||
return """-std=gnu99 $(threading_def)-DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into why we can't use |
||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,25 @@ | ||
JULIAHOME := $(abspath ..) | ||
SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
BUILDDIR := . | ||
JULIAHOME := $(abspath $(SRCDIR)/..) | ||
include $(JULIAHOME)/Make.inc | ||
|
||
FLAGS = -Wall -Wno-strict-aliasing -fno-omit-frame-pointer \ | ||
-I$(JULIAHOME)/src -I$(JULIAHOME)/src/support -I$(build_includedir) $(CFLAGS) | ||
outdir := $(libexecdir) | ||
|
||
DEBUGFLAGS += $(FLAGS) | ||
SHIPFLAGS += $(FLAGS) | ||
JLDFLAGS += $(LDFLAGS) $(NO_WHOLE_ARCHIVE) $(call exec,$(LLVM_CONFIG) --ldflags) $(OSLIBS) $(RPATH) | ||
embedding_binary := $(abspath $(outdir)/embedding$(JULIA_LIBSUFFIX)$(EXE)) | ||
|
||
ifeq ($(USE_SYSTEM_LIBM),0) | ||
ifneq ($(UNTRUSTED_SYSTEM_LIBM),0) | ||
JLDFLAGS += $(WHOLE_ARCHIVE) $(build_libdir)/libopenlibm.a $(NO_WHOLE_ARCHIVE) | ||
endif | ||
endif | ||
release: embedding | ||
debug: embedding-debug | ||
|
||
embedding-release: embedding | ||
embedding: $(embedding_binary) | ||
embedding-debug: $(embedding_binary) | ||
|
||
release debug: | ||
$(MAKE) embedding-$@ | ||
$(embedding_binary): $(wildcard embedding/*) | ||
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/examples/embedding $(JULIA_BUILD_MODE) \ | ||
JULIA="$(bindir)/julia$(JULIA_LIBSUFFIX)$(EXE)" BIN="$(outdir)" \ | ||
SPAWN="$(spawn)" CC="$(CC)" | ||
|
||
%.o: %.c | ||
@$(call PRINT_CC, $(CC) $(CPPFLAGS) $(CFLAGS) $(SHIPFLAGS) -c $< -o $@) | ||
%.do: %.c | ||
@$(call PRINT_CC, $(CC) $(CPPFLAGS) $(CFLAGS) $(DEBUGFLAGS) -c $< -o $@) | ||
clean: | ||
-rm -f $(embedding_binary) $(embedding_binary)-debug | ||
|
||
embedding: $(build_bindir)/embedding$(EXE) | ||
embedding-debug: $(build_bindir)/embedding-debug$(EXE) | ||
|
||
$(build_bindir)/embedding$(EXE): embedding.o | ||
@$(call PRINT_LINK, $(CXX) $(LINK_FLAGS) $(SHIPFLAGS) $^ -o $@ -L$(build_private_libdir) -L$(build_shlibdir) -ljulia $(JLDFLAGS)) | ||
$(build_bindir)/embedding-debug$(EXE): embedding.do | ||
@$(call PRINT_LINK, $(CXX) $(LINK_FLAGS) $(DEBUGFLAGS) $^ -o $@ -L$(build_private_libdir) -L$(build_shlibdir) -ljulia-debug $(JLDFLAGS)) | ||
|
||
|
||
clean: | $(CLEAN_TARGETS) | ||
rm -f *.o *.do | ||
rm -f $(build_bindir)/embedding-debug $(build_bindir)/embedding | ||
|
||
.PHONY: clean release debug | ||
.PHONY: all embedding clean | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This Makefile template requires the following variables to be set | ||
# in the environment or on the command-line: | ||
# JULIA: path to julia[.exe] executable | ||
# BIN: binary build directory | ||
|
||
ifndef JULIA | ||
$(error "Please pass JULIA=[path of target julia binary], or set as environment variable!") | ||
endif | ||
ifndef BIN | ||
$(error "Please pass BIN=[path of build directory], or set as environment variable!") | ||
endif | ||
|
||
#============================================================================= | ||
# this source directory where embedding.c is located | ||
SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
|
||
# get the executable suffix, if any | ||
EXE := $(suffix $(abspath $(JULIA))) | ||
|
||
# get compiler and linker flags. (see: `contrib/julia-config.jl`) | ||
CFLAGS += -lm $(shell $(SPAWN) $(JULIA) -e \ | ||
'include(joinpath(JULIA_HOME,Base.DATAROOTDIR,"julia","julia-config.jl"))' \ | ||
-- --cflags --ldflags --ldlibs) | ||
|
||
DEBUGFLAGS += -g | ||
|
||
#============================================================================= | ||
|
||
release: $(BIN)/embedding$(EXE) | ||
debug: $(BIN)/embedding-debug$(EXE) | ||
|
||
$(BIN)/embedding$(EXE): $(SRCDIR)/embedding.c | ||
$(CC) $^ -o $@ $(CFLAGS) | ||
|
||
$(BIN)/embedding-debug$(EXE): $(SRCDIR)/embedding.c | ||
$(CC) $^ -o $@ $(CFLAGS) $(DEBUGFLAGS) | ||
|
||
clean: | ||
@rm -f $(BIN)/embedding-debug$(EXE) $(BIN)/embedding$(EXE) | ||
|
||
.PHONY: release debug clean | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vtjnash can you think of any reason not to make this change? Part of the problem here was when
examples/Makefile
includedMake.inc
, theprefix
was getting set toexamples/julia-$(JULIA_COMMIT)
which of course nothing else built into