Skip to content

Commit

Permalink
Fix embedding example and simplify Makefile
Browse files Browse the repository at this point in the history
- get rid of makefile cruft
- use julia-config for flags, as documented in manual
- build into `libexec`

also move to subdir for clarity.
  • Loading branch information
ihnorton authored and JeffBezanson committed Apr 13, 2017
1 parent 5d7c4c2 commit 8dd3123
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 40 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ $(BUILDROOT)/doc/_build/html/en/index.html: $(shell find $(BUILDROOT)/base $(BUI
CLEAN_TARGETS += clean-docdir
clean-docdir:
@-rm -fr $(abspath $(build_docdir))
$(build_prefix)/.examples: $(wildcard $(JULIAHOME)/examples/*.jl) $(shell find $(JULIAHOME)/examples/clustermanager)

$(build_prefix)/.examples: $(wildcard $(JULIAHOME)/examples/*.jl) \
$(shell find $(JULIAHOME)/examples/clustermanager)
@echo Copying in usr/share/doc/julia/examples
@-rm -fr $(build_docdir)/examples
@mkdir -p $(build_docdir)/examples
@mkdir -p $(build_docdir)/examples/embedding
@cp -R $(JULIAHOME)/examples/*.jl $(build_docdir)/examples/
@cp -R $(JULIAHOME)/examples/clustermanager $(build_docdir)/examples/
@cp -R $(JULIAHOME)/examples/embedding $(build_docdir)/examples/embedding
@echo 1 > $@

examples: julia-sysimg-$(JULIA_BUILD_MODE)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/examples $(JULIA_BUILD_MODE)

julia-symlink: julia-ui-$(JULIA_BUILD_MODE)
ifneq ($(OS),WINNT)
ifndef JULIA_VAGRANT_BUILD
Expand Down Expand Up @@ -107,7 +114,7 @@ julia-sysimg-release : julia-inference julia-ui-release
julia-sysimg-debug : julia-inference julia-ui-debug
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) $(build_private_libdir)/sys-debug$(CPUID_TAG).$(SHLIB_EXT) JULIA_BUILD_MODE=debug

julia-debug julia-release : julia-% : julia-ui-% julia-sysimg-% julia-symlink julia-libccalltest
julia-debug julia-release : julia-% : julia-ui-% julia-sysimg-% julia-symlink julia-libccalltest examples

debug release : % : julia-%

Expand Down Expand Up @@ -522,6 +529,7 @@ clean: | $(CLEAN_TARGETS)
@-$(MAKE) -C $(BUILDROOT)/src clean
@-$(MAKE) -C $(BUILDROOT)/ui clean
@-$(MAKE) -C $(BUILDROOT)/test clean
@-$(MAKE) -C $(BUILDROOT)/examples clean
-rm -f $(BUILDROOT)/julia
-rm -f $(BUILDROOT)/*.tar.gz
-rm -f $(build_depsbindir)/stringreplace \
Expand All @@ -548,7 +556,7 @@ distcleanall: cleanall
test testall testall1 test clean distcleanall cleanall clean-* \
run-julia run-julia-debug run-julia-release run \
install binary-dist light-source-dist.tmp light-source-dist \
dist full-source-dist source-dist
dist full-source-dist source-dist examples

test: check-whitespace $(JULIA_BUILD_MODE)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/test default JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)
Expand Down
48 changes: 15 additions & 33 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
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)
embedding_binary := $(abspath $(build_libexecdir)/embedding$(JULIA_LIBSUFFIX)$(EXE))

DEBUGFLAGS += $(FLAGS)
SHIPFLAGS += $(FLAGS)
JLDFLAGS += $(LDFLAGS) $(NO_WHOLE_ARCHIVE) $(call exec,$(LLVM_CONFIG) --ldflags) $(OSLIBS) $(RPATH)
release: embedding
debug: embedding-debug

ifeq ($(USE_SYSTEM_LIBM),0)
ifneq ($(UNTRUSTED_SYSTEM_LIBM),0)
JLDFLAGS += $(WHOLE_ARCHIVE) $(build_libdir)/libopenlibm.a $(NO_WHOLE_ARCHIVE)
endif
endif
embedding: $(embedding_binary)
embedding-debug: $(embedding_binary)

embedding-release: embedding
$(embedding_binary): $(wildcard embedding/*)
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/examples/embedding $(JULIA_BUILD_MODE) \
JULIA="$(JULIA_EXECUTABLE)" BIN="$(build_libexecdir)" \
SPAWN="$(spawn)" CC="$(CC)"

release debug:
$(MAKE) embedding-$@
clean:
-rm -f $(embedding_binary) $(embedding_binary)-debug

%.o: %.c
@$(call PRINT_CC, $(CC) $(CPPFLAGS) $(CFLAGS) $(SHIPFLAGS) -c $< -o $@)
%.do: %.c
@$(call PRINT_CC, $(CC) $(CPPFLAGS) $(CFLAGS) $(DEBUGFLAGS) -c $< -o $@)

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

39 changes: 39 additions & 0 deletions examples/embedding/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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

#=============================================================================
# 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): embedding.c
$(CC) $^ -o $@ $(CFLAGS)

$(BIN)/embedding-debug$(EXE): embedding.c
$(CC) $^ -o $@ $(CFLAGS) $(DEBUGFLAGS)

clean:
@rm -f $(BIN)/embedding-debug$(EXE) $(BIN)/embedding$(EXE)

.PHONY: release debug clean

5 changes: 3 additions & 2 deletions examples/embedding.c → examples/embedding/embedding.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ double my_c_sqrt(double x)

int main()
{
jl_init(NULL);
jl_init();

{
// Simple running Julia code
Expand Down Expand Up @@ -49,7 +49,7 @@ int main()
{
// 1D arrays

jl_value_t* array_type = jl_apply_array_type( jl_float64_type, 1 );
jl_value_t* array_type = jl_apply_array_type( (jl_value_t*)jl_float64_type, 1 );
jl_array_t* x = jl_alloc_array_1d(array_type , 10);
JL_GC_PUSH1(&x);

Expand Down Expand Up @@ -97,6 +97,7 @@ int main()
jl_show(jl_stderr_obj(), jl_exception_occurred());
jl_printf(jl_stderr_stream(), "\n");
}

}

int ret = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/jlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ JL_DLLEXPORT void jl_init_with_image(const char *julia_home_dir,
jl_options.julia_home = julia_home_dir;
if (image_relative_path != NULL)
jl_options.image_file = image_relative_path;
else
jl_options.image_file = jl_get_default_sysimg_path();
julia_init(JL_IMAGE_JULIA_HOME);
jl_exception_clear();
}
Expand Down
4 changes: 2 additions & 2 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ char *shlib_ext = ".so";
#endif

static char system_image_path[256] = "\0" JL_SYSTEM_IMAGE_PATH;
static const char *get_default_sysimg_path(void)
JL_DLLEXPORT const char *jl_get_default_sysimg_path(void)
{
#ifdef CPUID_SPECIFIC_BINARIES
char *path = &system_image_path[1];
Expand Down Expand Up @@ -203,7 +203,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)

// If CPUID specific binaries are enabled, this varies between runs, so initialize
// it here, rather than as part of the static initialization above.
jl_options.image_file = get_default_sysimg_path();
jl_options.image_file = jl_get_default_sysimg_path();

int codecov = JL_LOG_NONE;
int malloclog= JL_LOG_NONE;
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel);
JL_DLLEXPORT void jl_init(const char *julia_home_dir);
JL_DLLEXPORT void jl_init_with_image(const char *julia_home_dir,
const char *image_relative_path);
JL_DLLEXPORT const char* jl_get_default_sysimg_path();
JL_DLLEXPORT int jl_is_initialized(void);
JL_DLLEXPORT void jl_atexit_hook(int status);
JL_DLLEXPORT void JL_NORETURN jl_exit(int status);
Expand Down

0 comments on commit 8dd3123

Please sign in to comment.