miniroon

Simplistic macaroon-based authorization for Unix systems
git clone https://ccx.te2000.cz/git/miniroon
Log | Files | Refs

codedeps.awk (850B)


      1 BEGIN {
      2 	if(length(target) == 0 || length(srcname) == 0) {
      3 		exit 2
      4 	}
      5 }
      6 
      7 /^#/ && $3 !~ /^"[<\/]/ {
      8 	inc[$3]=1
      9 }
     10 
     11 /^\/\/ \{IMP\} /{
     12 	imp[substr($0,10)]
     13 }
     14 
     15 function depname(s) {
     16 	sub(/"$/, "", s)
     17 	sub(/^"/, "", s)
     18 	return s
     19 }
     20 
     21 function deparray(fname) {
     22 	gsub(/[^a-zA-Z0-9_]/, "__", fname)
     23 	return "LINKDEP_" fname
     24 }
     25 
     26 function objfile(fname) {
     27 	sub(/\.c$/, ".o", fname)
     28 	return "build/" fname
     29 }
     30 
     31 END {
     32 	da = deparray(srcname)
     33 	printf "ifndef %s\n\n", da
     34 	printf "%s:", target
     35 	for(f in inc) {
     36 		printf " %s", depname(f)
     37 	}
     38 	printf "\n\n"
     39 	printf "%s:=%s\n", deparray(srcname), objfile(srcname)
     40 	append = 0
     41 	for(f in imp){
     42 		if(f == srcname) {
     43 			continue
     44 		}
     45 		printf "include build/%s.deps.mk\n", f
     46 		append = 1
     47 	}
     48 	if(append) {
     49 		printf "%s+= $(sort ", da
     50 		for(f in imp){
     51 			printf " $(%s)", deparray(f)
     52 		}
     53 		printf ")\n"
     54 	}
     55 	printf "\nendif\n"
     56 }