LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [bsdmake/pmake] Makefile Fun & Games (https://www.linuxquestions.org/questions/programming-9/%5Bbsdmake-pmake%5D-makefile-fun-and-games-289625/)

darklogik_org 02-13-2005 08:46 AM

[bsdmake/pmake] Makefile Fun & Games
 
Probably an easy one for those in the know, but I've let myself get behind on Makefile theory...

Code:

# $Id: Makefile,v 1.2 2005/02/13 14:23:33 markzero Exp $

CC = cc
CFLAGS = -pipe -O -W -Wall -pedantic -ansi
RM = /bin/rm -f

all: SWp_API_logerr SWp_new SWp_tsuite_tools SWp_logerr

SWp_API_logerr:        $(.TARGET).c $(.TARGET).h
SWp_new:              $(.TARGET).c $(.TARGET).h $(.TARGET).r SWp_API_logerr
SWp_tsuite_tools:      $(.TARGET).c $(.TARGET).h
SWp_logerr:            $(.TARGET).c $(.TARGET).h
SWp_example_object:    $(.TARGET).c $(.TARGET).h SWp_new

.c:
        $(CC) $(CFLAGS) -c $(.IMPSRC) -o $(.TARGET).o

clean:
        $(RM) *.o *.core

I want to add a new target - 'ExampleObjTest'. It's a single C source file that depends on SWP_new and SWp_example_object and should result in an executable.

What would be the tidiest and most concise way of adding ExampleObjTest given the implicit '.c' target?

Uh, perhaps not the best way to explain it.

darklogik_org 02-13-2005 12:03 PM

I can't believe that something so simple is so utterly impossible. This is driving me to complete frustration.

I have the unit-test ExampleTestObj.c, it relies on SWp_new.o and SWp_example_obj.o to compile and link. SWp_new.o relies on SWp_API_logerr.o to link sucessfully. I should not have to specify every single dependency for every single target as the list will get longer and longer and there appears to be no other way to do this.

darklogik_org 02-13-2005 01:34 PM

Took a different approach:

Code:

CC = cc
CFLAGS+= -O2 -pipe -W -Wall -pedantic -ansi
RM = /bin/rm -f
OBJS = SWp_API_logerr.o SWp_example_object.o SWp_logerr.o SWp_new.o \
      SWp_tsuite_tools.o
STATICLIB = libSWp.a
SHAREDLIB = libSWp.so
SHAREDFLAGS = -shared -Wl,-soname,libSWp.so

all: static shared

.c:
  ${CC} ${CFLAGS} -fpic -c ${.ALLSRC}

static: ${OBJS}
  ar rcv ${STATICLIB} ${OBJS}
  ranlib ${STATICLIB}

shared: ${OBJS}
  ${CC} ${SHAREDFLAGS} ${CFLAGS} ${OBJS} -o ${SHAREDLIB}

clean:
  ${RM} *.o *.core ${STATICLIB} ${SHAREDLIB}



All times are GMT -5. The time now is 10:21 PM.