nuclear@2: #!/bin/sh nuclear@2: nuclear@7: cfgfile=src/config.h nuclear@7: modfile=src/modules.c nuclear@19: logfile=config.log nuclear@19: echobin=`which echo` nuclear@19: nuclear@19: rm -f $logfile nuclear@19: nuclear@19: message() nuclear@19: { nuclear@19: $echobin $* | tee -a $logfile nuclear@19: } nuclear@7: nuclear@9: extract() nuclear@9: { nuclear@12: grep "$2:" $1 | sed "s/^.*$2: *\(.*\)\*\//\1/" nuclear@9: } nuclear@9: nuclear@7: get_depline() nuclear@2: { nuclear@9: extract $1 link-with nuclear@9: } nuclear@9: nuclear@9: get_framework() nuclear@9: { nuclear@9: extract $1 mac-framework nuclear@2: } nuclear@2: nuclear@7: get_usedef() nuclear@7: { nuclear@7: grep '#ifdef *USE_WSYS_MODULE' $1 | sed 's/^.*\(USE_WSYS_MODULE_.*\)/\1/' nuclear@7: } nuclear@2: nuclear@7: try_link() nuclear@7: { nuclear@7: srcfile=/tmp/sgl-trylink.c nuclear@7: aout=/tmp/sgl-a.out nuclear@7: nuclear@19: echo >>$logfile nuclear@19: echo "trying command line: cc -o $aout $srcfile $*" >>$logfile nuclear@19: nuclear@7: echo 'int main(void) { return 0; }' >$srcfile nuclear@19: eval cc -o $aout $srcfile $1 >>$logfile 2>>$logfile nuclear@13: res=$? nuclear@13: nuclear@13: rm -f $srcfile $aout nuclear@13: return $res nuclear@7: } nuclear@7: nuclear@7: # write beginning of config.h nuclear@7: echo '#ifndef CONFIG_H_' >$cfgfile nuclear@7: echo '#define CONFIG_H_' >>$cfgfile nuclear@7: echo >>$cfgfile nuclear@7: nuclear@7: # write beginning of modules.c nuclear@7: echo "/* this file is generated by $0, do not edit */" >$modfile nuclear@7: echo >>$modfile nuclear@9: echo '#define REGISTER_MODULE(name) \' >>$modfile nuclear@9: echo ' do { void sgl_register_##name(); sgl_register_##name(); } while(0)' >>$modfile nuclear@9: echo >>$modfile nuclear@7: echo 'void sgl_modules_init(void)' >>$modfile nuclear@7: echo '{' >>$modfile nuclear@7: nuclear@7: nuclear@7: # start scanning for modules nuclear@19: message 'Looking for usable window system modules ...' nuclear@7: nuclear@7: # collect all src/wsys_whatever.c files nuclear@13: all_files=`ls src/wsys_*.c src/wsys_*.m 2>/dev/null` nuclear@7: nuclear@7: for m in $all_files; do nuclear@7: # extract USE_WSYS_MODULE_* define nuclear@7: def=`get_usedef $m` nuclear@7: nuclear@7: # extract link-with line nuclear@9: if [ `uname -s` = Darwin ]; then nuclear@9: dep=`get_framework $m` nuclear@9: if [ -z "$dep" ]; then nuclear@9: dep=`get_depline $m` nuclear@9: fi nuclear@9: else nuclear@9: dep=`get_depline $m` nuclear@13: if [ -z "$dep" ]; then nuclear@13: dep=`get_framework $m` nuclear@13: fi nuclear@9: fi nuclear@9: nuclear@15: name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//' | sed 's/\.m//'` nuclear@19: message -n "-> trying module $name (needs: $dep) ... " nuclear@7: nuclear@12: if try_link "$dep"; then nuclear@19: message ok nuclear@7: nuclear@7: libs="$libs $dep" nuclear@7: nuclear@7: # emmit the USE_ define in config.h nuclear@7: echo "#define $def" >>$cfgfile nuclear@7: echo >>$cfgfile nuclear@7: nuclear@7: # make the registration call in modules.c nuclear@9: echo " REGISTER_MODULE($name);" >>$modfile nuclear@7: else nuclear@19: message failed nuclear@7: fi nuclear@7: done nuclear@7: echo "Will link with: $libs" nuclear@7: nuclear@7: # wrap up the modules.c file nuclear@7: echo '}' >>$modfile nuclear@7: nuclear@7: # wrap up the config.h file nuclear@7: echo '#endif /* CONFIG_H_ */' >>$cfgfile nuclear@7: nuclear@7: # generate makefile nuclear@19: message Generating makefile ... nuclear@7: nuclear@7: # hardcode prefix for now, too lazy to actually add an option... nuclear@2: echo 'PREFIX = /usr/local' >Makefile nuclear@7: echo "wsys_libs = $libs" >>Makefile nuclear@2: cat Makefile.in >>Makefile nuclear@7: nuclear@19: message 'Configuration complete. Run make (or gmake) to compile.'