Commits

Anonymous committed 12eb3bb

Hacked around in the makefile. Some of the OS if structures are rather ugly
atm. Corrected a few misnamed variables (CFLAGS to CXXFLAGS and LFLAGS to LDFLAGS). Also added rules
to properly handle dependencies. The build rules work on linux...give it a go
Macizens.

Comments (0)

Files changed (1)

-ifeq ($(shell uname),Linux)
-ARCH = linux
-LIBEXT = so
-else
-ARCH = macosx
-LIBEXT = dylib
+CPP := g++
+ARCH := $(shell uname -m | tr -s " ") #x86_64, x86, ppc, ...
+KERNEL := $(shell uname -s | tr -s " ") #Linux, Darwin, ...
+
+#Build environment pointers
+LIB_DIR := ./lib
+SRC_DIR := ./src
+OBJ_DIR := $(SRC_DIR)/_$(ARCH)
+ERL_DIR := ./erl
+EBIN_DIR := ./ebin
+
+#OS specific settings.  <<HERE>> This is ugly...fix?
+ifeq ($(KERNEL),Linux )
+LIB_EXT = so
+LDFLAGS = -Wall -fPIC -shared -flat_namespace -undefined
+else 
+ifeq ($(KERNEL),Darwin)
+LIB_EXT = dylib
+LDFLAGS = -Wall -fPIC -dynamiclib -flat_namespace -undefined suppress
+endif 
+$(error Makerules don't exists for $(KERNEL))
 endif
 
-PACKAGE_NAME = v8erl
-OUTLIB = lib$(PACKAGE_NAME).$(LIBEXT)
+#Is ERL_ROOT defined?  If not we have to guess....
+ifeq (${ERL_ROOT},)
+ERL_INC += -I/usr/lib/erlang/usr/include
+ERL_INC += -I/usr/local/lib/erlang/usr/include
+ERL_INC += -I/opt/local/lib/erlang/usr/include
 
-# erlang
-ERL_ROOT = /opt/local/lib/erlang
-ERL_INC  = $(ERL_ROOT)/usr/include
-# v8
-V8_ROOT  = ../v8
-V8_INC   = $(V8_ROOT)/include
-# compile
-CPP      = g++
-CFLAGS   = -Iinclude -I$(V8_INC) -I$(ERL_INC) -g -c -Wall
-LFLAGS   = -Wall -fPIC -dynamiclib -flat_namespace -undefined suppress -L$(V8_ROOT) -lv8_g
-CPPSRCS  = $(wildcard src/*.cc)
-CPPOBJS  = $(patsubst %.cc,%.o,$(CPPSRCS))
+EI_LIB += -L/usr/lib/erlang/lib/erl_interface-3.5.9/lib
+EI_LIB += -L/usr/local/lib/erlang/lib/erl_interface-3.5.9/lib
+EI_LIB += -L/opt/local/lib/erlang/lib/erl_interface-3.5.9/lib
+else
+ERL_INC = -I${ERL_ROOT}/usr/include
+EI_LIB = -L${ERL_ROOT}/lib/erl_interface-3.5.9/lib
+endif
 
-all: $(CPPOBJS) $(OUTLIB)
+#Is V8_ROOT defined?  If not we have to guess....
+ifeq (${V8_ROOT},)
+V8_INC += -I./v8/include
+V8_INC += -I../v8/include
 
-%.o: %.cc
-	$(CPP) $(CFLAGS) -o $@ $<
+V8_LIB += -L./v8
+V8_LIB += -L../v8
+else
+V8_LIB = -L${V8_ROOT}
+endif
 
+#Libs to build
+LIBS = v8erl
+LIB_TARGETS = $(addsuffix .$(LIB_EXT),$(addprefix lib/lib,$(LIBS)))
 
-%.dylib: $(CPPOBJS)
-	$(CPP) $(LFLAGS) -o $@ $(CPPOBJS)
+#Beams to build
+ERL_FILES = $(wildcard $(ERL_DIR)/*.erl)
+BEAM_FILES = $(addsuffix .beam,$(notdir $(basename $(ERL_FILES))))
+BEAM_TARGETS = $(addprefix $(EBIN_DIR)/,$(BEAM_FILES))
 
-ebin:
-	mkdir ebin
+APPS = $(wildcard $(ERL_DIR)/*.app)
+APP_TARGETS = $(addprefix $(EBIN_DIR)/,$(notdir $(APPS)))
+
+#Compile flags
+CXXFLAGS  = -I./include $(V8_INC) $(ERL_INC) -g -Wall
+
+default: all
+
+localdirs:
+	install -d $(LIB_DIR)
+	install -d $(EBIN_DIR)
+
+all: localdirs $(LIB_TARGETS) $(BEAM_TARGETS) $(APP_TARGETS)
+
+$(SRC_DIR)/%.o: $(SRC_DIR)/%.cc
+	$(CPP) -c $(CXXFLAGS) -o $@ $<
+
+lib/libv8erl.so: CXXFLAGS += -fPIC
+lib/libv8erl.so: $(SRC_DIR)/driver.o $(SRC_DIR)/js2erl.o
+	$(CPP) $(LDFLAGS) $^ -o $@
+
+lib/libv8erl.dylib: CXXFLAGS += -fPIC
+lib/libv8erl.dylib: $(SRC_DIR)/driver.o $(SRC_DIR)/js2erl.o
+	$(CPP) $(LDFLAGS) $^ -o $@
+
+$(EBIN_DIR)/%.beam: $(ERL_DIR)/%.erl
+	erlc -W -o $(EBIN_DIR)/ $<
+
+$(EBIN_DIR)/%.app: $(ERL_DIR)/%.app
+	cp $< $@
 
 erl: ebin
 	cd erl && make
 
-clean:
-	-rm $(CPPOBJS) $(OUTLIB)
-
-
+clean:    
+	rm -f src/*.o
+	rm -rf $(LIB_DIR)
+	rm -rf $(EBIN_DIR)
 
 .PHONY: clean erl
+