Alan Falloon avatar Alan Falloon committed 55871db

Made the makefile build the three different targets

Comments (0)

Files changed (2)

-export PATH:=.:$(shell pwd)/extern/bin:$(PATH)
+FEATURES:=$(sort $(filter target-specific order-only second-expansion,$(.FEATURES)))
+ifneq (order-only second-expansion target-specific,$(FEATURES))
+$(error Your version of make does not support the required features.)
+endif
+
+.PHONY: all
+all: $(addprefix bin/,part1 part2 part3)
+
+export PATH:=$(abspath extern/bin):$(PATH)
 OCAMLC=ocamlc 
 OCAMLOPT=ocamlopt 
 OCAMLLEX=ocamllex
 LINKFLAGS=-linkpkg
 OCAMLOPTFLAGS=
 
-SRC_FILES := part3/son_of_blub.ml
-ML_FILES  := $(filter %.ml,$(patsubst %.mll,%.ml,$(SRC_FILES:%.mly=%.ml)))
-MLI_FILES := $(filter %.mli,$(SRC_FILES:%.mly=%.mli))
-CMX_FILES := $(ML_FILES:%.ml=%.cmx) 
-CMO_FILES := $(ML_FILES:%.ml=%.cmo)
-CMI_FILES := $(MLI_FILES:%.mli=%.cmi) $(ML_FILES:%.ml=%.cmi)
-GARBAGE := $(filter-out $(SRC_FILES),$(ML_FILES) $(MLI_FILES) $(CMX_FILES) $(CMX_FILES:%.cmx=%.o) $(CMO_FILES) $(CMI_FILES) interpreter .depend)
+LLVMMODULES:=llvm_bitwriter llvm_executionengine llvm llvm_scalar_opts
+LLVMOC:=$(LLVMMODULES:%=%.cmxa)
+LLVML:=$(addprefix -cclib ,$(LLVMMODULES:%=-l%))
+
+# A little function to get all the ml files that can be created from the sources
+get-ml-files= $(filter  %.ml,$(patsubst %.mly,%.ml,$(patsubst %.mll,%.ml,$(1))))
+get-mli-files=$(filter %.mli,$(patsubst %.mly,%.mli,$(1)))
+
+part1_SRC_FILES := part1/barebones_blub.ml
+part2_SRC_FILES := part2/son_of_blub.ml
+part3_SRC_FILES := part3/son_of_blub.ml
+
+part:=part1
+include partN.mk
+part:=part2
+include partN.mk
+part:=part3
+include partN.mk
+
+GARBAGE := .depend $(filter-out $(SRC_FILES),$(GARBAGE))
+
+$(addprefix bin/,part1 part2 part3): %:
+	$(OCAMLFIND) $(OCAMLOPT) $(OCAMLFLAGS) $(INCLUDES) $(LINKFLAGS) -o $@ $(LLVMOC) $(OCAMLOPTFLAGS) $^ $(LLVML)
 
 .SUFFIXES:
 
 %.ml: %.mll
 	$(OCAMLLEX) $<
 
-all : part1
-
-LLVMMODULES:=llvm_bitwriter llvm_executionengine llvm llvm_scalar_opts
-LLVMOC:=$(LLVMMODULES:%=%.cmxa)
-LLVML:=$(addprefix -cclib ,$(LLVMMODULES:%=-l%))
-
-part1 : $(CMX_FILES)
-	$(OCAMLFIND) $(OCAMLOPT) $(OCAMLFLAGS) $(INCLUDES) $(LINKFLAGS) -o p2 $(LLVMOC) $(OCAMLOPTFLAGS) $^ $(LLVML)
-
 clean ::
 	rm -f $(GARBAGE)
 
 .PRECIOUS: %/
-extern/ extern/tar/ extern/build/ : %/ :
+extern/ extern/tar/ extern/build/ bin/ : %/ :
 	mkdir -p $@
-extern/tar/ extern/build/ : extern/
+extern/tar/ extern/build/ : | extern/
 
 PREFIX:=$(shell pwd)/extern
 EXTERNALS:=$(addprefix extern/bin/,ocamlc ocamlfind llvm-as) $(patsubst %,extern/lib/ocaml/site-lib/%/META,monad extlib)
 .depend: $(MLI_FILES) $(ML_FILES) | $(EXTERNALS) 
 	$(OCAMLFIND) $(OCAMLDEP) $(INCLUDES) $^ > .depend
 
-include .depend
+-include .depend
+$(part)_ML_FILES  := $(call get-ml-files, $($(part)_SRC_FILES))
+$(part)_MLI_FILES := $(call get-mli-files,$($(part)_SRC_FILES))
+$(part)_CMX_FILES := $($(part)_ML_FILES:%.ml=%.cmx) 
+$(part)_CMO_FILES := $($(part)_ML_FILES:%.ml=%.cmo)
+$(part)_CMI_FILES := $($(part)_MLI_FILES:%.mli=%.cmi) $($(part)_ML_FILES:%.ml=%.cmi)
+SRC_FILES      	  := $(SRC_FILES) $($(part)_SRC_FILES)
+GARBAGE        	  := $(GARBAGE)					\
+		     $($(part)_ML_FILES)			\
+		     $($(part)_MLI_FILES)			\
+		     $($(part)_CMX_FILES)			\
+		     $($(part)_CMO_FILES)			\
+		     $($(part)_CMI_FILES)			\
+		     $($(part)_CMX_FILES:%.cmx=%.o)	
+ML_FILES  := $(ML_FILES)  $($(part)_ML_FILES)
+MLI_FILES := $(MLI_FILES) $($(part)_MLI_FILES)
+
+bin/$(part): $($(part)_CMX_FILES) | bin/
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.