Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/awk -f
- # creqs: scan a c source file and determine the
- # compiler flags necessary, e.g. -lm for <math.h>
- # r(h): return the required command switch to link the header `h'
- # this would be a switch but apparently i cannot write
- # syntactically correct switches in awk!
- function r(h) {
- if (h == "math.h")
- return "-lm"
- if (h == "ncurses.h")
- return "-lncurses"
- if (h ~ /^SDL/)
- return "-l" substr(h, 5, length(h)-6)
- # length(h)-6 to trim trailing .h
- return ""
- }
- { if (match($0, "^#[ \t]*include[ \t]*[\"<][ \t]*")) {
- header = substr($0, 1+RLENGTH); # trim #include < from left of line
- if (!match(header, "[ \">]")) {
- # is there a better way than | "cat 1>&2" to print to stderr?
- printf "creqs: malformed #include directive: `%s'\n", $0 | "cat 1>&2"
- next
- }
- header = substr(header, 1, RSTART-1); # trim to the actual name of the header
- if (switch = r(header))
- reqs = reqs? reqs " " switch: switch
- }
- }
- END { print reqs }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement