-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "dumpmachine"/"dumpmachinefull" arguments to get the target machine triplet ("dumpmachinefull" for the full MSVC version). #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the addition, this looks useful, but I just wanted to point out a couple of possible (minor) improvements.
cccl
Outdated
@@ -39,6 +39,30 @@ case $MACHTYPE in | |||
;; | |||
esac | |||
|
|||
for arg in $@; do | |||
if [ "$arg" == "-dumpmachine" ] || [ "$arg" == "-dumpmachinefull" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why, but this script uses if test
in all the other places, so it should probably be used here too for consistency? Personally, I'd use if [[ ... ]]
in a bash script, e.g.
if [ "$arg" == "-dumpmachine" ] || [ "$arg" == "-dumpmachinefull" ]; then | |
if [[ $arg =~ ^-dumpmachine(full)?$ ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I will fix it to make it go along with other parts of the code as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the original, much simpler and easier to follow and probably more portable and possibly more portable if using =
. @vadz is right, we do use if test
everywhere, I think because we originally used sh instead of bash. Anyway, I'm no bash expert and don't really understand portability subtleties in bash except that what we currently using is meant to be more portable. Anyway, happy to be defer to some bash experts here.
cccl
Outdated
fi | ||
arch="$(echo ${cmd_out_parts[8]} | awk '{print tolower($0)}')" | ||
output="pc-windows-$msvc" | ||
if [ "$arch" = "x64" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a case
IMHO, for consistency with the similar code above and below and also because it seems better to use a single case
rather than a chain of if/elif
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will switch to case
instead.
cccl
Outdated
if [ "$arch" = "x64" ]; then | ||
output="x86_64-$output" | ||
elif [ "$arch" = "x86" ]; then | ||
output="i386-$output" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it should be i386
or i686
. It seems clang uses the former, Rust uses the latter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I create an X86 file, the file
command, which calls libmagic
, shows that it is an Intel 80386, which is i386
. Not sure how accurate that is, but this is why I went with i386
. I also did the same with armv7
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vadz I have updated the code with the new changes based on your suggestions, as well as documented why I chose the above architectures in some code comments.
This patch needs documenting with the added options like all the other options are documented. Can you point me to some cc compiler that implements |
I don't think there is a But, you are right. I need to add documentation to the code. |
Add two new command-line arguments to get the target machine's triplet, by parsing the command-line output of
cl
:*
dumpmachine
, which is to get the base machine triplet in the format{arch}-pc-windows-msvc
, where{arch}
is the target archetecture. If the target architecture is ARM or X86,{arch}
will be set toarmv7
ori386
, respectfully (since there are many ARM or X86 archetectures).dumpmachine
is similer to that ofgcc
/clang
's command of the same name.*
dumpmachinefull
, which has the same output asdumpmachine
, except it is post-fixed by the full MSVC version being used. In other words, the command-line argument has the following format{arch}-pc-windows-msvc{msvcver}
, where{arch}
is the target archetecture and{msvcver}
is the MSVC version.These arguments precede any other arguments passed to
cccl
, and ifdumpmachine
/dumpmachinefull
is processed, it will print the target triplet and exit succefully (the first ofdumpmachine
ordumpmachinefull
will be processed).