Create a gist now

Instantly share code, notes, and snippets.

@janl /Makefile
Created Oct 23, 2016

What would you like to do?
CouchDB 0.5.0 Custom Makefile by @janl
# CouchDb Makefile
# (c) 2006 Jan Lehnardt <jan@php.net>
# This program is Free Software. See license.txt
UNICODE_INCLUDE_DIR ?= /usr/include/
ERLANG_INCLUDE_DIR ?= /usr/lib/erlang/driver
COUCHDB_INSTALL_DIR ?= /usr/local/couchdb
ERLC ?= /usr/bin/erlc
BUILD_DIR ?= ./build
DIST_DIR ?= ./dist
CC ?= /usr/bin/gcc
CPP ?= /usr/bin/g++
INSTALL ?= /usr/bin/install
ANTLR_OBJ_FILES=Fabric/antlr/ANTLRUtil.o Fabric/antlr/BitSet.o Fabric/antlr/CommonHiddenStreamToken.o Fabric/antlr/MismatchedTokenException.o Fabric/antlr/RecognitionException.o Fabric/antlr/TokenStreamBasicFilter.o Fabric/antlr/ASTFactory.o Fabric/antlr/CharBuffer.o Fabric/antlr/CommonToken.o Fabric/antlr/MismatchedUnicodeCharException.o Fabric/antlr/String.o Fabric/antlr/TokenStreamHiddenTokenFilter.o Fabric/antlr/ASTNULLType.o Fabric/antlr/CharScanner.o Fabric/antlr/InputBuffer.o Fabric/antlr/NoViableAltException.o Fabric/antlr/Token.o Fabric/antlr/TokenStreamRewriteEngine.o Fabric/antlr/ASTRefCount.o Fabric/antlr/CommonAST.o Fabric/antlr/LLkParser.o Fabric/antlr/NoViableAltForCharException.o Fabric/antlr/TokenBuffer.o Fabric/antlr/TokenStreamSelector.o Fabric/antlr/BaseAST.o Fabric/antlr/CommonASTWithHiddenTokens.o Fabric/antlr/MismatchedCharException.o Fabric/antlr/Parser.o Fabric/antlr/TokenRefCount.o Fabric/antlr/TreeParser.o
FABRIC_OBJ_FILES=Fabric/GeneratedCode/FabricLexer.o Fabric/GeneratedCode/FabricParser.o Fabric/Fabric.o Fabric/Element.o Fabric/NewRuntimeNode.o
CPPFLAGS=-I./Fabric/ -I./Fabric/GeneratedCode/ -I$(UNICODE_INCLUDE_DIR) -I./Fabric/antlr/ -D_DEBUG
LDFLAGS=-L$(BUILD_DIR)/
COUCH_DB_BEAM_FILES=$(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_db.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_doc.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_file.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_server.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_stream.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_util.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_btree.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_db_sup.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_fabric.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_log.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_server_sup.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch_table_group.beam $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/mod_couch.beam
#
# copy common
# copy build/couch-x.x.x -> install/lib/
# copy build/couch.boot install/boot
# copy startCouchDb ->install/bin
# copy couch_erl_driver.so -> install/lib
# copy FabricServer => install/bin
install: couchdb
cp -R dist/common/* $(COUCHDB_INSTALL_DIR)/
mkdir $(COUCHDB_INSTALL_DIR)/lib $(COUCHDB_INSTALL_DIR)/bin
cp $(BUILD_DIR)/FabricServer $(COUCHDB_INSTALL_DIR)/bin/
cp dist/unix/bin/startCouchDb.sh $(COUCHDB_INSTALL_DIR)/bin/
cp $(BUILD_DIR)/couch_erl_driver.so $(COUCHDB_INSTALL_DIR)/lib/
cp -R $(BUILD_DIR)/couch-$(COUCHDB_VERSION) $(ERLANG_LIB_DIR)
mv $(COUCHDB_INSTALL_DIR)/couch_httpd.conf.src $(COUCHDB_INSTALL_DIR)/couch_httpd.conf
./dist/unix/bin/config.sh
mv ./dist/unix/couch.ini $(COUCHDB_INSTALL_DIR)/
mkdir $(COUCHDB_INSTALL_DIR)/boot/
cp $(BUILD_DIR)/couch.boot $(COUCHDB_INSTALL_DIR)/boot/
dist: couchdb
cp $(BUILD_DIR)/FabricServer $(DIST_DIR)/
cp $(BUILD_DIR)/couch_erl_driver.so $(DIST_DIR)/
#couchdb
couchdb: host $(BUILD_DIR)/couch_erl_driver.so $(COUCH_DB_BEAM_FILES) $(BUILD_DIR)/FabricServer $(BUILD_DIR)/couch.boot
@echo "CouchDb has been built successfully!"
host:
ifeq ($(strip $(HOST)),)
@echo "Cannot determine HOST. exiting...";
exit 1;
endif
$(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/%.beam: CouchDb/%.erl
$(ERLC) -o $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin $<
$(BUILD_DIR)/couch_erl_driver.so:
ifeq ($(HOST),Linux)
$(CC) -rdynamic -shared -I$(ERLANG_INCLUDE_DIR) CouchDb/couch_port_driver.c -L/usr/lib -o $(BUILD_DIR)/couch_erl_driver.so -licuuc -licudata -licui18n
endif
ifeq ($(HOST),Darwin)
$(CC) -bundle -flat_namespace -undefined suppress -I$(ERLANG_INCLUDE_DIR) CouchDb/couch_port_driver.c -L/usr/local/lib -o $(BUILD_DIR)/couch_erl_driver.so -licudata -licuuc -licui18n
@echo "ignore the warning?"
endif
$(BUILD_DIR)/couch.boot: CouchDb/couch.rel $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch.app
$(ERLC) -pa $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/ -I $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/ -I CouchDb/ -o $(BUILD_DIR)/ CouchDb/couch.rel
$(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch.app: CouchDb/couch.app
cp CouchDb/couch.app $(BUILD_DIR)/couch-$(COUCHDB_VERSION)/ebin/couch.app
# fabric
$(BUILD_DIR)/FabricServer: $(BUILD_DIR)/libfabric.a
$(CPP) $(CPPFLAGS) $(LDFLAGS) FabricServer/FabricServer.cpp -o $(BUILD_DIR)/FabricServer -lfabric -licuuc -licui18n -licudata
@echo "FabricServer done"
$(BUILD_DIR)/FabricTests: fabric
$(CPP) $(CPPFLAGS) $(LDFLAGS) Fabric/FabricTests/FabricTests.cpp -o $(BUILD_DIR)/FabricTests -lfabric -licuuc -licui18n -licudata
@echo "Fabric Tests Done"
$(BUILD_DIR)/libfabric.a: $(FABRIC_OBJ_FILES) $(ANTLR_OBJ_FILES)
$(AR) rcs $(BUILD_DIR)/libfabric.a Fabric/*.o Fabric/GeneratedCode/*.o Fabric/antlr/*.o
Fabric/Fabric.o:
$(CPP) -c $(CPPFLAGS) Fabric/Fabric.cpp -o Fabric/Fabric.o
Fabric/Element.o:
$(CPP) -c $(CPPFLAGS) Fabric/Element.cpp -o Fabric/Element.o
Fabric/NewRuntimeNode.o:
$(CPP) -c $(CPPFLAGS) Fabric/NewRuntimeNode.cpp -o Fabric/NewRuntimeNode.o
Fabric/GeneratedCode/%.cpp:
./Fabric/AntlrCodeGen.sh
Fabric/GeneratedCode/FabricLexer.o: Fabric/GeneratedCode/FabricLexer.cpp
$(CPP) -c $(CPPFLAGS) $< -o $@
Fabric/GeneratedCode/FabricParser.o: Fabric/GeneratedCode/FabricParser.cpp
$(CPP) -c $(CPPFLAGS) $< -o $@
Fabric/antlr/.cpp.o:
$(CPP) -c $(CPPFLAGS) $< -o $@
# clean
clean: clean_all
clean_all: clean_fabric clean_antlr clean_fabrictest clean_fabricserver
rm -rf build/*
clean_fabric:
rm -f Fabric/*.o Fabric/GeneratedCode/*.o
clean_antlr:
rm -f Fabric/antlr/*.o
clean_fabrictest:
rm -f Fabric/FabricTest/FabricTest
clean_fabricserver:
rm -f FabricServer/FabricServer
.PHONY: clean clean_all clean_antlr clean_fabricserver clean_fabrictest fabric fabric_server couchdb host dist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment