Solved

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

Posted on 2014-10-10
6
314 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 32

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 32

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 32

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now