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.
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."