0
votes

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.

1
What happens when you make clean, and then make ../../lib/socketserver/abms_engine_socket_server.o?Beta
@Beta, I just tried it and gave below output. ---------------------------------------------- >>$ make make: Nothing to be done for all'. >>$ 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.Nish
Your description of the directory structure is inconsistent in the use of slashes. Both include/abms_engine_socket_server and src/abms_engine_socket_server appear to be directories, though they have no slashes. But dist/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
@Beta, I just removed "abms_engine_socket_server" from destination directory in the directory structure and put try again without making any changes on Makefile. Then it is hitting this error(for make all) "make: *** No rule to make target ../../dist/bin/abms_engine_socket_server', needed by all'. Stop. "Nish
What happens when you make clean, and then make ../../lib/socketserver/abms_engine_socket_server.o?Beta

1 Answers

0
votes

I have a rather similar structure, so yo can take a look at my makefile which I documented here if it is of help to you.

Makefile: no rule to make target

You must look at the accepted answer, that's the one containing my working version.