#********************************************************************* # # (C) 2001-07 Justin Couch # http://www.vlc.com.au/~justin/ # # Lowest level common makefile for both native and Java code # # Author: Justin Couch # Version: $Revision: 1.2 $ # #********************************************************************* # # Directories for standard stuff # include $(PROJECT_ROOT)/make/Makefile.inc NATIVE_DEV_ROOT = $(SRC_DIR)/native NATIVE_SRC_DIR = $(NATIVE_DEV_ROOT) 3RDPARTY_DLL_DIR = dll DESTINATION = obj LIB_DESTINATION = bin JNI_HEADER_DIR = $(JAVA_HOME)/include # # Built up tool information # CC=gcc CFLAGS= INCLUDE_LIST=$(INCLUDES) $(INCLUDE_DIR) $(JNI_HEADER_DIR) EMPTY = SPACE = $(EMPTY) $(EMPTY) OS_NAME=$(shell uname) ifeq (, $(strip $(findstring CYGWIN, $(OS_NAME)))) PATH_SEP=':' LIB_SUFFIX=so LIB_PREFIX=lib INCLUDE_LIST+=$(JNI_HEADER_DIR)/linux CC_LINK_OPTIONS = -Wl -shared $(CFLAGS) ifdef LIBRARY_3RDPARTY 3RDPARTY_LIBS = $(patsubst %,-l%, $(LIBRARY_3RDPARTY)) endif else PATH_SEP=';' LIB_SUFFIX=dll LIB_PREFIX= INCLUDE_LIST+=$(JNI_HEADER_DIR)/win32 /usr/include/win32api CFLAGS +=-D_WIN32 CC_LINK_OPTIONS = -shared $(CFLAGS) -L$(3RDPARTY_DLL_DIR) ifdef LIBRARY_3RDPARTY 3RDPARTY_LIBS = $(patsubst %,-l%, $(LIBRARY_3RDPARTY)) endif endif INCS=$(subst $(SPACE)$(SPACE),$(SPACE),$(INCLUDE_LIST)) INC_DIRS=$(subst $(SPACE),$(SPACE)-I,$(INCS)) # # Option listing for the various commands # CC_OPTIONS = -c -O2 $(INC_DIRS) $(CFLAGS) # # Build rules. # ifdef LIBRARY LIB_DIR = $(DESTINATION)/$(LIBRARY) OBJ_FILE_LIST = $(SOURCE_FILES:%.c=%.o) OBJ_FILES = $(SOURCE_FILES:%.c=$(DESTINATION)/$(LIBRARY)/%.o) LIB_FILES = $(LIB_DESTINATION)/$(LIB_PREFIX)$(LIBRARY).$(LIB_SUFFIX) endif SOURCE_FILES = $(filter %.c,$(C_SOURCE)) LIB_LIST_CLEAN = $(patsubst %,$(NATIVE_SRC_DIR)/%/.clean,$(LIBRARY_LIST)) LIB_LIST_BUILD = $(patsubst %,$(NATIVE_SRC_DIR)/%/.build,$(LIBRARY_LIST)) # # General build rules # # Rule 0. Applied when make is called without targets. all: $(LIB_DIR) $(LIB_DESTINATION) $(OBJ_FILES) $(LIB_FILES) # Rule 1. If the destination dir is missing then create it $(LIB_DIR) : $(PRINT) Missing object dir. Creating $(LIB_DIR) $(MAKEDIR) $(LIB_DIR) # Rule 1. If the destination dir is missing then create it $(LIB_DESTINATION) : $(PRINT) Missing library output dir. Creating $(LIB_DESTINATION) $(MAKEDIR) $(LIB_DESTINATION) # Rule 2. Change ".build" tag to "Makefile", thus call the library makefile # which in turn recalls this makefile with target all (rule 10). %.build : $(PRINT) Building directory $(subst .build,' ',$@) $(MAKE) -k -f $(subst .build,Makefile,$@) all # Rule 3. Call rule 2 for every package buildall : $(LIB_LIST_BUILD) $(PRINT) Completed native libraries. # # Specific dependency build rules # # Rule 4. Building a .o object file from a .java file $(LIB_DIR)/%.o : $(NATIVE_DIR)/$(LIBRARY)/%.c $(PRINT) Compiling $*.c $(CC) $(CC_OPTIONS) $< -o $@ # Rule 5. Building a .o file from a .c file. Invokes rule 4. %.o : $(NATIVE_DIR)/$(LIBRARY)/%.c $(PRINT) creating $(LIB_DIR)/$(LIBRARY) $(MAKE) -k $(LIB_DIR)/$@ # Rule 6. Building a .dll or .so from .o files. $(LIB_DESTINATION)/$(LIB_PREFIX)$(LIBRARY).$(LIB_SUFFIX): $(OBJ_FILES) $(PRINT) Building $@ $(CC) $(CC_LINK_OPTIONS) -o $(LIB_DESTINATION)/$(LIB_PREFIX)$(LIBRARY).$(LIB_SUFFIX) $(OBJ_FILES) $(3RDPARTY_LIBS) # # Cleanups # # Rule 8. Remove all produced files (except javadoc) cleanall : $(DELETE) $(LIB_DIR)/*.o # Rule 9. Change ".clean" tag to "Makefile", thus call the package makefile # which in turn recalls this makefile with target cleanall (rule 8). %.clean : $(MAKE) -k -f $(subst .clean,Makefile,$@) cleanall # Rule 10: Call rule 9 for every package directory clean : $(LIB_LIST_CLEAN) $(PRINT) Done clean. # Rule to build everything complete : clean buildall