Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

948 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

23 Experts available now in Live!

Get 1:1 Help Now