# # rules.mk : set flags and make rules # # # pull in the file search stuff # include $(TOPDIR)/mk/paths.mk PRE_SRCS:= $(ALL_SRCS) #HC_OPTS += $(INC_OPTS) HSC_OPTS += -Imk $(INC_OPTS) CC_OPTS += -Imk -optc-O3 $(INC_OPTS) # If $(way) is set then we define $(way_) and $(_way) from it in the # obvious fashion. ifeq "$(way)" "p" way_ := $(way)_ _way := _$(way) endif # # building the profiled way # ifeq "$(way)" "p" PROF_OPTS = -prof -auto-all LD_OPTS += $(PROF_OPTS) HC_OPTS += $(PROF_OPTS) HC_OPTS += -hisuf $(way_)hi -hcsuf $(way_)hc -osuf $(way_)o endif # # Binary flags # BIN_HC_OPTS += $(patsubst %,-package %, $(BIN_DEPS)) BIN_LD_OPTS = $(BIN_LIBS) # # Compute dependencies # depend: $(MKDEPENDHS_SRCS) @echo -n "Rebuilding dependencies... " @$(GHC) -M -optdep-f -optdepdepend $(HC_OPTS) $(MKDEPENDHS_SRCS) @echo "done." # # boot and all targets # .PHONY: boot all boot :: depend all :: $(HS_BINS) $(BIN) :: $(OBJS) $(BIN_OBJS) $(GHC) -o $@ $(LD_OPTS) $(BIN_LD_OPTS) $(BIN_HC_OPTS) $(OBJS) $(BIN_OBJS) $(STRIP) $(BIN) EXTRA_CLEANS+= $(BIN) # No need to define .SUFFIXES because we don't use any suffix rules # Instead we use gmake's pattern rules exlusively .SUFFIXES: # This declaration tells GNU make to delete the target if it has # changed and the command which created it exited with a non-zero exit # code. .DELETE_ON_ERROR: # # We anticipate wanting to use multiple ways. Particularly prof. # %.$(way_)o: %.hs $(GHC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi %.$(way_)o : %.lhs $(GHC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi %.$(way_)hi : %.$(way_)o @: %_hsc.c %_hsc.h %.hs : %.hsc $(HSC2HS) $(HSC_OPTS) $(SYMS) $< @touch $(patsubst %.hsc,%_hsc.c,$<) %.$(way_)o : %.c @$(RM) $@ $(GHC) $(CC_OPTS) -c $< -o $@ # preprocssed files, for haddock docs # remember to strip #pragma lines from MacOSX cpp. %.raw-hs : %.lhs $(GHC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@ %.raw-hs : %.hs $(GHC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@ # Alex Suffix Rules %.hs : %.x $(ALEX) $(ALEX_OPTS) $< # Happy Suffix Rules %.hs : %.y $(HAPPY) $(HAPPY_OPTS) $< # # Building the haddock docs # ifneq "$(HADDOCK)" "" .PHONY: doc html docs :: html html :: html1 html2 HTML_DIR = html HADDOCK_SRCS += $(HS_SRCS) HS_PPS = $(addsuffix .raw-hs, \ $(filter-out $(basename $(NO_DOCS)), \ $(basename $(HADDOCK_SRCS)))) EXTRA_HS_PPS = $(addsuffix .raw-hs, $(basename $(NO_DOCS))) INSTALL_DATAS += $(HTML_DIR) # circular (excluded) modules first html1 : $(EXTRA_HS_PPS) @$(INSTALL_DIR) $(HTML_DIR) $(HADDOCK) $(HADDOCK_OPTS)2 -o $(HTML_DIR) $(EXTRA_HS_PPS) -k $(PKG) html2 : $(HS_PPS) @$(INSTALL_DIR) $(HTML_DIR) $(HADDOCK) $(HADDOCK_OPTS) -o $(HTML_DIR) $(HS_PPS) -k $(PKG) @cd $(HTML_DIR) && $(HADDOCK) --gen-index -i yi.interface -i yi.interface2 CLEAN_FILES += $(HS_PPS) $(EXTRA_HS_PPS) distclean :: $(RM) -rf $(HTML_DIR) endif # # cleaning # .PHONY: clean distclean clean: $(RM) $(MOSTLY_CLEAN_FILES) $(EXTRA_CLEANS) $(CLEAN_FILES) distclean :: clean $(RM) $(DIST_CLEAN_FILES) *~ */*~ $(RM) -rf $(DIST_CLEAN_DIRS) find tests -type f | sed -n '/^.*\/[0-9]*$$/p' | xargs rm -f # # installing # # For each of these variables that is defined, you # get one install rule # # INSTALL_PROGS executable programs in $(bindir) # INSTALL_LIBS platform-dependent libraries in $(libdir) (ranlib'ed) # INSTALL_DATAS platform-independent files in $(datadir) # INSTALL_IFACES platform-dependent interface files in $(ifacedir) # .PHONY: install install-dirs INSTALL_PROGS += $(HS_BINS) INSTALL_IFACES += INSTALL_LIBS += show-install : @echo "BINDIR = $(BINDIR)" @echo "LIBDIR = $(LIBDIR)" @echo "DATADIR = $(DATADIR)" # the sed is to strip any trailing '_' from the inplace bin names. ifneq "$(INSTALL_PROGS)" "" install :: $(INSTALL_PROGS) @$(INSTALL_DIR) $(BINDIR) @for i in $(INSTALL_PROGS); do \ j=`echo $$i | sed 's/_$$//'` ;\ echo $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(BINDIR)/$$j ;\ $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(BINDIR)/$$j ;\ done endif ifneq "$(INSTALL_LIBS)" "" install :: $(INSTALL_LIBS) @$(INSTALL_DIR) $(LIBDIR) @for i in $(INSTALL_LIBS); do \ echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(LIBDIR) ;\ $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(LIBDIR) ;\ done endif ifneq "$(INSTALL_DATA)" "" install :: $(INSTALL_DATAS) @$(INSTALL_DIR) $(DATADIR) @for i in $(INSTALL_DATAS); do \ if [ -d $$i ] ; then \ echo $(CP) -r $$i $(DATADIR)/ ;\ $(CP) -r $$i $(DATADIR)/ ;\ else \ echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DATADIR)/ ;\ $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DATADIR)/ ;\ fi ;\ done endif ifneq "$(INSTALL_IFACES)" "" install :: $(INSTALL_IFACES) @$(INSTALL_DIR) $(IFACEDIR) @for i in $(INSTALL_IFACES); do \ $(INSTALL_DIR) $(IFACEDIR)/`dirname $$i` ;\ echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(IFACEDIR)/`dirname $$i`/ ; \ $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(IFACEDIR)/`dirname $$i`/ ; \ done endif install :: $(PKG).conf.install @$(INSTALL_DIR) $(LIBDIR) $(INSTALL_DATA) $(INSTALL_OPTS) $< $(LIBDIR)/$(PKG).conf