From owner-freebsd-hackers@FreeBSD.ORG Fri Jul 2 22:53:24 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5D9A41065675 for ; Fri, 2 Jul 2010 22:53:24 +0000 (UTC) (envelope-from herron.philip@googlemail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id E35888FC0A for ; Fri, 2 Jul 2010 22:53:23 +0000 (UTC) Received: by wwd20 with SMTP id 20so184945wwd.31 for ; Fri, 02 Jul 2010 15:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=G47u/+R7EXmMXVdNgmGwtJCfesE73jshdff62FWKmjs=; b=O4ROv+6wWqSXJ6i6aRCQTmqIlJ0InAROGmsJDAiVdZ4PCOoBBe24yQfsWueBpjqnDV SueLotNtBkQs3YCvcIjg8UFMk3YueJ/bJWRH5JqTmHMc7xvQLbJdyDNbd5UqfJ3Bu2yF lU4OWu2AbyS9ALsPEYLLR6aiLO4WlIUZUrmms= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=bgeL8M/ZzlvWUzi4gz3fNG7XX4ELpDd/jcx13xnLFjHum3qQMtIkRwrVO+fx+Xkhgb XWJ/QWMNo6VWoUkoj7V6T65QY3YMSn58BIjF5wu79QB6Iq7z6sUqVg/YxBc4fDc/K85o zveUfFnDZ/aIg2aMonq3NxFCK4KL+USDmFO+Q= MIME-Version: 1.0 Received: by 10.227.151.138 with SMTP id c10mr866360wbw.46.1278111197573; Fri, 02 Jul 2010 15:53:17 -0700 (PDT) Sender: herron.philip@googlemail.com Received: by 10.216.13.9 with HTTP; Fri, 2 Jul 2010 15:53:17 -0700 (PDT) In-Reply-To: References: Date: Fri, 2 Jul 2010 23:53:17 +0100 X-Google-Sender-Auth: 8Jblp_n96r3N1R9pJchPsEKV7XE Message-ID: From: Philip Herron To: Matthew Fleming Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: Using lex in a shared library X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Jul 2010 22:53:24 -0000 On 2 July 2010 23:31, Matthew Fleming wrote: > On Fri, Jul 2, 2010 at 2:54 PM, Philip Herron wrot= e: >> On 2 July 2010 22:51, Matthew Fleming wrote: >>> I have the following Makefile for a shared library at $work: >>> >>> ISI_TOP=3D =A0 =A0 =A0 =A0../.. >>> >>> LIB=3D =A0 =A0 =A0 =A0 =A0 =A0isi_date >>> SHLIB_MAJOR=3D =A0 =A01 >>> SHLIB_MINOR=3D =A0 =A00 >>> SRCS=3D =A0 =A0 =A0 =A0 =A0 date.c date_parser.new.c lex.yy.c >>> INCS=3D =A0 =A0 =A0 =A0 =A0 date.h >>> INCLUDEDIR=3D =A0 =A0 /usr/include/isi_date >>> >>> YFLAGS+=3D =A0 =A0 =A0 =A0-vt >>> FLEX=3D =A0 =A0 =A0 =A0 =A0 /usr/bin/flex >>> LDADD=3D =A0 =A0 =A0 =A0 =A0-ll >>> >>> CLEANFILES+=3D =A0 =A0date_parser.new.c y.tab.h y.tab.c lex.yy.c y.outp= ut \ >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0check_date.log test >>> >>> lex.yy.c: date_lexer.new.l >>> =A0 =A0 =A0 =A0${FLEX} $> >>> >>> CFLAGS+=3D =A0 =A0 =A0 =A0-I${.CURDIR} >>> #CFLAGS+=3D =A0 =A0 =A0 -g >>> >>> .include "${ISI_TOP}/isi.lib.mk" >>> >>> >>> >>> This builds fine as on i386. =A0I'm trying to get all our user-space to >>> be 64-bit clean, and I run into an error when building on amd64: >>> >>> /data/sb/BR_MDF_64CLEAN/obj/data/sb/BR_MDF_64CLEAN/src/tmp/usr/bin/ld: >>> /data/sb/BR_MDF_64CLEAN/obj/data/sb/BR_MDF_64CLEAN/src/tmp/usr/lib/libl= .a(libyywrap.o): >>> relocation R_X86_64_32 can not be used when making a shared object; >>> recompile with -fPIC >>> /data/sb/BR_MDF_64CLEAN/obj/data/sb/BR_MDF_64CLEAN/src/tmp/usr/lib/libl= .a: >>> could not read symbols: Bad value >>> >>> The following diff makes the compile work, but I have no idea (yet) >>> whether this will run, if it's the right solution, etc. >>> >>> >>> Index: usr.bin/lex/lib/Makefile >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >>> --- usr.bin/lex/lib/Makefile =A0 =A0(revision 153343) >>> +++ usr.bin/lex/lib/Makefile =A0 =A0(working copy) >>> @@ -4,11 +4,16 @@ >>> >>> =A0LIB=3D =A0 =A0ln >>> =A0SRCS=3D =A0 libmain.c libyywrap.c >>> -NO_PIC=3D >>> +#NO_PIC=3D >>> >>> +SHLIB_MAJOR=3D =A0 1 >>> +SHLIB_MINOR=3D =A0 0 >>> + >>> =A0.if ${MK_INSTALLLIB} !=3D "no" >>> =A0LINKS=3D =A0${LIBDIR}/libln.a ${LIBDIR}/libl.a >>> =A0LINKS+=3D =A0 =A0 =A0 =A0${LIBDIR}/libln.a ${LIBDIR}/libfl.a >>> +LINKS+=3D =A0 =A0 =A0 =A0${LIBDIR}/libln.so ${LIBDIR}/libl.so >>> +LINKS+=3D =A0 =A0 =A0 =A0${LIBDIR}/libln${LIB_SUFFIX}.so ${LIBDIR}/lib= l${LIB_SUFFIX}.so >>> =A0.endif >>> >>> =A0.if ${MK_PROFILE} !=3D "no" >> >> Although maybe not helpful but have you considered using >> automake/libtool instead makes it so much simpler in my opinion. > > Instead of... ? =A0Instead of this makefile? > > Thanks, > matthew > Yeah to create your self a shared library using automake: $ rm Makefile $ cat >> Makefile.am <.la libcrules_la_LDFLAGS =3D -release 0.5.0 libcrules_la_SOURCES =3D ss_parser.y \ ss_lexical.l \ bb_backend.c \ ... EOF Automake will auto-handle Lex and Yacc files too. And is extremely portable= . $ automake --gnu --add-missing --copy --force This will generate you all the Makefie.in files recursively over your work dir. When building these Makefile.in you only need do it once really, unless you change your makefile.am files. The makefiles.in are designed to be portable. All they need is some configuration though autoconf to tell it what compiler to use etc. --Phil