From owner-freebsd-questions@FreeBSD.ORG Wed Dec 30 09:33:02 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0D76F106566B for ; Wed, 30 Dec 2009 09:33:02 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from smtp.infracaninophile.co.uk (gate6.infracaninophile.co.uk [IPv6:2001:8b0:151:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 60F9E8FC18 for ; Wed, 30 Dec 2009 09:33:01 +0000 (UTC) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost [IPv6:::1]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.3/8.14.3) with ESMTP id nBU9Wttg085900; Wed, 30 Dec 2009 09:32:56 GMT (envelope-from m.seaman@infracaninophile.co.uk) X-DKIM: Sendmail DKIM Filter v2.8.3 smtp.infracaninophile.co.uk nBU9Wttg085900 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infracaninophile.co.uk; s=200708; t=1262165576; bh=y1oWyx7k3zfq4MuOzj/gvbwE28QrBNLuW4x2+xZ9B/Y=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Cc:Content-Type:Date:From:In-Reply-To: Message-ID:Mime-Version:References:To; z=Message-ID:=20<4B3B1E41.4010104@infracaninophile.co.uk>|Date:=20W ed,=2030=20Dec=202009=2009:32:49=20+0000|From:=20Matthew=20Seaman= 20|Organization:=20Infracaninophi le|User-Agent:=20Thunderbird=202.0.0.23=20(X11/20091129)|MIME-Vers ion:=201.0|To:=20Oliver=20Mahmoudi=20|CC :=20"freebsd-questions@FreeBSD.org"=20|Subject:=20Re:=20how=20does=20the=20C=20pre-processor=20interf ace=20with=20make?|References:=20<6b4b2d2c0912292317h7c4d9bbfo196d cf48396e0afa@mail.gmail.com>|In-Reply-To:=20<6b4b2d2c0912292317h7c 4d9bbfo196dcf48396e0afa@mail.gmail.com>|X-Enigmail-Version:=200.95 .6|Content-Type:=20multipart/signed=3B=20micalg=3Dpgp-sha256=3B=0D =0A=20protocol=3D"application/pgp-signature"=3B=0D=0A=20boundary=3 D"------------enigC23A6DBAF5F7C2611DC5979A"; b=Sr1BlWMHRu2JUDYlN1yM7x3tEi87kbw6xs7l5Pn8VcsOeTXO4SqVmQrgG0sSajOWl jHiK/nlWAM4a0B798J5I/ECzelsFGycGpe2+S/wASKt9ycgx6aciB+YokMIReXVVoJ jWj4f4Ih3PS+woGhAEoIgJgUZmiYAJ1ow8oKELYc= X-Authentication-Warning: happy-idiot-talk.infracaninophile.co.uk: Host localhost [IPv6:::1] claimed to be happy-idiot-talk.infracaninophile.co.uk Message-ID: <4B3B1E41.4010104@infracaninophile.co.uk> Date: Wed, 30 Dec 2009 09:32:49 +0000 From: Matthew Seaman Organization: Infracaninophile User-Agent: Thunderbird 2.0.0.23 (X11/20091129) MIME-Version: 1.0 To: Oliver Mahmoudi References: <6b4b2d2c0912292317h7c4d9bbfo196dcf48396e0afa@mail.gmail.com> In-Reply-To: <6b4b2d2c0912292317h7c4d9bbfo196dcf48396e0afa@mail.gmail.com> X-Enigmail-Version: 0.95.6 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigC23A6DBAF5F7C2611DC5979A" X-Virus-Scanned: clamav-milter 0.95.3 at happy-idiot-talk.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VERIFIED,NO_RELAYS autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on happy-idiot-talk.infracaninophile.co.uk Cc: "freebsd-questions@FreeBSD.org" Subject: Re: how does the C pre-processor interface with make? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Dec 2009 09:33:02 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC23A6DBAF5F7C2611DC5979A Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Oliver Mahmoudi wrote: > Hey folks, >=20 > I was wondering how the C pre-processor interfaces with make. Let's sup= pose > that I have a little C program, something along the lines of: >=20 > #include >=20 > int > main() > { > #ifdef FOO > fprintf(stdout, "Hi, my name is foo.\n"); > #endif >=20 > #ifdef BAR > fprintf(stdout, "Hi, my name is bar.\n"); > #endif >=20 > fprintf(stdout, "I am always here.\n"); >=20 > return(1-1); > } >=20 > It is easy to control the pre-processor in the above code by defining t= he > respective terms or leaving them out, however, > I am trying to control the conditionals from out of a makefile. >=20 > This is essentially the way in which the kernel sources are compiled. >=20 > Any suggestions? Yes. You have to define your FOO and BAR variables on the cc(1) command line using the -D flag, based on the equivalent settings in make. Suppos= ing your little program is held in a file wibble.c, then in your Makefile you= 'ld need something like this to compile and link it into a program called wib= ble: =2Eif defined(FOO) CFLAGS+=3D -DFOO =2Eendif =2Eif defined(BAR) CFLAGS+=3D -DBAR =2Eendif wibble: wibble.c ${CC} ${CFLAGS} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} Then you'ld invoke make(1) as: % make -DFOO -DBAR wibble or define FOO and BAR in the shell environment, which make(1) should pick= up. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW --------------enigC23A6DBAF5F7C2611DC5979A Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREIAAYFAks7HkcACgkQ8Mjk52CukIxEGQCdFTuhkHJlkEM91SmWsSW3ZHcd 9mgAn2W2aiD1tmbOzJooj8C4v2vyZ5/5 =7JiM -----END PGP SIGNATURE----- --------------enigC23A6DBAF5F7C2611DC5979A--