Solved

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

Posted on 2014-10-10
6
317 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
6 Comments
 
LVL 33

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 33

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 33

Accepted Solution

by:
sarabande earned 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
This is about my first experience with programming Arduino.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

776 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