Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Mar 1998 14:34:31 -0500
From:      Brian Cully <shmit@kublai.com>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   Objective C rules for /usr/share/mk
Message-ID:  <19980330143431.00467@kublai.com>

next in thread | raw e-mail | index | archive | help

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii

I've been tweaking around in /usr/share/mk that I might make Objective
C programs with BSD make.

The way things stand now, I have to add the following rules whenever
I want to put together an ObjC program:

CFLAGS=	-I/usr/include/objc -Wno-import
LDADD=	-lobjc

.SUFFIXES: .m
.m.o:
	$(CC) $(CFLAGS) -c $<

I'd like to be able to strip those out entirely. I've managed to do
so by some makefile hacking in share/mk, but I'm not sure if it's the
right approach.

The way things stand now, it looks as though the makefiles depend on
some hard-coded behaviour in `make' and `cc'. Namely that `make' knows
the default for compiling object files of various types, and that
`cc' knows the appropriate include paths and links with the appropriate
library at the linker step.

The only place this isn't the case is in sys.mk, and I feel as though
my patches will work just fine for that.

One of the obvious problems with the patches I've made is that I've
put the rules for .m.o in bsd.prog.mk, which doesn't seem appropriate,
as I feel it's applicable for bsd.lib.mk as well, and there ought to
be a place where I can define it once and not have to worry about it
again.

I've also defined the following variables:
OBJC:		the Objective C compiler
OBJCINCLUDES:	the include path for Objective C headers
OBJCLIBS:	libraries with which to link.

These are all at the top of bsd.prog.mk, and once again, I don't feel
as though they belong there.

The patches are attached.

-- 
Brian Cully						<shmit@erols.com>
``And when one of our comrades was taken prisoner, blindfolded, hung
  upside-down, shot, and burned, we thought to ourselves, `These are the
  best experiences of our lives''' -Pathology (Joe Frank, Somewhere Out There)

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Description: Patches to make Objective C work.
Content-Disposition: attachment; filename="mk.patches"

diff -cr mk/bsd.dep.mk mk.new/bsd.dep.mk
*** mk/bsd.dep.mk	Mon Mar 30 14:15:48 1998
--- mk.new/bsd.dep.mk	Mon Mar 30 14:14:53 1998
***************
*** 55,60 ****
--- 55,65 ----
  	    ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
  	    ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}
  .endif
+ .if ${SRCS:M*.m} != ""
+ 	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
+ 	   ${OBJCCFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
+ 	   ${OBJCFLAGS:M-Wno-import*} ${.ALLSRC:M*.m}
+ .endif
  .if target(_EXTRADEPEND)
  	cd ${.CURDIR}; ${MAKE} _EXTRADEPEND
  .endif
diff -cr mk/bsd.libnames.mk mk.new/bsd.libnames.mk
*** mk/bsd.libnames.mk	Mon Mar 30 14:15:48 1998
--- mk.new/bsd.libnames.mk	Mon Mar 30 14:14:53 1998
***************
*** 43,48 ****
--- 43,49 ----
  LIBMYTINFO?=	${DESTDIR}/usr/lib/libmytinfo.a
  LIBNCURSES?=	${DESTDIR}/usr/lib/libncurses.a
  LIBOPIE?=	${DESTDIR}/usr/lib/libopie.a
+ LIBOBJC?=	${DESTDIR}/usr/lib/libobjc.a
  LIBPC?=		${DESTDIR}/usr/lib/libpc.a	# XXX doesn't exist
  LIBPCAP?=	${DESTDIR}/usr/lib/libpcap.a
  LIBPLOT?=	${DESTDIR}/usr/lib/libplot.a	# XXX doesn't exist
diff -cr mk/bsd.prog.mk mk.new/bsd.prog.mk
*** mk/bsd.prog.mk	Mon Mar 30 14:15:48 1998
--- mk.new/bsd.prog.mk	Mon Mar 30 14:29:26 1998
***************
*** 8,19 ****
  # Default executable format
  BINFORMAT?=	aout
  
! .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
  
  CFLAGS+=${COPTS} ${DEBUG_FLAGS}
  .if defined(DESTDIR)
  CFLAGS+= -I${DESTDIR}/usr/include
  CXXINCLUDES+= -I${DESTDIR}/usr/include/g++
  .endif
  
  .if !defined(DEBUG_FLAGS)
--- 8,26 ----
  # Default executable format
  BINFORMAT?=	aout
  
! .SUFFIXES: .out .o .c .cc .cxx .m .C .y .l .s .S
  
+ OBJC?=	cc
  CFLAGS+=${COPTS} ${DEBUG_FLAGS}
+ OBJCFLAGS+=${COPTS} ${DEBUG_FLAGS} -Wno-import
+ OBJCLIBS+=-lobjc
+ CXXFLAGS+=${COPTS} ${DEBUG_FLAGS}
  .if defined(DESTDIR)
  CFLAGS+= -I${DESTDIR}/usr/include
  CXXINCLUDES+= -I${DESTDIR}/usr/include/g++
+ OBJCINCLUDES+= -I${DESTDIR}/usr/include/objc
+ .else
+ OBJCINCLUDES+= -I/usr/include/objc
  .endif
  
  .if !defined(DEBUG_FLAGS)
***************
*** 28,33 ****
--- 35,47 ----
  .if defined(SRCS)
  
  OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
+ 
+ .if ${SRCS:M*.m} != ""
+ .m.o:
+ 	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC}
+ 
+ LDADD+=	${OBJCLIBS}
+ .endif
  
  ${PROG}: ${OBJS}
  	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
diff -cr mk/sys.mk mk.new/sys.mk
*** mk/sys.mk	Mon Mar 30 14:15:48 1998
--- mk.new/sys.mk	Mon Mar 30 14:14:53 1998
***************
*** 15,21 ****
  .if defined(%POSIX)
  .SUFFIXES:	.o .c .y .l .a .sh .f
  .else
! .SUFFIXES:	.out .a .ln .o .c .cc .cxx .C .F .f .e .r .y .l .S .s .cl .p .h .sh
  .endif
  
  .LIBS:		.a
--- 15,21 ----
  .if defined(%POSIX)
  .SUFFIXES:	.o .c .y .l .a .sh .f
  .else
! .SUFFIXES:	.out .a .ln .o .c .cc .cxx .C .m .F .f .e .r .y .l .S .s .cl .p .h .sh
  .endif
  
  .LIBS:		.a
***************
*** 43,48 ****
--- 43,51 ----
  CXX		?=	c++
  CXXFLAGS	?=	${CXXINCLUDES} ${CFLAGS}
  
+ OBJC		?=	cc
+ OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS}
+ 
  CPP		?=	cpp
  
  .if ${.MAKEFLAGS:M-s} == ""
***************
*** 184,189 ****
--- 187,195 ----
  
  .cc.o .cxx.o .C.o:
  	${CXX} ${CXXFLAGS} -c ${.IMPSRC}
+ 
+ .m.o:
+ 	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC}
  
  .p.o:
  	${PC} ${PFLAGS} -c ${.IMPSRC}

--jRHKVT23PllUwdXP--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980330143431.00467>