-   Programming (
-   -   [bsdmake/pmake] Makefile Fun & Games (

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...


# $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

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

        $(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:


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 \
SHAREDFLAGS = -shared -Wl,-soname,

all: static shared

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

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

shared: ${OBJS}

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

All times are GMT -5. The time now is 08:06 AM.