-
Notifications
You must be signed in to change notification settings - Fork 2.1k
make: Place most configuration macros in a separate file instead of on the command line #5097
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| genconfigheader.sh | ||
| ------------------ | ||
|
|
||
| Usage: `genconfigheader.sh <output_header_file> [CFLAGS]` | ||
|
|
||
| Generate a build configuration header from CFLAGS arguments | ||
|
|
||
| - Arguments on the form `-Dmacro_name=macro_value` will be converted to | ||
| the form `#define macro_name macro_value` | ||
| - Arguments given on the form `-Dmacro_name` will be converted to the form `#define macro_name 1` | ||
| - The output file will be overwritten if it already exists _and_ the new output file's contents differs from the old file. | ||
|
|
||
| By not replacing the output file on every run, make can still use the file | ||
| modification times for dependency calculations. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/bin/sh | ||
|
|
||
| # | ||
| # Copyright (C) 2016 Eistec AB | ||
| # | ||
| # This file is subject to the terms and conditions of the GNU Lesser General | ||
| # Public License v2.1. See the file LICENSE in the top level directory for more | ||
| # details. | ||
| # | ||
|
|
||
| DEBUG=0 | ||
| if [ "${QUIET}" != "1" ]; then | ||
| DEBUG=1 | ||
| fi | ||
|
|
||
| if [ $# -lt 1 ]; then | ||
| echo "Usage: $0 <output.h> [CFLAGS]..." | ||
| echo "Extract all macros from CFLAGS and generate a header file" | ||
| exit 1 | ||
| fi | ||
| OUTPUTFILE="$1" | ||
| shift | ||
|
|
||
| MD5SUM=md5sum | ||
| if [ "$(uname -s)" = "Darwin" ]; then | ||
| MD5SUM=md5 -r | ||
| fi | ||
|
|
||
| # atomically update the file | ||
| TMPFILE= | ||
| trap '[ -n "${TMPFILE}" ] && rm -f "${TMPFILE}"' EXIT | ||
| # Create temporary output file | ||
| TMPFILE=$(mktemp ${OUTPUTFILE}.XXXXXX) | ||
|
|
||
| if [ -z "${TMPFILE}" ]; then | ||
| echo "Error creating temporary file, aborting" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # exit on any errors below this line | ||
| set -e | ||
|
|
||
| echo "/* DO NOT edit this file, your changes will be overwritten and won't take any effect! */" > "${TMPFILE}" | ||
| echo "/* Generated from CFLAGS: $@ */" >> "${TMPFILE}" | ||
| for arg in "$@"; do | ||
| case ${arg} in | ||
| -D*) | ||
| # Strip leading -D | ||
| d=${arg#-D} | ||
| if [ -z "${d##*=*}" ]; then | ||
| # key=value pairs | ||
| key=${d%%=*} | ||
| value=${d#*=} | ||
| echo "#define $key $value" >> "${TMPFILE}" | ||
| else | ||
| # simple #define | ||
| echo "#define $d 1" >> "${TMPFILE}" | ||
| fi | ||
| ;; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -U*) echo "#undef ${arg#-U}" >> "${TMPFILE}" ;;?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea! |
||
| -U*) | ||
| # Strip leading -U | ||
| d=${arg#-U} | ||
| echo "#undef $d" >> "${TMPFILE}" | ||
| ;; | ||
| *) | ||
| continue | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # Only replace old file if the new file differs. This allows make to check the | ||
| # date of the config header for dependency calculations. | ||
| NEWMD5=$(${MD5SUM} ${TMPFILE} | cut -c -32) | ||
| OLDMD5=$(${MD5SUM} ${OUTPUTFILE} 2>/dev/null | cut -c -32) | ||
| if [ "${NEWMD5}" != "${OLDMD5}" ]; then | ||
| if [ "${DEBUG}" -eq 1 ]; then echo "Replacing ${OUTPUTFILE} (${NEWMD5} != ${OLDMD5})"; fi | ||
| # Set mode according to umask | ||
| chmod +rw "${TMPFILE}" | ||
| mv -f "${TMPFILE}" "${OUTPUTFILE}" | ||
| else | ||
| if [ "${DEBUG}" -eq 1 ]; then echo "Keeping old ${OUTPUTFILE}"; fi | ||
| fi | ||
|
|
||
| # $TMPFILE will be deleted by the EXIT trap above if it still exists when we exit | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a specific reason for switching these lines? I'm just curious.
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 remember, I think I just deleted them and rewrote them, and when I
did, I put them in alphabetical order.
Den 28 jun 2016 07:38 skrev "BytesGalore" [email protected]: