# ----------------------------------------------------------------------------- # Makefile template starts here. default: all GHC_OPTS += -i$(odir) # For adding options on the command-line GHC_OPTS += $(EXTRA_HC_OPTS) HS_OBJS = $(patsubst %,$(odir)/%.$(osuf),$(subst .,/,$(modules))) HS_IFS = $(patsubst %,$(odir)/%.$(hisuf),$(subst .,/,$(modules))) C_OBJS = $(patsubst %.c,$(odir)/%.$(osuf),$(C_SRCS)) ifeq "$(way:%dyn=YES)" "YES" LIB = $(odir)/libHS$(package)$(_way:%_dyn=%)-ghc$(GHC_VERSION)$(soext) else LIB = $(odir)/libHS$(package)$(_way).a endif RM = rm -f # Optionally include local customizations: -include Makefile.local # Rules follow: MKSTUBOBJS = find $(odir) -name "*_stub.$(osuf)" -print # HACK ^^^ we tried to use $(wildcard), but apparently it fails due to # make using cached directory contents, or something. # We have to jump through some hoops if we don't want the vanilla way, # as it's handled specially ifneq "$(way) $(VANILLA_WAY)" " NO" all :: $(odir)/.depend $(LIB) endif $(odir)/.depend : $(MAKEFILE) $(GHC) -M $(GENERATE_DOT_DEPEND) $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(filter-out -split-objs, $(GHC_OPTS)) $(modules) for dir in $(sort $(foreach mod,$(HS_OBJS) $(C_OBJS),$(dir $(mod)))); do \ if test ! -d $$dir; then mkdir -p $$dir; fi \ done include $(odir)/.depend ifeq "$(way:%dyn=YES)" "YES" $(LIB) : $(HS_OBJS) $(C_OBJS) @$(RM) $@ $(GHC) -shared -dynamic -no-auto-link-packages -o $@ $(C_OBJS) $(HS_OBJS) `$(MKSTUBOBJS)` $(LIB_LD_OPTS) else ifneq "$(filter -split-objs, $(GHC_OPTS))" "" $(LIB) : $(HS_OBJS) $(C_OBJS) @$(RM) $@ (echo $(C_OBJS) `$(MKSTUBOBJS)`; find $(patsubst %.$(osuf),%_split,$(HS_OBJS)) -name '*.$(way_)o' -print) | xargs $(AR) q $(EXTRA_AR_ARGS) $@ else $(LIB) : $(HS_OBJS) $(C_OBJS) @$(RM) $@ echo $(C_OBJS) $(HS_OBJS) `$(MKSTUBOBJS)` | xargs $(AR) q $(EXTRA_AR_ARGS) $@ endif endif ifneq "$(GHCI_LIB)" "" ifeq "$(way)" "" all :: $(GHCI_LIB) $(GHCI_LIB) : $(HS_OBJS) $(C_OBJS) @$(RM) $@ $(LD) -r -o $@ $(EXTRA_LD_OPTS) $(HS_OBJS) `$(MKSTUBOBJS)` $(C_OBJS) endif endif # suffix rules # The .hs files might be in $(odir) if they were preprocessed $(odir_)%.$(osuf) : $(odir_)%.hs $(GHC) $(GHC_OPTS) -c $< -o $@ -ohi $(basename $@).$(hisuf) $(odir_)%.$(osuf) : $(odir_)%.lhs $(GHC) $(GHC_OPTS) -c $< -o $@ -ohi $(basename $@).$(hisuf) $(odir_)%.$(osuf) : %.c @$(RM) $@ $(GHC) $(GHC_CC_OPTS) -c $< -o $@ $(odir_)%.$(way_)s : %.c @$(RM) $@ $(GHC) $(GHC_CC_OPTS) -S $< -o $@ %.$(hisuf) : %.$(osuf) @if [ ! -f $@ ] ; then \ echo Panic! $< exists, but $@ does not.; \ exit 1; \ else exit 0 ; \ fi %.$(way_)hi-boot : %.$(osuf)-boot @if [ ! -f $@ ] ; then \ echo Panic! $< exists, but $@ does not.; \ exit 1; \ else exit 0 ; \ fi $(odir_)%.$(hisuf) : %.$(way_)hc @if [ ! -f $@ ] ; then \ echo Panic! $< exists, but $@ does not.; \ exit 1; \ else exit 0 ; \ fi show: @echo '$(VALUE)="$($(VALUE))"' clean :: $(RM) $(HS_OBJS) $(C_OBJS) $(LIB) $(GHCI_LIB) $(HS_IFS) .depend $(RM) -rf $(wildcard $(patsubst %.$(osuf), %_split, $(HS_OBJS))) $(RM) $(wildcard $(patsubst %.$(osuf), %.o-boot, $(HS_OBJS))) $(RM) $(wildcard $(patsubst %.$(osuf), %.hi-boot, $(HS_OBJS))) $(RM) $(wildcard $(patsubst %.$(osuf), %_stub.o, $(HS_OBJS))) ifneq "$(strip $(WAYS))" "" ifeq "$(way)" "" all clean :: # Don't rely on -e working, instead we check exit return codes from sub-makes. @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \ for i in $(WAYS) ; do \ echo "== $(MAKE) way=$$i -f $(MAKEFILE) $@;"; \ $(MAKE) way=$$i -f $(MAKEFILE) --no-print-directory $(MFLAGS) $@ ; \ if [ $$? -eq 0 ] ; then true; else exit $$x_on_err; fi; \ done @echo "== Finished recursively making \`$@' for ways: $(WAYS) ..." endif endif