简体   繁体   中英

How to generate automatically Makefile in vim (c/c++) super fast?

I'm quite new to vim, have installed few plugins one of them is SnipMate, which is quite useful while writing a short Makefile.

snippet base
    PHONY: clean, mrproper
    CC = gcc
    CFLAGS = -g -Wall

    all: $1

    %.o: %.c        $(CC) $(CFLAGS) -c -o $@ $<

    ${1:OUTPUT_FILENAME}: $1.o
        $(CC) $(CFLAGS) -o $@ $+

    clean:      rm -f *.o core.*

    mrproper: clean         rm -f $1

but still it takes time to add manually the file names, I'm quite sure with some Vim Magic :) , Vim would able to do it automatically (executing it via hotkey) after I have wrote those c files, any suggestions?

Thank you all!

You can extract filenames automatically with glob() , and globpath() (don't ask me about SnipMate syntax to import the result -- I'm maintaining another template/snippet plugin).

But if you always use everything automatically, why don't you do it directly with make? There are ways to automatically glob filenames that match a pattern. If you need to trim files, well in that case listing explicitly every file you want to keep makes sense. But don't forget to remove unwanted files every time you trigger the update the file list action you wish to define.

BTW, IIRC, a properly configured gnumake (ie, not mingw one) already has the rule for %.o: %.c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM