Skip to content
Open
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
24 changes: 14 additions & 10 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,28 @@ DIRS = $(build_bindir) $(build_libdir)
$(foreach dir,$(DIRS),$(eval $(call dir_target,$(dir))))

ifeq ($(OS),WINNT)
$(BUILDDIR)/julia_res.o: $(JULIAHOME)/contrib/windows/julia.rc $(JULIAHOME)/VERSION
$(BUILDDIR)/julia_res.o $(BUILDDIR)/julia_res_debug.o: $(JULIAHOME)/contrib/windows/julia.rc $(JULIAHOME)/VERSION
JLVER=`cat $(JULIAHOME)/VERSION` && \
JLVERi=`echo $$JLVER | perl -nle \
'/^(\d+)\.?(\d*)\.?(\d*)/ && \
print int $$1,",",int $$2,",",int $$3,",0"'` && \
$(CROSS_COMPILE)windres $< -O coff -o $@ -DJLVER=$$JLVERi -DJLVER_STR=\\\"$$JLVER\\\"
EXE_OBJS += $(BUILDDIR)/julia_res.o
EXE_DOBJS += $(BUILDDIR)/julia_res.o
EXE_DOBJS += $(BUILDDIR)/julia_res_debug.o
endif

# Embed an Info.plist in the julia executable
# Create an intermediate target Info.plist for Darwin code signing.
ifeq ($(DARWIN_FRAMEWORK),1)
$(BUILDDIR)/Info.plist: $(JULIAHOME)/VERSION
/usr/libexec/PlistBuddy -x -c "Clear dict" $@
/usr/libexec/PlistBuddy -x -c "Add :CFBundleName string julia" $@
/usr/libexec/PlistBuddy -x -c "Add :CFBundleIdentifier string $(darwin_codesign_id_julia_ui)" $@
/usr/libexec/PlistBuddy -x -c "Add :CFBundleInfoDictionaryVersion string 6.0" $@
/usr/libexec/PlistBuddy -x -c "Add :CFBundleVersion string $(JULIA_COMMIT)" $@
/usr/libexec/PlistBuddy -x -c "Add :CFBundleShortVersionString string $(JULIA_MAJOR_VERSION).$(JULIA_MINOR_VERSION).$(JULIA_PATCH_VERSION)" $@
@TMPFILE=$$(mktemp $(abspath [email protected])); \
/usr/libexec/PlistBuddy -x -c "Clear dict" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleName string julia" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleIdentifier string $(darwin_codesign_id_julia_ui)" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleInfoDictionaryVersion string 6.0" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleVersion string $(JULIA_COMMIT)" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleShortVersionString string $(JULIA_MAJOR_VERSION).$(JULIA_MINOR_VERSION).$(JULIA_PATCH_VERSION)" $$TMPFILE; \
mv $$TMPFILE $@
Comment on lines +92 to +99
Copy link
Member

Choose a reason for hiding this comment

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

Instead we could also just do a single PlistBuddy invocation

Suggested change
@TMPFILE=$$(mktemp $(abspath [email protected])); \
/usr/libexec/PlistBuddy -x -c "Clear dict" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleName string julia" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleIdentifier string $(darwin_codesign_id_julia_ui)" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleInfoDictionaryVersion string 6.0" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleVersion string $(JULIA_COMMIT)" $$TMPFILE; \
/usr/libexec/PlistBuddy -x -c "Add :CFBundleShortVersionString string $(JULIA_MAJOR_VERSION).$(JULIA_MINOR_VERSION).$(JULIA_PATCH_VERSION)" $$TMPFILE; \
mv $$TMPFILE $@
/usr/libexec/PlistBuddy -x \
-c "Clear dict" \
-c "Add :CFBundleName string julia" \
-c "Add :CFBundleIdentifier string $(darwin_codesign_id_julia_ui)" \
-c "Add :CFBundleInfoDictionaryVersion string 6.0" \
-c "Add :CFBundleVersion string $(JULIA_COMMIT)" \
-c "Add :CFBundleShortVersionString string $(JULIA_MAJOR_VERSION).$(JULIA_MINOR_VERSION).$(JULIA_PATCH_VERSION)" \
$@

.INTERMEDIATE: $(BUILDDIR)/Info.plist # cleanup this file after we are done using it
JLDFLAGS += -Wl,-sectcreate,__TEXT,__info_plist,Info.plist
$(build_bindir)/julia$(EXE): $(BUILDDIR)/Info.plist
Expand Down Expand Up @@ -151,11 +153,13 @@ $(build_bindir)/julia-debug$(EXE): $(EXE_DOBJS) $(build_shlibdir)/libjulia-debug
@$(call PRINT_LINK, $(CC) $(LOADER_CFLAGS) $(DEBUGFLAGS) $(EXE_DOBJS) -o $@ $(LOADER_LDFLAGS) $(RPATH) -ljulia-debug)

$(BUILDDIR)/julia.expmap: $(SRCDIR)/julia.expmap.in $(JULIAHOME)/VERSION
sed <'$<' >'$@' -e 's/@JULIA_SHLIB_SYMBOL_VERSION@/JL_LIBJULIA_$(SOMAJOR)/'
@TMPFILE=$$(mktemp $(abspath [email protected])); \
sed <'$<' >$$TMPFILE -e 's/@JULIA_SHLIB_SYMBOL_VERSION@/JL_LIBJULIA_$(SOMAJOR)/'; \
mv $$TMPFILE $@
Comment on lines +156 to +158
Copy link
Member

Choose a reason for hiding this comment

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

How about we add a new helper script like this (created via ChatGPT, just to keep it interesting ;-)), stored as, say, atomic_write_if_different.sh somewhere we can easily reach it:

#!/bin/sh
# Atomic write-if-different helper
# Usage: atomic_write_if_different.sh TARGET

set -eu

target=$1
tmp=$(mktemp "${target}.XXXXXX") || exit 1

# Ensure temporary file gets cleaned up on exit or interrupt
cleanup() {
    rm -f "$tmp"
}
trap cleanup EXIT INT TERM HUP

# Read stdin to the temporary file
cat > "$tmp"

# If target does not exist, move new file into place
if [ ! -f "$target" ]; then
    mv "$tmp" "$target"
    trap - EXIT
    exit 0
fi

# Compare old and new; only replace if different
if cmp -s "$tmp" "$target"; then
    # identical
    rm -f "$tmp"
else
    mv "$tmp" "$target"
fi

trap - EXIT
exit 0

Then here we can write

Suggested change
@TMPFILE=$$(mktemp $(abspath [email protected])); \
sed <'$<' >$$TMPFILE -e 's/@JULIA_SHLIB_SYMBOL_VERSION@/JL_LIBJULIA_$(SOMAJOR)/'; \
mv $$TMPFILE $@
sed <'$<' -e 's/@JULIA_SHLIB_SYMBOL_VERSION@/JL_LIBJULIA_$(SOMAJOR)/' \
| PATH/TO/atomic_write_if_different.sh $@

The result has more comprehensive functionality and is arguably easier to read and maintain -- I think this is more visible in some of the other places.

Copy link
Member Author

Choose a reason for hiding this comment

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

I do like that. We need to be careful though, since half of the places we use this, the "if different" policy should not be applied, while the other half it should be (and a few don't care)


clean: | $(CLEAN_TARGETS)
rm -f $(BUILDDIR)/*.o $(BUILDDIR)/*.dbg.obj
rm -f $(build_bindir)/julia*
rm -f $(BUILDDIR)/julia.expmap
rm -f $(BUILDDIR)/julia.expmap*

.PHONY: clean release debug julia-release julia-debug
67 changes: 40 additions & 27 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,23 @@ $(BUILDDIR)/%.h.gen : $(SRCDIR)/%.d
sed 's/JULIA_/JL_PROBE_/' $@ > [email protected]
mv [email protected] $@

# Generate `.inc` file that contains a list of `#define` macros to rename functions defined in `libjulia-internal`
# to have a `ijl_` prefix instead of `jl_`, to denote that they are coming from `libjulia-internal`. This avoids
# potential confusion with debugging tools, when inspecting a process that has both `libjulia` and `libjulia-internal`
# loaded at the same time.
$(BUILDDIR)/jl_internal_funcs.inc: $(SRCDIR)/jl_exported_funcs.inc
# Generate `.inc` file that contains a list of `#define` macros to rename functions defined in `libjulia-internal`
# to have a `ijl_` prefix instead of `jl_`, to denote that they are coming from `libjulia-internal`. This avoids
# potential confusion with debugging tools, when inspecting a process that has both `libjulia` and `libjulia-internal`
# loaded at the same time.
grep 'XX(..*)' $< | sed -E 's/.*XX\((.+)\).*/#define \1 i\1/g' >$@
@TMPFILE=$$(mktemp $(abspath [email protected])); \
grep 'XX(..*)' $< | sed -E 's/.*XX\((.+)\).*/#define \1 i\1/g' > $$TMPFILE; \
mv $$TMPFILE $@

# Generate `.inc` file that contains a list of `#define` macros to access global data through struct instances
$(BUILDDIR)/jl_data_globals_defs.inc: $(SRCDIR)/jl_exported_data.inc
# Generate `.inc` file that contains a list of `#define` macros to access global data through struct instances
@TMPFILE=$$(mktemp $(abspath [email protected])); \
{ \
grep 'XX(.*)' $< | sed -E 's/.*XX\(([^,]+), .*\).*/#define jl_\1 (sysimg_global.\1)/g'; \
grep 'YY(.*)' $< | sed -E 's/.*YY\(([^,]+), .*\).*/#define jl_\1 (const_globals.jl\1)/g'; \
} >$@
} > $$TMPFILE; \
mv $$TMPFILE $@

# source file rules
$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) | $(BUILDDIR)
Expand Down Expand Up @@ -352,13 +356,17 @@ $(build_shlibdir)/libllvmcalltest.$(SHLIB_EXT): $(SRCDIR)/llvmcalltest.cpp $(LLV
julia_flisp.boot.inc.phony: $(BUILDDIR)/julia_flisp.boot.inc

$(BUILDDIR)/julia_flisp.boot.inc: $(BUILDDIR)/julia_flisp.boot $(FLISP_EXECUTABLE_release)
@$(call PRINT_FLISP, $(call spawn,$(FLISP_EXECUTABLE_release)) $(call cygpath_w,$(SRCDIR)/bin2hex.scm) < $< > $@)
@$(call PRINT_FLISP, TMPFILE=$$(mktemp $(abspath [email protected])); \
$(call spawn,$(FLISP_EXECUTABLE_release)) $(call cygpath_w,$(SRCDIR)/bin2hex.scm) < $< > $$TMPFILE; \
mv $$TMPFILE $@)

$(BUILDDIR)/julia_flisp.boot: $(addprefix $(SRCDIR)/,jlfrontend.scm flisp/aliases.scm flisp/profile.scm \
julia-parser.scm julia-syntax.scm match.scm utils.scm ast.scm macroexpand.scm mk_julia_flisp_boot.scm) \
$(FLISP_EXECUTABLE_release)
@$(call PRINT_FLISP, $(call spawn,$(FLISP_EXECUTABLE_release)) \
$(call cygpath_w,$(SRCDIR)/mk_julia_flisp_boot.scm) $(call cygpath_w,$(dir $<)) $(notdir $<) $(call cygpath_w,$@))
@$(call PRINT_FLISP, TMPFILE=$$(mktemp $(abspath [email protected])); \
$(call spawn,$(FLISP_EXECUTABLE_release)) \
$(call cygpath_w,$(SRCDIR)/mk_julia_flisp_boot.scm) $(call cygpath_w,$(dir $<)) $(notdir $<) $(call cygpath_w,$$TMPFILE); \
mv $$TMPFILE $@)

# additional dependency links
$(BUILDDIR)/codegen-stubs.o $(BUILDDIR)/codegen-stubs.dbg.obj: $(addprefix $(SRCDIR)/,intrinsics.h llvm-julia-passes.inc)
Expand Down Expand Up @@ -427,23 +435,28 @@ $(BUILDDIR)/flisp/libflisp-debug.a: $(addprefix $(SRCDIR)/,flisp/*.h flisp/*.c)
$(MAKE) -C $(SRCDIR)/flisp debug BUILDDIR='$(abspath $(BUILDDIR)/flisp)'

$(BUILDDIR)/julia_version.h: $(JULIAHOME)/VERSION
@echo "// This is an autogenerated header file" > $@.$(JULIA_BUILD_MODE).tmp
@echo "#ifndef JL_VERSION_H" >> $@.$(JULIA_BUILD_MODE).tmp
@echo "#define JL_VERSION_H" >> $@.$(JULIA_BUILD_MODE).tmp
@echo "#define JULIA_VERSION_STRING" \"$(JULIA_VERSION)\" >> $@.$(JULIA_BUILD_MODE).tmp
@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"}' >> $@.$(JULIA_BUILD_MODE).tmp
@echo "#endif" >> $@.$(JULIA_BUILD_MODE).tmp
mv $@.$(JULIA_BUILD_MODE).tmp $@
@TMPFILE=$$(mktemp $(abspath [email protected])); \
{ \
echo "// This is an autogenerated header file"; \
echo "#ifndef JL_VERSION_H"; \
echo "#define JL_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"; \
} > $$TMPFILE; \
mv $$TMPFILE $@

CXXLD = $(CXX) -shared

$(BUILDDIR)/julia.expmap: $(SRCDIR)/julia.expmap.in $(JULIAHOME)/VERSION $(LLVM_CONFIG_ABSOLUTE)
sed <'$<' >'$@' -e "s/@JULIA_SHLIB_SYMBOL_VERSION@/JL_LIBJULIA_$(SOMAJOR)/" \
-e "s/@LLVM_SHLIB_SYMBOL_VERSION@/$(LLVM_SHLIB_SYMBOL_VERSION)/"
@TMPFILE=$$(mktemp $(abspath [email protected])); \
sed <'$<' >$$TMPFILE -e "s/@JULIA_SHLIB_SYMBOL_VERSION@/JL_LIBJULIA_$(SOMAJOR)/" \
-e "s/@LLVM_SHLIB_SYMBOL_VERSION@/$(LLVM_SHLIB_SYMBOL_VERSION)/"; \
mv $$TMPFILE $@

$(build_shlibdir)/libjulia-internal.$(JL_MAJOR_MINOR_SHLIB_EXT): $(BUILDDIR)/julia.expmap $(OBJS) $(BUILDDIR)/flisp/libflisp.a $(BUILDDIR)/support/libsupport.a $(LIBUV)
@$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(SHIPFLAGS) $(JCXXFLAGS) $(CXXLDFLAGS) $(OBJS) $(RPATH_LIB) -o $@ \
Expand Down Expand Up @@ -554,11 +567,11 @@ INCLUDED_CXX_FILES := \
clean:
-rm -fr $(build_shlibdir)/libjulia-internal* $(build_shlibdir)/libjulia-codegen*
-rm -rf $(build_shlibdir)/libccalltest* $(build_shlibdir)/libllvmcalltest* $(build_shlibdir)/libccalllazyfoo* $(build_shlibdir)/libccalllazybar*
-rm -f $(BUILDDIR)/julia_flisp.boot $(BUILDDIR)/julia_flisp.boot.inc $(BUILDDIR)/jl_internal_funcs.inc $(BUILDDIR)/jl_data_globals_defs.inc
-rm -f $(BUILDDIR)/julia_flisp.boot* $(BUILDDIR)/julia_flisp.boot.inc* $(BUILDDIR)/jl_internal_funcs.inc* $(BUILDDIR)/jl_data_globals_defs.inc*
-rm -f $(BUILDDIR)/*.dbg.obj $(BUILDDIR)/*.o $(BUILDDIR)/*.dwo $(BUILDDIR)/*.$(SHLIB_EXT) $(BUILDDIR)/*.a $(BUILDDIR)/*.h.gen
-rm -f $(BUILDDIR)/julia.expmap
-rm -f $(BUILDDIR)/julia.expmap*
-rm -f $(BUILDDIR)/julia_version.h
-rm -f $(BUILDDIR)/compile_commands.json
-rm -f $(BUILDDIR)/compile_commands.json*

clean-flisp:
-$(MAKE) -C $(SRCDIR)/flisp clean BUILDDIR='$(abspath $(BUILDDIR)/flisp)'
Expand Down Expand Up @@ -657,7 +670,7 @@ clean-analyzegc:
# Compilation database generation using existing clang infrastructure
.PHONY: regenerate-compile_commands
regenerate-compile_commands:
TMPFILE=$$(mktemp -p $(BUILDDIR) compile_commands.json.XXXXXX); \
@TMPFILE=$$(mktemp $(abspath $(BUILDDIR)/compile_commands.json.XXXXXX)); \
{ \
CLANG_TOOLING_C_FLAGS="$$($(JULIAHOME)/contrib/escape_json.sh clang $(CLANG_TOOLING_C_FLAGS))"; \
CLANG_TOOLING_CXX_FLAGS="$$($(JULIAHOME)/contrib/escape_json.sh clang $(CLANG_TOOLING_CXX_FLAGS))"; \
Expand Down
4 changes: 2 additions & 2 deletions src/flisp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ INCLUDED_FLISP_FILES := flisp.c:cvalues.c flisp.c:types.c flisp.c:print.c flisp.
# Compilation database generation
.PHONY: regenerate-compile_commands
regenerate-compile_commands:
TMPFILE=$$(mktemp -p $(BUILDDIR) compile_commands.json.XXXXXX); \
@TMPFILE=$$(mktemp $(abspath $(BUILDDIR)/compile_commands.json.XXXXXX)); \
{ \
CLANG_TOOLING_C_FLAGS="$$($(JULIAHOME)/contrib/escape_json.sh clang $(CLANG_TOOLING_C_FLAGS))"; \
echo "["; \
Expand Down Expand Up @@ -176,7 +176,7 @@ clean:
rm -f $(BUILDDIR)/*.a
rm -f $(BUILDDIR)/$(EXENAME)$(EXE)
rm -f $(BUILDDIR)/$(EXENAME)-debug$(EXE)
rm -f $(BUILDDIR)/compile_commands.json
rm -f $(BUILDDIR)/compile_commands.json*
rm -f $(BUILDDIR)/host/*

.PHONY: flisp-deps compile-database
4 changes: 2 additions & 2 deletions src/support/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ INCLUDED_SUPPORT_FILES := hashing.c:MurmurHash3.c
# Compilation database generation
.PHONY: regenerate-compile_commands
regenerate-compile_commands:
TMPFILE=$$(mktemp -p $(BUILDDIR) compile_commands.json.XXXXXX); \
@TMPFILE=$$(mktemp $(abspath $(BUILDDIR)/compile_commands.json.XXXXXX)); \
{ \
CLANG_TOOLING_S_FLAGS="$$($(JULIAHOME)/contrib/escape_json.sh clang $(JCPPFLAGS) $(DEBUGFLAGS))"; \
CLANG_TOOLING_C_FLAGS="$$($(JULIAHOME)/contrib/escape_json.sh clang $(JCPPFLAGS) $(JCFLAGS) $(DEBUGFLAGS))"; \
Expand Down Expand Up @@ -123,7 +123,7 @@ clean:
rm -f $(BUILDDIR)/core*
rm -f $(BUILDDIR)/libsupport.a
rm -f $(BUILDDIR)/libsupport-debug.a
rm -f $(BUILDDIR)/compile_commands.json
rm -f $(BUILDDIR)/compile_commands.json*
rm -f $(BUILDDIR)/host/*

.PHONY: compile-database