Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2014-10-10
6
Medium Priority
?
350 Views
Last Modified: 2014-10-23
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
0
Comment
Question by:wayneb01
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:sarabande
ID: 40380478
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
 

Author Comment

by:wayneb01
ID: 40381213
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
 
LVL 35

Expert Comment

by:sarabande
ID: 40382013
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
 

Author Comment

by:wayneb01
ID: 40390749
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
 
LVL 35

Accepted Solution

by:
sarabande earned 1500 total points
ID: 40391765
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question