abcminiuser / dmbs

Dean's Makefile Build System - making MAKE easier.
51 stars 18 forks source link

Duplicate source names give error #12

Open NicoHood opened 8 years ago

NicoHood commented 8 years ago

I try to compile those files:

avrnacl_small/crypto_auth/hmac.c 
avrnacl_small/crypto_box/curve25519xsalsa20poly1305.c 
avrnacl_small/crypto_core/hsalsa20.c 
avrnacl_small/crypto_core/salsa20.c 
avrnacl_small/crypto_dh/curve25519.c 
avrnacl_small/crypto_hash/sha512.c 
avrnacl_small/crypto_hashblocks/sha512.c 
avrnacl_small/crypto_onetimeauth/poly1305.c 
avrnacl_small/crypto_scalarmult/curve25519.c 
avrnacl_small/crypto_secretbox/xsalsa20poly1305.c 
avrnacl_small/crypto_sign/ed25519.c 
avrnacl_small/crypto_sign/sc25519.c 
avrnacl_small/crypto_sign/precompute.c 
avrnacl_small/crypto_sign/ge25519.c 
avrnacl_small/crypto_stream/xsalsa20.c 
avrnacl_small/crypto_stream/salsa20.c 
avrnacl_small/crypto_verify/verify.c

But I get this error:

dmbs/DMBS/gcc.mk:95: *** Cannot build with OBJDIR parameter set - one or more object file name is not unique.  Stop.

If you look closer at the sources you will notice that sha512.c (and others) are available in two folders (but still different code inside). I think the folder structure is not kept in the output path and therefor this causes problems.

Using latest dmbs release-20160403 or newer (from git).

NicoHood commented 8 years ago

This is my patch (not sure if its good like this, but "it works")

# Check if an output object file directory was specified instead of the input file location
ifneq ($(OBJDIR),.)
   # Prefix all the object filenames with the output object file directory path
   OBJECT_FILES    := $(addprefix $(patsubst %/,%,$(OBJDIR))/, $(OBJECT_FILES))
   OBJECT_PATH := $(dir $(OBJECT_FILES))
   $(shell mkdir -p $(OBJECT_PATH))

   # Create the output object file directory if it does not exist and add it to the virtual path list
   $(shell mkdir $(OBJDIR) 2> /dev/null)
   VPATH           += $(dir $(SRC))
endif
abcminiuser commented 7 years ago

Sorry, I really haven't been looking at Github for ages - too much paid work that leaves me too unmotivated to look at my personal projects :(.

Just took a look at this. The issue with multiple object files with identical names is a very hard one to solve, specifically because of relative paths. Give SRC of:

SRC = Test.c ../Library/Test.c

The resulting objects will be:

Test.o ../Library/Test.o

Which is fine to build in place. Unfortunately however, you can't easily rebase that path against a new object path in GNU make as far as I am aware, so simply adding a common OBJDIR prefix $(addprefix $(patsubst %/,%,$(OBJDIR))/, $(OBJECT_FILES)) results in:

obj/Test.o obj/../Library/Test.o

I.e. objects are generated outside the desired root OBJDIR folder. That's why I enforce the unique name constraint on the input source files if you want to put all the objects into a flat OBJDIR directly - stripping off the full base path of the input source files sidesteps the relative pathing issue.

NicoHood commented 7 years ago

You could possibly check for duplicate names and then name them with Test_1 Test_2? Or you could add a hash before each file which would be unique enough. A small CRC would not give too much trash output and serve the needs.

NicoHood commented 7 years ago

And what if we just replace ".." by "rel" and create this path?