From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 25 15:06:28 2008 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 2013C106564A for ; Tue, 25 Nov 2008 15:06:28 +0000 (UTC) (envelope-from laladelausanne@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.30]) by mx1.freebsd.org (Postfix) with ESMTP id CC07A8FC18 for ; Tue, 25 Nov 2008 15:06:27 +0000 (UTC) (envelope-from laladelausanne@gmail.com) Received: by yw-out-2324.google.com with SMTP id 9so1069918ywe.13 for ; Tue, 25 Nov 2008 07:06:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :content-type:content-transfer-encoding:mime-version:subject:date :x-mailer; bh=TCEZ6Br7skL0YhW6KCuMt89R6begcPBEtYQofxCmzco=; b=B28d/aWgEAn+VVP9kOhpxCVycIFlpztDbsakjKzYKA6xEv9J7xy0saGffxHoXUb3s/ ZEFz+Dl7zLKY6MNJ3IHTPpO2e9VSRIqL+DfDFACVzWq5xIrkboVT1ndylm4Rjwv02raA /kq5uwCAKlevJ4fQOyZuoPM3fu8LrvJm91akU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:content-type:content-transfer-encoding :mime-version:subject:date:x-mailer; b=s4ZEVshRWV8KoI9rwfjLAKUcXvUfn34LavJRWSJa2N2J6MDvvOl2WsUiumWmk6q1Lv qHGt9O4PEI1dvczxmY+Xf2RgvI/fuEB/mjacvzU2A1vbqZVPEF0AR4d8UrOTFpjZKn5v FVoOjSbS7pqtOvT7qYPgW3BVnk1khjdwEDvdM= Received: by 10.86.62.3 with SMTP id k3mr3006157fga.46.1227622856743; Tue, 25 Nov 2008 06:20:56 -0800 (PST) Received: from nslpc5.epfl.ch (nslpc5.epfl.ch [128.178.149.20]) by mx.google.com with ESMTPS id e11sm7457220fga.9.2008.11.25.06.20.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 25 Nov 2008 06:20:55 -0800 (PST) Message-Id: <711D7381-D852-4B6B-991A-84BA6DEFB679@gmail.com> From: =?UTF-8?Q?Nikola_Kne=C5=BEevi=C4=87?= To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Date: Tue, 25 Nov 2008 15:20:54 +0100 X-Mailer: Apple Mail (2.929.2) Subject: How to build kernel module spread on subdirectories? 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: Tue, 25 Nov 2008 15:06:28 -0000 Hi, I'm playing with the Click Modular router on my FreeBSD box. Out of curiosity, I decided to switch its GNU makefile to BSD style. I managed to do it, but I would like to polish it a bit more (and learn some things along). Old GNUmakefile relies heavily on OBJS and *_OBJS, as it fills these variables. I would like to switch to using SRCS. I managed to do it partially, for the files which are in the ${.CURDIR}. Click has a certain dir hierarchy of elements. First, it builds its elements, where each group of elements is in a different directory. Then it places all generated .o files in ${.CURDIR}. Finally, it links the whole shebang. Element building is done in another Makefile, which is generated by a script. (Main) GNUmakefile calls this script, then it includes that makefile via '-include'. The script traverses the dir hierarchy, and based on some variables, creates a Makefile which outlines like this: # subdir0 ELEMENT_OBJS__x= \ file0.o \ file1.o #subdir1 ELEMENT_OBJS__y= \ file2.o \ file3.o \ ... ELEMENT_OBJS= \ $(ELEMENT_OBJS__x) \ $(ELEMENT_OBJS__y) $(ELEMENT_OBJS__x): %.o: subdir0/%.cc $(call cxxcompile,-c $< -o $@,CXX) $(ELEMENT_OBJS__y): %.o: subdir1/%.cc $(call cxxcompile,-c $< -o $@,CXX) I'm interested in how can I transfer this into BSD-style makefile? I tried to move from OBJS into SRCS (main BSDmakefile now has: SRCS+=$ (ELEMENT_SRCS)), by using something like: # subdir0 ELEMENT_SRCS__x =\ subdir1/file0.cc \ subdir1/file1.cc ... But this fails during the linking phase, because the linker is called with subdir1/file0.o, instead of just file0.o. To make something clear, I didn't just rewrite the GNUmakefile to BSDmakefile, I also followed some of the logic used to build kernel modules. I'm including bsd.kmod.ko, list sources in SRCS, don't have any explicit rule to build .o out of .cc/.c. There is no all: target, as well. Thanks, Nikola