* [PATCH 0/2] btrfs-progs: standardize utility filenames and add default rules to Makefile
@ 2013-04-21 22:10 Eric Sandeen
2013-04-21 22:22 ` [PATCH 2/2] btrfs-progs: Add " Eric Sandeen
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Eric Sandeen @ 2013-04-21 22:10 UTC (permalink / raw)
To: linux-btrfs
2 patches here.
The first renames the single .c files which are built into btrfs-$FOO
commands - previously we built i.e. btrfs-calc-size from calc-size.c
IMHO this helps separate out which files are main command-type
files, and which are not. (Eventually I hope to move things
into subdirs to organize a bit more).
Then, after renaming i.e. calc-size.c to btrfs-calc-size.c we can
write a simpler default rule for these utilities (patch 2/2).
The default static rule is handy because it'll automatically build
i.e. "make btrfs-image.static" or "make btrfs-calc-size.static"
if you need them.
I think this is a net win, with a bit less Makefile code
duplication, but if people don't like it, no big deal. I was hoping
to clean up & re-organize the userspace build a little, and this
seems like a decent first step along the way.
Comments welcome, especially from people who are better at Make than
I am. ;) And if this is two clever by half I'm not wedded to it.
-Eric
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] btrfs-progs: Add default rules to Makefile
2013-04-21 22:10 [PATCH 0/2] btrfs-progs: standardize utility filenames and add default rules to Makefile Eric Sandeen
@ 2013-04-21 22:22 ` Eric Sandeen
2013-04-24 12:43 ` David Sterba
2013-04-23 16:09 ` [PATCH 0/2] btrfs-progs: standardize utility filenames and add " David Sterba
2013-04-23 20:57 ` [PATCH 1/2 (resend)] btrfs-progs: standardize tool source filenames Eric Sandeen
2 siblings, 1 reply; 7+ messages in thread
From: Eric Sandeen @ 2013-04-21 22:22 UTC (permalink / raw)
To: linux-btrfs
Add a default rule for any btrfs-$FOO or btrfs-$FOO.static
target, allowing it to be built from btrfs-$FOO.c along with
all the normal userspace objects.
This gets rid of a lot of the cut and pasted rules for
each individual command, and as an added bonus makes it
easy to build any btrfs-$FOO statically as well, i.e.
# make btrfs-convert.static
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
Makefile | 79 ++++++++++++++++++++-------------------------------------------
1 file changed, 26 insertions(+), 53 deletions(-)
diff --git a/Makefile b/Makefile
index 10f5fe5..86d2c93 100644
--- a/Makefile
+++ b/Makefile
@@ -105,6 +105,32 @@ $(lib_links):
$(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so.0
$(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so
+# external libs required by various binaries; for btrfs-foo,
+# specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
+btrfs_convert_libs = -lext2fs -lcom_err
+btrfs_image_libs = -lpthread
+btrfs_fragment_libs = -lgd -lpng -ljpeg -lfreetype
+
+# keep intermediate files from the below implicit rules around
+.PRECIOUS: $(addsuffix .o,$(progs))
+
+# Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
+# The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
+# turns them into a list of libraries to link against if they exist
+#
+# For static variants, use an extra $(subst) to get rid of the ".static"
+# from the target name before translating to list of libs
+
+btrfs-%.static: version.h $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
+ @echo " [LD] $@"
+ $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
+ $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS) \
+ $($(subst -,_,$(subst .static,,$@)-libs))
+
+btrfs-%: version.h $(objects) $(libs) btrfs-%.o
+ @echo " [LD] $@"
+ $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
+
btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
@@ -115,19 +141,6 @@ btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objec
$(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
$(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
-btrfs-calc-size: $(objects) $(libs) btrfs-calc-size.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-calc-size btrfs-calc-size.o $(objects) $(LDFLAGS) $(LIBS)
-
-btrfs-find-root: $(objects) $(libs) btrfs-find-root.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-find-root btrfs-find-root.o $(objects) $(LDFLAGS) $(LIBS)
-
-btrfs-find-root.static: $(static_objects) btrfs-find-root.static.o $(static_libbtrfs_objects)
- @echo " [LD] $@"
- $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs-find-root.static btrfs-find-root.static.o $(static_objects) \
- $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
-
# For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
btrfsck: btrfs
@echo " [LN] $@"
@@ -142,42 +155,10 @@ mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
$(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
$(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
-btrfs-debug-tree: $(objects) $(libs) btrfs-debug-tree.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) btrfs-debug-tree.o $(LDFLAGS) $(LIBS)
-
-btrfs-zero-log: $(objects) $(libs) btrfs-zero-log.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o $(LDFLAGS) $(LIBS)
-
-btrfs-show-super: $(objects) $(libs) btrfs-show-super.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-show-super $(objects) btrfs-show-super.o $(LDFLAGS) $(LIBS)
-
-btrfs-select-super: $(objects) $(libs) btrfs-select-super.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-select-super $(objects) btrfs-select-super.o $(LDFLAGS) $(LIBS)
-
btrfstune: $(objects) $(libs) btrfstune.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
-btrfs-map-logical: $(objects) $(libs) btrfs-map-logical.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS)
-
-btrfs-corrupt-block: $(objects) $(libs) btrfs-corrupt-block.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-corrupt-block $(objects) btrfs-corrupt-block.o $(LDFLAGS) $(LIBS)
-
-btrfs-image: $(objects) $(libs) btrfs-image.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS)
-
-btrfs-crc: btrfs-crc.o $(libs)
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-crc btrfs-crc.o $(LDFLAGS) $(LIBS)
-
dir-test: $(objects) $(libs) dir-test.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
@@ -186,14 +167,6 @@ quick-test: $(objects) $(libs) quick-test.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
-btrfs-convert: $(objects) $(libs) btrfs-convert.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-convert $(objects) btrfs-convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
-
-btrfs-fragments: $(objects) $(libs) btrfs-fragments.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-fragments $(objects) btrfs-fragments.o $(LDFLAGS) $(LIBS) -lgd -lpng -ljpeg -lfreetype
-
ioctl-test: $(objects) $(libs) ioctl-test.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] btrfs-progs: standardize utility filenames and add default rules to Makefile
2013-04-21 22:10 [PATCH 0/2] btrfs-progs: standardize utility filenames and add default rules to Makefile Eric Sandeen
2013-04-21 22:22 ` [PATCH 2/2] btrfs-progs: Add " Eric Sandeen
@ 2013-04-23 16:09 ` David Sterba
2013-04-23 16:48 ` Eric Sandeen
2013-04-23 20:57 ` [PATCH 1/2 (resend)] btrfs-progs: standardize tool source filenames Eric Sandeen
2 siblings, 1 reply; 7+ messages in thread
From: David Sterba @ 2013-04-23 16:09 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-btrfs
On Sun, Apr 21, 2013 at 05:10:44PM -0500, Eric Sandeen wrote:
> 2 patches here.
I see only
[PATCH 2/2] btrfs-progs: Add default rules to Makefile
in my mbox that's threaded under the 0/2 cover mail.
> I think this is a net win, with a bit less Makefile code
> duplication, but if people don't like it, no big deal. I was hoping
> to clean up & re-organize the userspace build a little, and this
> seems like a decent first step along the way.
Looks ok to me, the rule duplication was obvious and asking for a
cleanup.
david
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] btrfs-progs: standardize utility filenames and add default rules to Makefile
2013-04-23 16:09 ` [PATCH 0/2] btrfs-progs: standardize utility filenames and add " David Sterba
@ 2013-04-23 16:48 ` Eric Sandeen
0 siblings, 0 replies; 7+ messages in thread
From: Eric Sandeen @ 2013-04-23 16:48 UTC (permalink / raw)
To: dsterba@suse.cz; +Cc: Eric Sandeen, linux-btrfs
On Apr 23, 2013, at 11:09 AM, David Sterba <dsterba@suse.cz> wrote:
> On Sun, Apr 21, 2013 at 05:10:44PM -0500, Eric Sandeen wrote:
>> 2 patches here.
>
> I see only
>
> [PATCH 2/2] btrfs-progs: Add default rules to Makefile
>
> in my mbox that's threaded under the 0/2 cover mail.
>
I must have run into a size limit on the server... Let me double check on the rename behavior which should make it smaller, I think?
Eric
>> I think this is a net win, with a bit less Makefile code
>> duplication, but if people don't like it, no big deal. I was hoping
>> to clean up & re-organize the userspace build a little, and this
>> seems like a decent first step along the way.
>
> Looks ok to me, the rule duplication was obvious and asking for a
> cleanup.
>
> david
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2 (resend)] btrfs-progs: standardize tool source filenames
2013-04-21 22:10 [PATCH 0/2] btrfs-progs: standardize utility filenames and add default rules to Makefile Eric Sandeen
2013-04-21 22:22 ` [PATCH 2/2] btrfs-progs: Add " Eric Sandeen
2013-04-23 16:09 ` [PATCH 0/2] btrfs-progs: standardize utility filenames and add " David Sterba
@ 2013-04-23 20:57 ` Eric Sandeen
2013-04-24 12:21 ` David Sterba
2 siblings, 1 reply; 7+ messages in thread
From: Eric Sandeen @ 2013-04-23 20:57 UTC (permalink / raw)
To: linux-btrfs
For any btrfs-$FOO executable, rename the main source file from
$FOO.c to to btrfs-$FOO.c
This makes it slightly more obvious what's building what,
and allows us to write a default rule in the Makefile for
these tools.
(also add btrfs-calc-size to the list of objects to remove
on make clean)
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
vger ate my giant rename-files patch; here's the makefile bit, and
hopefully the rename-diffs at the end are something that git
knows how to apply? TBH I've never tried that before.
-Eric
diff --git a/Makefile b/Makefile
index db70981..10f5fe5 100644
--- a/Makefile
+++ b/Makefile
@@ -115,17 +115,17 @@ btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objec
$(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
$(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
-calc-size: $(objects) $(libs) calc-size.o
+btrfs-calc-size: $(objects) $(libs) btrfs-calc-size.o
@echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o calc-size calc-size.o $(objects) $(LDFLAGS) $(LIBS)
+ $(Q)$(CC) $(CFLAGS) -o btrfs-calc-size btrfs-calc-size.o $(objects) $(LDFLAGS) $(LIBS)
-btrfs-find-root: $(objects) $(libs) find-root.o
+btrfs-find-root: $(objects) $(libs) btrfs-find-root.o
@echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-find-root find-root.o $(objects) $(LDFLAGS) $(LIBS)
+ $(Q)$(CC) $(CFLAGS) -o btrfs-find-root btrfs-find-root.o $(objects) $(LDFLAGS) $(LIBS)
-btrfs-find-root.static: $(static_objects) find-root.static.o $(static_libbtrfs_objects)
+btrfs-find-root.static: $(static_objects) btrfs-find-root.static.o $(static_libbtrfs_objects)
@echo " [LD] $@"
- $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs-find-root.static find-root.static.o $(static_objects) \
+ $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs-find-root.static btrfs-find-root.static.o $(static_objects) \
$(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
# For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
@@ -142,9 +142,9 @@ mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
$(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
$(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
-btrfs-debug-tree: $(objects) $(libs) debug-tree.o
+btrfs-debug-tree: $(objects) $(libs) btrfs-debug-tree.o
@echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS)
+ $(Q)$(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) btrfs-debug-tree.o $(LDFLAGS) $(LIBS)
btrfs-zero-log: $(objects) $(libs) btrfs-zero-log.o
@echo " [LD] $@"
@@ -186,13 +186,13 @@ quick-test: $(objects) $(libs) quick-test.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
-btrfs-convert: $(objects) $(libs) convert.o
+btrfs-convert: $(objects) $(libs) btrfs-convert.o
@echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
+ $(Q)$(CC) $(CFLAGS) -o btrfs-convert $(objects) btrfs-convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
-btrfs-fragments: $(objects) $(libs) fragments.o
+btrfs-fragments: $(objects) $(libs) btrfs-fragments.o
@echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o btrfs-fragments $(objects) fragments.o $(LDFLAGS) $(LIBS) -lgd -lpng -ljpeg -lfreetype
+ $(Q)$(CC) $(CFLAGS) -o btrfs-fragments $(objects) btrfs-fragments.o $(LDFLAGS) $(LIBS) -lgd -lpng -ljpeg -lfreetype
ioctl-test: $(objects) $(libs) ioctl-test.o
@echo " [LD] $@"
@@ -212,7 +212,7 @@ clean :
@echo "Cleaning"
$(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \
btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
- btrfs.static mkfs.btrfs.static \
+ btrfs.static mkfs.btrfs.static btrfs-calc-size \
version.h \
$(libs) $(lib_links)
$(Q)$(MAKE) $(MAKEOPTS) -C man $@
diff --git a/calc-size.c b/btrfs-calc-size.c
similarity index 100%
rename from calc-size.c
rename to btrfs-calc-size.c
diff --git a/convert.c b/btrfs-convert.c
similarity index 100%
rename from convert.c
rename to btrfs-convert.c
diff --git a/debug-tree.c b/btrfs-debug-tree.c
similarity index 100%
rename from debug-tree.c
rename to btrfs-debug-tree.c
diff --git a/find-root.c b/btrfs-find-root.c
similarity index 100%
rename from find-root.c
rename to btrfs-find-root.c
diff --git a/fragments.c b/btrfs-fragments.c
similarity index 100%
rename from fragments.c
rename to btrfs-fragments.c
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2 (resend)] btrfs-progs: standardize tool source filenames
2013-04-23 20:57 ` [PATCH 1/2 (resend)] btrfs-progs: standardize tool source filenames Eric Sandeen
@ 2013-04-24 12:21 ` David Sterba
0 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2013-04-24 12:21 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-btrfs
On Tue, Apr 23, 2013 at 03:57:25PM -0500, Eric Sandeen wrote:
> vger ate my giant rename-files patch; here's the makefile bit, and
> hopefully the rename-diffs at the end are something that git
> knows how to apply? TBH I've never tried that before.
Yes it works, eg. the rename from btrsfck.c -> cmds-check.c has been
done that way.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: Add default rules to Makefile
2013-04-21 22:22 ` [PATCH 2/2] btrfs-progs: Add " Eric Sandeen
@ 2013-04-24 12:43 ` David Sterba
0 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2013-04-24 12:43 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-btrfs
On Sun, Apr 21, 2013 at 05:22:37PM -0500, Eric Sandeen wrote:
> This gets rid of a lot of the cut and pasted rules for
> each individual command, and as an added bonus makes it
> easy to build any btrfs-$FOO statically as well, i.e.
>
> # make btrfs-convert.static
Nice!
> +# keep intermediate files from the below implicit rules around
> +.PRECIOUS: $(addsuffix .o,$(progs))
I guess you saw something like
$ make btrfs-calc-size.static
...
rm btrfs-calc-size.static.o
at the end of the make output (though there's not rule to rm the file).
I've found this blogpost
http://darrendev.blogspot.cz/2008/06/stopping-make-delete-intermediate-files.html
that describes how to prevent the intermediate files to disappear, and
I've verified that this
-.PRECIOUS: $(addsuffix .o,$(progs))
+.SECONDARY:
works as expected in our case. Besides this change I moved the per-prog
libs variables up in the Makefile so the configurable settings are kept
close together:
+# external libs required by various binaries; for btrfs-foo,
+# specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
+btrfs_convert_libs = -lext2fs -lcom_err
+btrfs_image_libs = -lpthread
+btrfs_fragment_libs = -lgd -lpng -ljpeg -lfreetype
david
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-04-24 12:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-21 22:10 [PATCH 0/2] btrfs-progs: standardize utility filenames and add default rules to Makefile Eric Sandeen
2013-04-21 22:22 ` [PATCH 2/2] btrfs-progs: Add " Eric Sandeen
2013-04-24 12:43 ` David Sterba
2013-04-23 16:09 ` [PATCH 0/2] btrfs-progs: standardize utility filenames and add " David Sterba
2013-04-23 16:48 ` Eric Sandeen
2013-04-23 20:57 ` [PATCH 1/2 (resend)] btrfs-progs: standardize tool source filenames Eric Sandeen
2013-04-24 12:21 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.