Created
February 14, 2014 09:39
-
-
Save bluebat/8998367 to your computer and use it in GitHub Desktop.
Quick Sort in Makefile
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
#!/usr/bin/gmake -sf | |
#modified after jserv's Makefile.qsort from | |
#http://blog.linux.org.tw/~jserv/archives/002035.html | |
gt = $(shell if [ $1 -gt $2 ] ; then echo TRUE; fi) | |
lt = $(shell if [ $1 -lt $2 ] ; then echo TRUE; fi) | |
le = $(shell if [ $1 -le $2 ] ; then echo TRUE; fi) | |
define qsort | |
$(if $(call le,$(words $1),1),$1, \ | |
$(call qsort, \ | |
$(foreach i,$1, \ | |
$(if $(call gt,$(firstword $1),$i), $i,))) \ | |
$(firstword $1) \ | |
$(call qsort, \ | |
$(foreach i,$1, \ | |
$(if $(call lt,$(firstword $1),$i), $i,)))) | |
endef | |
ifeq "$(MAKECMDGOALS)" "" | |
$(info Usage: qsort.mk num1 num2 num3 ...) | |
else | |
$(info $(strip $(call qsort, $(MAKECMDGOALS)))) | |
endif | |
%: | |
@true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment