I am trying to write a Makefile script for a provided directory structure and list of files by my clients. below image shows the roughly how source files and header files located in the main directory of the project.
rootDir/
-lib/
-socketserver/
-dist/
-bin/
-include/
-abms_engine_socket_server/
-abms_engine_socket_server.h
-common/
-----
-hashtable/
-----
-src/
-abms_engine_socket_server/
-Makefile
-abms_engine_socket_server.c
-common/
-----
-hashtable/
-----
In this case below are the build target directories
library file dir: (rootDir)/lib/socketserver bin file dir: (rootDir)/dist/bin/abms_engine_socket_server make file dir: (rootDir)/src/abms_engine_socket_server include files and source files also located within "include" and "src" directories.
I already try with below script to compile the entire source files.
HEADER_DIR = ../../include/abms_engine_socket_server
HEADER_COMMON_DIR = $(HEADER_DIR)/common
HEADER_HASHTABLE_DIR = $(HEADER_DIR)/hashtable
SRC_DIR = ..
SRC_COMMON_DIR = $(SRC_DIR)/common
SRC_HASHTABLE_DIR = $(SRC_DIR)/hashtable
OBJ_DIR = ../../lib/socketserver
DEST_DIR = ../../dist/bin
SRC = abms_engine_socket_server.c
CC = gcc -g -std=gnu99 -DUNIX -DINTERNAL_LOGGER
CFLAGS = -lm
PROG_ENG_SOCKET_SVR = $(DEST_DIR)/abms_engine_socket_server
HASHTABLE_OBJS = $(OBJ_DIR)/hashtable.o $(OBJ_DIR)/hashtable_itr.o $(OBJ_DIR)/hashtable_utility.o
COMMON_OBJS = $(OBJ_DIR)/CUtil.o $(OBJ_DIR)/CConfig.o $(OBJ_DIR)/CSocket.o
#Compiler to compile the hashtable objects
$(OBJ_DIR)/%.o : $(SRC_HASHTABLE_DIR)/%.c
$(CC) -c $< -o $@
#Compiler to compile the common objects which have header files too
$(OBJ_DIR)/%.o : $(SRC_COMMON_DIR)/%.c
$(CC) -c $< -o $@
#Compiler to compile the process objects which do not have header files
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $< -o $@
#Compiler to compile the other binaries
$(DEST_DIR)/% : $(OBJ_DIR)/%.o $(HASHTABLE_OBJS) $(COMMON_OBJS)
$(CC) $(CFLAGS) $(HASHTABLE_OBJS) $(COMMON_OBJS) $< -o $@
#all: $(PROG_ENG_SOCKET_SVR)
all: $(SRC) $(PROG_ENG_SOCKET_SVR)
clean:
rm -f *~ $(OBJ_DIR)/*.o $(PROG_ENG_SOCKET_SVR)
But finally I am getting bellow error make: Nothing to be done for `all'.
Please instruct me to create this make file to compile these sources using single make file. All responses are welcome. Thanks.
make clean
, and thenmake ../../lib/socketserver/abms_engine_socket_server.o
? – Betaall'. >>$ make clean rm -f *~ ../../lib/socketserver/*.o ../../dist/bin/abms_engine_socket_server rm: cannot remove
../../dist/bin/abms_engine_socket_server': Is a directory make: *** [clean] Error 1 ------------------------------------------------- According to this, I think the build destination also should be changed in the Make file. – Nishinclude/abms_engine_socket_server
andsrc/abms_engine_socket_server
appear to be directories, though they have no slashes. Butdist/bin/abms_engine_socket_server/
has a slash, even though the Makefile treats it as a target file. If it is a directory, I suggest you remove it and try again. – Beta../../dist/bin/abms_engine_socket_server', needed by
all'. Stop. " – Nish