How do I create a single Makefile with different compiler options for two sets of source code?

I have two groups of of C code and need to compile the first group with one set of compiler options and the second group with a different set of compiler options.  I am trying to do this with a single Makefile. The Makefile attached creates the dynamic library but uses the compiler options $CLFAGS0 for all source files instead of using $CFLAGS for the $SRCS set of source code and $CFLAGS0 for the $SRCS0 set of source code.

I am compiling with Solaris Studio 12.2 using dmake.

Makefile
wayneb01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sarabandeCommented:
you may try the following:

## Compile Source Files to Object Files ##
OBJSCO = dpslock.o dpsunlock.o find_files.o xusrcmd.o getusrname.o
$(OBJSCO):  $(OBJDIR)/%.o : %.c
	$(CC) $(CFLAGSO) -o $@ -c $< $(INCLDSC)

OBJSC = bridge.o bridge_update.o bridge_load.o bridge_loc.o bridge_store.o
$(OBJSC): $(OBJDIR)/%.o: %.c
	$(CC) $(CFLAGS) -o $@ $<

Open in new window


Sara
0
wayneb01Author Commented:
Sara,  I tried the change you listed, but dmake throws an error on $(OBJSCO):  $(OBJDIR)/%.o : %.c

dmake: Fatal error in reader: Makefile, line 37: Extra `:', `::', or `:=' on dependency line
0
sarabandeCommented:
yes, unfortunately dmake is not compatible to gnu make.

you may try conditional macro definition like that:

## Compiler Options ##
CFLAGSX=-xCC -O -m64 -xcode=pic32 -Bdynamic

CFLAGSO =-O -dalign -xstrconst -errtags=yes -v -W2,-AKNR_S \
          -Wc,-Qiselect-funcalign=32 -Wc,-Qgsched-trace_late=1 -Wc,-Qgsched-T5 \
          -D_REENTRANT -DSS_64BIT_SERVER -DBIT64 -DMACHINE64 -KPIC -I${ORACLE_HOME}/rdbms/public

## Source Files ##
SRCSC= \
	dpslock.c \
	dpsunlock.c \
	find_files.c \
	xusrcmd.c \
	getusrname.c

SRCSCO = \
	bridge.c \
	bridge_update.c \
	bridge_load.c \
	bridge_loc.c \
	bridge_store.c

## Compile Source Files to Object Files ##
OBJSCO=$(SRCSCO:%.c=$(OBJDIR)/%.o)
## redefine CFLAGS if target from OBJSCO list
$(OBJSCO): CFLAGS = $(CFLAGSO)

OBJSC=$(SRCSC:%.c=$(OBJDIR)/%.o)
## redefine CFLAGS if target from OBJSC list
$(OBJSC): CFLAGS = $(CFLAGSX)

$(OBJDIR)/%.o: %.c
	$(CC) $(CFLAGS) -o $@ -c $< 

Open in new window


see 'Conditional Macros' in http://docs.oracle.com/cd/E19253-01/816-5165/6mbb0m9l0/index.html

if that doesn't work i would use 2 makefiles.

Sara
0
wayneb01Author Commented:
I tried to the conditional macros, but received an error from dmake.  Following your recommendation of using two makefiles, I created three makefiles.  Two makefiles with different compiler options and one to build the library from the objects.  This was successful.

In one last attempt to use a single makefile, I created different directories for the object files which worked.  Objects from one set of source files are written to one directory and the other set of source files are written to a different directory.  The same makefile then makes a library from both sets of objects.
0
sarabandeCommented:
the directory solution is the best because it  handles the case at designed. the conditional stuff always fights with the fact that make is not a programming language and that it is extremely difficult to handle groups of files differently when they were located in the same folders.

Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.