diff --git a/Makefile b/Makefile index 1834058efca54..e53d146647c9d 100644 --- a/Makefile +++ b/Makefile @@ -267,7 +267,7 @@ ifeq ($(OS),WINNT) endif $(INSTALL_F) $(build_includedir)/uv* $(DESTDIR)$(includedir)/julia endif - $(INSTALL_F) src/julia.h src/options.h src/support/*.h $(DESTDIR)$(includedir)/julia + $(INSTALL_F) src/julia.h src/julia_version.h src/options.h src/support/*.h $(DESTDIR)$(includedir)/julia # Copy system image $(INSTALL_F) $(build_private_libdir)/sys.ji $(DESTDIR)$(private_libdir) $(INSTALL_M) $(build_private_libdir)/sys.$(SHLIB_EXT) $(DESTDIR)$(private_libdir) diff --git a/src/.gitignore b/src/.gitignore index b3ae41ba187c6..f681ce47fdd2c 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -17,3 +17,4 @@ /libjulia-release.a /libjulia-release.so /libjulia-release.dylib +/julia_version.h diff --git a/src/Makefile b/src/Makefile index 9afff8e593d78..58caeb708fd54 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,7 +12,7 @@ SRCS = \ jltypes gf ast builtins module codegen disasm debuginfo interpreter \ alloc dlload sys init task array dump toplevel jl_uv jlapi profile llvm-simdloop -HEADERS = julia.h julia_internal.h options.h $(wildcard support/*.h) $(LIBUV_INC)/uv.h +HEADERS = julia.h julia_internal.h julia_version.h options.h $(wildcard support/*.h) $(LIBUV_INC)/uv.h FLAGS = \ -D_GNU_SOURCE -Iflisp -Isupport \ @@ -87,6 +87,18 @@ $(BUILDDIR)/flisp/libflisp.a: flisp/*.h flisp/*.c $(BUILDDIR)/support/libsupport $(BUILDDIR)/flisp/libflisp-debug.a: flisp/*.h flisp/*.c $(BUILDDIR)/support/libsupport-debug.a $(MAKE) -C flisp debug BUILDDIR='$(abspath $(BUILDDIR)/flisp)' +julia_version.h: ../VERSION + @echo "// This is an autogenerated header file" > $@ + @echo "#ifndef JULIA_VERSION_H" >> $@ + @echo "#define JULIA_VERSION_H" >> $@ + @echo "#define JULIA_VERSION_STRING" \"$(JULIA_VERSION)\" >> $@ + @echo $(JULIA_VERSION) | awk 'BEGIN {FS="[.,-]"} \ + {print "#define JULIA_VERSION_MAJOR " $$1 "\n" \ + "#define JULIA_VERSION_MINOR " $$2 "\n" \ + "#define JULIA_VERSION_PATCH " $$3 ; \ + if (NF<4) print "#define JULIA_VERSION_IS_RELEASE 1" ; else print "#define JULIA_VERSION_IS_RELEASE 0"}' >> $@ + @echo "#endif" >> $@ + ifneq ($(USEMSVC), 1) CXXLD = $(CXX) -shared else @@ -121,6 +133,7 @@ clean: -rm -f $(build_shlibdir)/libjulia* -rm -f $(BUILDDIR)/julia_flisp.boot $(BUILDDIR)/julia_flisp.boot.inc -rm -f $(BUILDDIR)/*.dbg.obj $(BUILDDIR)/*.o *~ $(BUILDDIR)/*.$(SHLIB_EXT) $(BUILDDIR)/*.a *# + -rm -f $(BUILDDIR)/julia_version.h clean-flisp: -$(MAKE) -C flisp clean BUILDDIR='$(abspath $(BUILDDIR)/flisp)' diff --git a/src/jlapi.c b/src/jlapi.c index 006482e50d921..a93201c6586fc 100644 --- a/src/jlapi.c +++ b/src/jlapi.c @@ -259,6 +259,31 @@ DLLEXPORT jl_value_t *jl_get_image_file(void) return jl_cstr_to_string(jl_compileropts.image_file); } +DLLEXPORT const int jl_ver_major(void) +{ + return JULIA_VERSION_MAJOR; +} + +DLLEXPORT const int jl_ver_minor(void) +{ + return JULIA_VERSION_MINOR; +} + +DLLEXPORT const int jl_ver_patch(void) +{ + return JULIA_VERSION_PATCH; +} + +DLLEXPORT const int jl_ver_is_release(void) +{ + return JULIA_VERSION_IS_RELEASE; +} + +DLLEXPORT const char* jl_ver_string(void) +{ + return JULIA_VERSION_STRING; +} + #ifdef __cplusplus } #endif diff --git a/src/julia.h b/src/julia.h index 18e30aafe6d33..52f2f96f11abf 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1351,6 +1351,15 @@ extern DLLEXPORT jl_compileropts_t jl_compileropts; #define JL_COMPILEROPT_DUMPBITCODE_ON 1 #define JL_COMPILEROPT_DUMPBITCODE_OFF 2 +// Version information +#include "julia_version.h" + +DLLEXPORT extern const int jl_ver_major(void); +DLLEXPORT extern const int jl_ver_minor(void); +DLLEXPORT extern const int jl_ver_patch(void); +DLLEXPORT extern const int jl_ver_is_release(void); +DLLEXPORT extern const char* jl_ver_string(void); + #ifdef __cplusplus } #endif diff --git a/test/version.jl b/test/version.jl index 232ed232d412e..c1e9fb8650d06 100644 --- a/test/version.jl +++ b/test/version.jl @@ -133,3 +133,9 @@ for major=0:3, minor=0:3, patch=0:3 @test x < thismajor(x) ? nextmajor(x) == thismajor(x) : thismajor(x) < nextmajor(x) end end + +# julia_version.h version test + +@test VERSION.major == ccall(:jl_ver_major,Int,()) +@test VERSION.minor == ccall(:jl_ver_minor,Int,()) +@test VERSION.patch == ccall(:jl_ver_patch,Int,())