Makefile pour Linux ou windows
Bonjour
J'essaie de faire un seul makefile pour faire de la compilation (croisée ou non) d'un même programme. Voici mon ensemble de fichiers :
Le makefile
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| all: option
option:
@echo "option mrproper et clean pour nettoyer plus ou moins"
@echo "option windows ou win pour créer un exécutable windows"
@echo "option linux ou lin pour créer un exécutable linux"
windows:
make -f makefile.windows
win:
make -f makefile.windows
lin:
make -f makefile.linux
linux: lin
clean:
rm *.o *.org
mrproper: clean
rm perso.exe perso |
Le makefile.linux
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| CC=gcc
CFLAGS= -Wshadow -Winit-self -Wredundant-decls -Wcast-align -Wundef -Wfloat-equal -Winline -Wunreachable-code -Wmissing-declarations -Wmissing-include-dirs -Wswitch-enum -Wswitch-default -Wmain -Wall `pkg-config gtk+-3.0 --cflags` -export-dynamic
LDFLAGS=`pkg-config gtk+-3.0 --libs` -export-dynamic -lzip -lm
EXEC=perso
SRC= $(wildcard *.c)
OBJ= $(SRC:.c=.o)
all: $(EXEC)
$(EXEC) : $(OBJ)
$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.c
$(CC) -o $@ -c $< $(CFLAGS) |
Le makefile.windows
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| CC=i686-w64-mingw32-gcc
CFLAGS= -Wshadow -Winit-self -Wredundant-decls -Wcast-align -Wundef -Wfloat-equal -Winline -Wunreachable-code -Wmissing-declarations -Wmissing-include-dirs -Wswitch-enum -Wswitch-default -Wmain -Wall `i686-w64-mingw32-pkg-config gtk+-3.0 --cflags` -export-dynamic -mwindows
LDFLAGS=`i686-w64-mingw32-pkg-config gtk+-3.0 --libs` -lzip -mwindows -Wl,--export-all-symbols
EXEC=perso.exe
SRC= $(wildcard *.c)
OBJ= $(SRC:.c=.org)
all: $(EXEC)
$(EXEC) : $(OBJ)
$(CC) -o $@ $^ $(LDFLAGS)
%.org: %.c
$(CC) -o $@ -c $< $(CFLAGS) |
Pour pouvez remarquer que pour une meilleure cohabitation, les objets de linux sont en .o et ceux de windows en .obj. Ceci me permet de compiler pour l'un ou pour l'autre. Mais, j'ai un problème, un petit problème : "makefile win" ne marche pas ! C'est à dire que pour luii, il n'y a rien à faire. Pourquoi ?
Regardez si dessous pour bien saisir ce que je veux dire.
Code:
1 2 3 4 5 6
| [troumad@localhost perso]$ make win
make: «*win*» est à jour.
[troumad@localhost perso]$ make windows
make -f makefile.windows
make[1]*: on entre dans le répertoire «*/home/troumad/Documents/add/perso*»
i686-w64-mingw32-gcc -o utile.org -c utile.c -Wshadow -Winit-self -Wredundant-decls -Wcast-align -Wundef -Wfloat-equal -Winline -Wunreachable-code -Wmissing-declarations -Wmissing-include-dirs -Wswitch-enum -Wswitch-default -Wmain -Wall `i686-w64-mingw32-pkg-config gtk+-3.0 --cflags` -export-dynamic -mwindows |