1

I have to modify some very old source code. It comes with a very long Makefile and I'm not very familiar with Makefiles in general. It also relies on a precompiling step by an old Informix server.

I need to modify the Makefile so that the source code inside my_directory will compile by including the sources in common_src.

Here is the structure :

- common_src
- my_directory
   - Makefile

The .o files should be generated inside my_directory.

I have the following :

COMMONSRC=$(HOME)/common_src

ESQL=   esql
ESQLFLAGS=  -e

CFLAGS= -DGTKDVPT \
    -I$(INFORMIXDIR)/incl/esql \
    -I$(COMMONSRC)

OFILES= rwfich.o
HFILES= sqlheader.h

COMMON_HFILES=  $(HFILES:%.h=$(COMMONSRC)/%.h)

gcd:        bin/gcd


bin/gcd:    $(LIBGC) gcd.o $(LIBOUTILS)
            @echo -n "Link:     bin/gcd "
            @$(CC) $(CFLAGS) gcd.o $(LIBGC) \
            $(SQLLIBS) $(LNKOPT) -obin/gcd_lnk > gcdlnk.err 2>&1
            @touch bin/gcd
            @mv -f bin/gcd bin/oldgcd
            @mv -f bin/gcd_lnk bin/gcd
            @echo "Ok."

$(LIBGC):   $(RWFOBJ) 
    @echo -n "$(LIBGC)     :    "
    @rm -f $(LIBGC)
    @echo -n "Construction ...  "
    @ar rc $(LIBGC) 
    @echo "Ok."

$(RWFOBJ):  $(OBJDIR)/%.o : $(COMMONSRC)/%.ec $(COMMON_HFILES)
            @echo -n "$<     :  Precompilation  "
            @$(ESQL) $(ESQLFLAGS) $< > $*.err 2>&1
            @echo -n "Compilation  "
            @$(CC) $(CFLAGS) -c $*.c >> $*.err 2>&1
            @rm $*.c
            @echo "Ok."

When I run the Makefile, and it gets to $(RWFOBJ), the .err file output by the Informix recompilation step for rwfich.ec says : esqlc: "/home/my_directory/rwfich.ec", line 7: Error -33042: Cannot open input file 'sqlheader.h'. 1 error(s) found.

Does anyone have an idea what's wrong with this ? I have even tried hardcoding the .h file with its complete path:

$(RWFOBJ):  $(OBJDIR)/%.o : $(COMMONSRC)/%.ec $(HOME)/common_src/sqlheader.h

but no dice : I get the same error.

Thanks a lot to anyone who could point me in the right direction.

SofiaMNC
  • 11
  • 1
  • 5

2 Answers2

0

When asking for help please always include the make command you invoked and the error output you got, cut and pasted into your question (with proper formatting) rather than paraphrased. Even slight differences in the exact text of the error can make a big difference.

Also, your makefile is incomplete because you don't show us what the value of RWOBJ is, and you have a typo (you define COMMON_HFILES but you refer to $(COMMON_HFILE). Since make doesn't complain about this I assume the typo only exists here in your question not in your actual makefile (this another reason why cut and paste is better).

Also please include the operating system you're using and the version of make you're using.

In this case the error you're getting "Cannot open input file" is not coming from make, it's coming from your compiler. Make is able to find your header files just fine, but then it invokes the compiler and you haven't told the compiler where to find the header files.

You need to add the -I$(COMMONSRC) option to your compile line (assuming you're using a POSIX-ish compiler such as GCC or clang).

You haven't provided enough information about your complete makefile for us to advise you on where to put that option but see if there's a make variable containing other -I options etc.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Thank you for your reply. I've modified the question according to your suggestions. You're right, I should have provided more details. I have the -I$(COMMONSRC) flag, but the error happens at the precompiling step with the Informix server... – SofiaMNC Nov 18 '20 at 13:27
  • Well, you have to tell the "informix server" where to find the headers during the "precompiling step". Likely you have to add something to the `ESQLFLAGS` variable. If you don't know what you need to add, and the documentation for the Informix server precompiler doesn't tell you, then this is a question about Informix server precompilers, not about makefiles, so you should add the appropriate tags to your question and modify the summary to try to attract people with the right type of knowledge (e.g., this is not a "Makefile error")... which unfortunately is not me! :) – MadScientist Nov 18 '20 at 13:52
  • I see, yeah you're right. Thank you for taking the time in any case ! – SofiaMNC Nov 18 '20 at 13:54
0

I solved the problem by adding the $(CFLAGS) to the Informix precompiling line, like so: @$(ESQL) $(ESQLFLAGS) $(CFLAGS) $< > $*.err 2>&1, so the total target looks like:

$(RWFOBJ):  $(OBJDIR)/%.o : $(COMMONSRC)/%.ec $(COMMON_HFILES)
        @echo -n "$<     :  Precompilation  "
        @$(ESQL) $(ESQLFLAGS) $(CFLAGS) $< > $*.err 2>&1
        @echo -n "Compilation  "
        @$(CC) $(CFLAGS) -c $*.c >> $*.err 2>&1
        @rm $*.c
        @echo "Ok."
SofiaMNC
  • 11
  • 1
  • 5