Skip to content

Commit

Permalink
Makefile: Use portable target-local variables 1/2
Browse files Browse the repository at this point in the history
BSD make does not support mixing global and local variables. In other
words, do not use += to append to global variables in target-local
definitions.
  • Loading branch information
tleedjarv committed Dec 16, 2024
1 parent d3c5729 commit 239d9dc
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/Makefile.OCaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ OCAMLOBJS_TUI+=linktext.cmo
## Mac UI
OCAMLOBJS_MAC+=uimacbridge.cmo
OCAMLLIBS_MAC+=threads.cma
INCLFLAGS_MAC+=-I +threads
CAMLFLAGS_MAC+=-I +threads

## Graphic UI
ifndef OCAMLFIND
Expand Down Expand Up @@ -352,7 +352,7 @@ ifneq ($(findstring $(OSARCH),FreeBSD OpenBSD NetBSD DragonFly),)
rm -f inotifytest__.ml inotifytest__.cm[oix] inotifytest__.o inotifytest__ > /dev/null 2>&1)
ifeq ($(FOUND_LIBINOTIFY), true)
FSMDIR = fsmonitor/inotify
$(NAME_FSM)$(EXEC_EXT): CAMLCFLAGS += $(LIBINOTIFY_INC)
$(NAME_FSM)$(EXEC_EXT): CAMLCFLAGS_FSM_X = $(LIBINOTIFY_INC)
CLIBS_FSM = $(LIBINOTIFY_LIB)
endif
endif
Expand Down Expand Up @@ -417,40 +417,44 @@ win32rc/unison.res.lib: win32rc/unison.rc win32rc/U.ico
$(WINDRES) win32rc/unison.rc win32rc/unison.res
$(WINDRES) win32rc/unison.res win32rc/unison.res.lib

# Context-specific variables, enabling target local variables
CAMLFLAGS_X = $(CAMLFLAGS) $(CAMLFLAGS_GUI_X) $(CAMLFLAGS_FSM_X) $(CAMLFLAGS_MAC_X)
CAMLCFLAGS_X = $(CAMLCFLAGS) $(CAMLCFLAGS_FSM_X)

.SUFFIXES:
.SUFFIXES: .mli .cmi .ml .cmo .cmx .c .o .obj

.mli.cmi:
@echo "$(CAMLC): $< ---> $@"
$(CAMLC) $(CAMLFLAGS) -c $(CWD)/$<
$(CAMLC) $(CAMLFLAGS_X) -c $(CWD)/$<

.ml.cmo:
@echo "$(OCAMLC): $< ---> $@"
$(OCAMLC) $(CAMLFLAGS) -c $(CWD)/$<
$(OCAMLC) $(CAMLFLAGS_X) -c $(CWD)/$<

.ml.cmx:
@echo "$(OCAMLOPT): $< ---> $@"
$(OCAMLOPT) $(CAMLFLAGS) -c $(CWD)/$<
$(OCAMLOPT) $(CAMLFLAGS_X) -c $(CWD)/$<

.c$(OBJ_EXT):
@echo "$(CAMLC): $< ---> $@"
$(CAMLC) $(CAMLFLAGS) $(CAMLCFLAGS) -ccopt $(OUTPUT_SEL)$(CWD)/$@ -c $(CWD)/$<
$(CAMLC) $(CAMLFLAGS_X) $(CAMLCFLAGS_X) -ccopt $(OUTPUT_SEL)$(CWD)/$@ -c $(CWD)/$<

$(NAME)$(EXEC_EXT): $(CAMLOBJS) $(CAMLOBJS_TUI) $(COBJS)
@echo Linking $@
$(CAMLC) -verbose $(CAMLFLAGS) $(CAMLLDFLAGS) -o $@ $(CAMLLIBS) $^ $(CLIBS)
$(CAMLC) -verbose $(CAMLFLAGS_X) $(CAMLLDFLAGS) -o $@ $(CAMLLIBS) $^ $(CLIBS)

$(NAME_GUI)$(EXEC_EXT): CAMLFLAGS += $(CAMLFLAGS_GUI)
$(NAME_GUI)$(EXEC_EXT): CAMLFLAGS_GUI_X = $(CAMLFLAGS_GUI)
$(NAME_GUI)$(EXEC_EXT): $(CAMLOBJS) $(CAMLOBJS_GUI) $(COBJS)
@echo Linking $@
$(CAMLC) -verbose $(CAMLFLAGS) $(CAMLLDFLAGS) $(CAMLLDFLAGS_GUI) -o $@ $(CAMLLIBS) $(CAMLLIBS_GUI) $^ $(CLIBS)
$(CAMLC) -verbose $(CAMLFLAGS_X) $(CAMLLDFLAGS) $(CAMLLDFLAGS_GUI) -o $@ $(CAMLLIBS) $(CAMLLIBS_GUI) $^ $(CLIBS)

$(NAME_FSM)$(EXEC_EXT): CAMLFLAGS += -I fsmonitor -I $(FSMDIR)
$(NAME_FSM)$(EXEC_EXT): CAMLFLAGS_FSM_X = -I fsmonitor -I $(FSMDIR)
$(NAME_FSM)$(EXEC_EXT): $(CAMLOBJS_FSM) $(FSMCOBJS)
@echo Linking $@
$(CAMLC) -verbose $(CAMLFLAGS) $(CAMLLDFLAGS) -o $@ $(CAMLLIBS_FSM) $^ $(CLIBS) $(CLIBS_FSM)
$(CAMLC) -verbose $(CAMLFLAGS_X) $(CAMLLDFLAGS) -o $@ $(CAMLLIBS_FSM) $^ $(CLIBS) $(CLIBS_FSM)

$(NAME)-blob.o: INCLFLAGS += $(INCLFLAGS_MAC)
$(NAME)-blob.o: CAMLFLAGS_MAC_X = $(CAMLFLAGS_MAC)
# Unfortunately -output-obj does not put .o files into the output, only .cmx
# files, so we have to use $(LD) to take care of COBJS.
# [2023-07] The limitations of -output-obj have been overcome by a new option
Expand All @@ -459,7 +463,7 @@ $(NAME)-blob.o: INCLFLAGS += $(INCLFLAGS_MAC)
# threads (needed by uimacbridge): https://github.com/ocaml/ocaml/issues/7933
$(NAME)-blob.o: $(CAMLOBJS) $(CAMLOBJS_MAC) $(COBJS)
@echo Linking $@
$(CAMLC) -dstartup -output-obj -verbose -cclib -keep_private_externs $(CAMLFLAGS) -o u-b.o $(CAMLLDFLAGS) $(CAMLLIBS) $(CAMLLIBS_MAC) $(CLIBS) $(CAMLOBJS) $(CAMLOBJS_MAC)
$(CAMLC) -dstartup -output-obj -verbose -cclib -keep_private_externs $(CAMLFLAGS_X) -o u-b.o $(CAMLLDFLAGS) $(CAMLLIBS) $(CAMLLIBS_MAC) $(CLIBS) $(CAMLOBJS) $(CAMLOBJS_MAC)
$(LD) -r -keep_private_externs -o $@ u-b.o $(COBJS)
$(RM) u-b.o

Expand Down

0 comments on commit 239d9dc

Please sign in to comment.