[PATCH c-hglib] Makefile: create a Makefile to build the hglib shared library

julian.stana at gmail.com julian.stana at gmail.com
Mon Feb 24 12:33:03 CST 2014


# HG changeset patch
# User Iulian Stana and Giovanni Gherdovich <g.gherdovich at gmail.com>
# Date 1386352529 -7200
#      Fri Dec 06 19:55:29 2013 +0200
# Node ID 3450b2bacd1bc27126dcfab980463051f2057447
# Parent  d2f51737f8b2b819796c660b8fb5728862684ccc
Makefile: create a Makefile to build the hglib shared library

There are 5 types of targets: build, install, uninstall, examples, clean
 - the build target will create the shared library in the current directory.
 - the install target will create the shared library in the current directory
   and will copy it to the local directory.
 - the uninstall target will remove the shared library from the local directory
 - the examples target will create an executable file for each example
 - the clean target will clean the entire repository from build artifacts and
   binaries

diff --git a/Makefile b/Makefile
new file mode 100644
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,78 @@
+CC = gcc
+CFLAGS = -Wall -g -std=c89
+
+HGLIB_OBJ= hglib/client.o hglib/utils.o
+SHARED_LIBRARY = hg
+
+EXAMPLE_FILES = examples/export-import \
+		examples/import \
+		examples/init \
+		examples/log \
+		examples/merge \
+		examples/verify
+EXAMPLES_TARGETS = $(EXAMPLE_FILES:=_level0)
+
+SHARED_LIB_PATH = /usr/local/lib
+HGLIB_DIR_PATH = ./hglib
+EXAMPLES_DIR_PATH = ./examples
+
+
+# Build Target
+##############
+build: lib$(SHARED_LIBRARY).so
+
+
+# Help
+######
+help:
+	@echo 'Commonly used make targets:'
+	@echo '  build        - build the shared library in the local directory'
+	@echo '  install      - install the shared library to PREFIX ($(SHARED_LIB_PATH))'
+	@echo '  examples     - build example executable'
+	@echo '  clean        - remove files created by other targets'
+	@echo '  uninstall    - uninstall the shared library'
+
+
+# Install
+#########
+install: lib$(SHARED_LIBRARY).so
+	cp -uf lib$(SHARED_LIBRARY).so $(SHARED_LIB_PATH)
+
+uninstall:
+	rm -f $(SHARED_LIB_PATH)/lib$(SHARED_LIBRARY).so
+
+
+# Shared Library
+################
+lib$(SHARED_LIBRARY).so: $(HGLIB_OBJ)
+	$(CC) -shared $(HGLIB_OBJ) -o lib$(SHARED_LIBRARY).so
+
+hglib/%.o: hglib/%.c
+	$(CC) $(CFLAGS) -fPIC -c $< -o $@
+
+
+# Examples
+##########
+examples: build $(EXAMPLE_FILES)
+
+examples/%: examples/%.o
+	$(CC) $(CFLAGS) $< -o $@_level0 -l$(SHARED_LIBRARY) -L.
+
+examples/%.o: examples/%.c
+	$(CC) $(CFLAGS) -c $< -o $@ -I$(HGLIB_DIR_PATH)
+
+
+# Clean
+#######
+clean: cleanex cleanhg
+	rm -f *.o *~
+	rm -f lib$(SHARED_LIBRARY).so
+
+cleanex:
+	rm -f $(EXAMPLES_DIR_PATH)/*.o $(EXAMPLES_DIR_PATH)/*~
+	rm -f $(EXAMPLES_TARGETS)
+
+cleanhg:
+	rm -f $(HGLIB_DIR_PATH)/*.o $(HGLIB_DIR_PATH)/*~
+
+.PHONY: build clean install uninstall examples


More information about the Mercurial-devel mailing list