refactor configure script
Generate a makefile config instead of a makefile with predefined constants. This makes the build a bit more easier to modify. Also improve the makefile and apply some suggestions from shellcheck. :)
This commit is contained in:
		
							parent
							
								
									4bb8d391fd
								
							
						
					
					
						commit
						f1b79c2a7c
					
				
					 3 changed files with 60 additions and 66 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -4,4 +4,4 @@ | |||
| esv | ||||
| result | ||||
| 
 | ||||
| Makefile | ||||
| config.mk | ||||
							
								
								
									
										29
									
								
								Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,29 @@ | |||
| IMPORT    = import | ||||
| PREFIX    = /usr/local | ||||
| MANPREFIX = ${PREFIX}/man | ||||
| 
 | ||||
| DC      = ${_DC} | ||||
| CFLAGS  = ${_CFLAGS} | ||||
| OBJS    = ${_OBJS} | ||||
| 
 | ||||
| all: esv | ||||
| 
 | ||||
| include config.mk | ||||
| 
 | ||||
| esv: ${OBJS} | ||||
| 	${DC} ${_LDFLAGS} -of=$@ ${OBJS} | ||||
| 
 | ||||
| .SUFFIXES: .d .o | ||||
| 
 | ||||
| .d.o: | ||||
| 	${DC} ${CFLAGS} -c $< | ||||
| 
 | ||||
| clean: | ||||
| 	rm -f esv ${OBJS} ${INIOBJS} | ||||
| 
 | ||||
| install: esv | ||||
| 	install -Dm755 esv ${DESTDIR}${PREFIX}/bin/esv | ||||
| 	install -Dm644 esv.1 ${DESTDIR}${MANPREFIX}/man1 | ||||
| 	install -Dm644 esv.conf.5 ${DESTDIR}${MANPREFIX}/man5 | ||||
| 
 | ||||
| .PHONY: all clean install | ||||
							
								
								
									
										95
									
								
								configure
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										95
									
								
								configure
									
										
									
									
										vendored
									
									
								
							|  | @ -4,40 +4,9 @@ | |||
| 
 | ||||
| set -e | ||||
| 
 | ||||
| import=import | ||||
| 
 | ||||
| mkf=Makefile | ||||
| mkf=config.mk | ||||
| objs='esv.o esvapi.o initial.o' | ||||
| srcs='esv.d esvapi.d initial.d' | ||||
| makefile=' | ||||
| IMPORT    = '"$import"' | ||||
| PREFIX    = /usr/local | ||||
| MANPREFIX = ${PREFIX}/man | ||||
| 
 | ||||
| DC      = ${_DC} | ||||
| CFLAGS  = ${_CFLAGS} | ||||
| OBJS    = ${_OBJS} | ||||
| 
 | ||||
| all: esv | ||||
| 
 | ||||
| esv: ${OBJS} | ||||
| 	${DC} ${_LDFLAGS} -of=$@ ${OBJS} | ||||
| 
 | ||||
| .SUFFIXES: .d .o | ||||
| 
 | ||||
| .d.o: | ||||
| 	${DC} ${CFLAGS} -c $< | ||||
| 
 | ||||
| clean: | ||||
| 	rm -f esv ${OBJS} ${INIOBJS} | ||||
| 
 | ||||
| install: | ||||
| 	install -Dm755 esv ${DESTDIR}${PREFIX}/bin/esv | ||||
| 	install -Dm644 esv.1 ${DESTDIR}${MANPREFIX}/man1/esv.1 | ||||
| 	install -Dm644 esv.conf.5 ${DESTDIR}${MANPREFIX}/man5/esv.conf.5 | ||||
| 
 | ||||
| .PHONY: all clean install | ||||
| ' | ||||
| 
 | ||||
| # utility functions | ||||
| 
 | ||||
|  | @ -45,10 +14,10 @@ present () { | |||
| 	command -v "$1" 1>/dev/null 2>/dev/null | ||||
| } | ||||
| using () { | ||||
| 	>&2 printf "using $1\n" | ||||
| 	>&2 printf "using %s\n" "$1" | ||||
| } | ||||
| error () { | ||||
| 	>&2 printf "$(basename $0): $1\n" | ||||
| throw () { | ||||
| 	>&2 printf "%s: %s\n" "$(basename "$0")" "$1" | ||||
| 	exit 1 | ||||
| } | ||||
| 
 | ||||
|  | @ -56,7 +25,7 @@ error () { | |||
| 
 | ||||
| ## D compiler | ||||
| gen_DC () { | ||||
| 	if ! [ -z "$dc" ]; then | ||||
| 	if [ -n "$dc" ]; then | ||||
| 		using "$dc" | ||||
| 		return 0 | ||||
| 	fi | ||||
|  | @ -65,7 +34,7 @@ gen_DC () { | |||
| 	elif present dmd; then | ||||
| 		dc=dmd | ||||
| 	else | ||||
| 		error "D compiler not found; install ldc or dmd" | ||||
| 		throw "D compiler not found; install ldc or dmd" | ||||
| 	fi | ||||
| 
 | ||||
| 	using "$dc" | ||||
|  | @ -101,7 +70,7 @@ gen_LDFLAGS () { | |||
| 		fi | ||||
| 	fi | ||||
| 	if [ -z "$debug" ]; then | ||||
| 		if ! [ -z "$ldflags" ]; then ldflags="$ldflags "; fi | ||||
| 		if [ -n "$ldflags" ]; then ldflags="$ldflags "; fi | ||||
| 		ldflags="$ldflags-L--gc-sections" | ||||
| 	fi | ||||
| 
 | ||||
|  | @ -118,7 +87,7 @@ while getopts c:dhr ch; do | |||
| 			case "$OPTARG" in | ||||
| 				ldc2) dc="ldc2" ;; | ||||
| 				dmd)  dc="dmd"  ;; | ||||
| 				*) error "unknown D compiler '$OPTARG' specified (valid options: ldc2, dmd)" ;; | ||||
| 				*) throw "unknown D compiler '$OPTARG' specified (valid options: ldc2, dmd)" ;; | ||||
| 			esac | ||||
| 			;; | ||||
| 		d) debug=1 ;; | ||||
|  | @ -135,7 +104,7 @@ options: | |||
| EOF | ||||
| 			exit 0 | ||||
| 			;; | ||||
| 		?) exit 1 ;; | ||||
| 		'?') exit 1 ;; | ||||
| 		:) exit 1 ;; | ||||
| 	esac | ||||
| done | ||||
|  | @ -147,33 +116,29 @@ gen_CFLAGS | |||
| gen_LDFLAGS | ||||
| 
 | ||||
| rm -f "$mkf" | ||||
| printf '# begin generated definitions' >>"$mkf" | ||||
| printf ' | ||||
| 
 | ||||
| { | ||||
| 	printf '# begin generated definitions | ||||
| _DC = %s | ||||
| _CFLAGS = %s | ||||
| _LDFLAGS = %s | ||||
| '              \ | ||||
| 	"$dc"      \ | ||||
| 	"$cflags"  \ | ||||
| 	"$ldflags" \ | ||||
| 		>>"$mkf" | ||||
| ## generate obj list | ||||
| printf '_OBJS =' >>"$mkf" | ||||
| for obj in $objs; do | ||||
| 	printf " $obj" >>"$mkf" | ||||
| done | ||||
| printf '\n' >>"$mkf" | ||||
| printf '# end generated definitions\n' >>"$mkf" | ||||
| ' "$dc" "$cflags" "$ldflags" | ||||
| 
 | ||||
| printf "$makefile" >>"$mkf" | ||||
| 	## generate obj list | ||||
| 	printf '_OBJS =' | ||||
| 	for obj in $objs; do | ||||
| 		printf ' %s' "$obj" | ||||
| 	done | ||||
| 	printf '\n# end generated definitions\n' | ||||
| 
 | ||||
| ## generate dependency list | ||||
| >&2 printf "generating dependency list\n" | ||||
| printf '\n# begin generated dependencies\n' >>"$mkf" | ||||
| i=1 | ||||
| for obj in $objs; do | ||||
| 	"$dc" -O0 -o- -makedeps \ | ||||
| 		"$(printf "$srcs" | awk '{print $'"$i"'}')" >>"$mkf" | ||||
| 	i="$(($i + 1))" | ||||
| done | ||||
| printf '# end generated dependencies\n' >>"$mkf" | ||||
| 	## generate dependency list | ||||
| 	printf '\n# begin generated dependencies\n' | ||||
| 	i=1 | ||||
| 	for obj in $objs; do | ||||
| 		"$dc" -o- -makedeps \ | ||||
| 			  "$(printf '%s' "$srcs" | awk '{print $'"$i"'}')" | ||||
| 		i="$((i + 1))" | ||||
| 	done | ||||
| 	unset i | ||||
| 	printf '# end generated dependencies\n' | ||||
| } >>"$mkf" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue